Skip to content

Commit

Permalink
Tests: Improve stability of e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Aug 7, 2018
1 parent 3bf1e49 commit 6e7f7de
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"publish:dev": "npm run build:packages && lerna publish --npm-tag next",
"publish:prod": "npm run build:packages && lerna publish",
"test": "npm run lint && npm run test-unit",
"pretest-e2e": "concurrently \"./bin/reset-e2e-tests.sh\" \"npm run build\"",
"pretest-e2e2": "concurrently \"./bin/reset-e2e-tests.sh\" \"npm run build\"",
"test-e2e": "cross-env JEST_PUPPETEER_CONFIG=test/e2e/puppeteer.config.js wp-scripts test-unit-js --config test/e2e/jest.config.json --runInBand",
"test-e2e:watch": "npm run test-e2e -- --watch",
"test-php": "npm run lint-php && npm run test-unit-php",
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/classic-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ describe( 'classic editor', () => {

it( 'Should work properly', async () => {
// Click visual editor
await page.click( '#content-tmce' );
await page.click( '#content_ifr' );
await expect( page ).toClick( '#content-tmce' );
await expect( page ).toClick( '#content_ifr' );

// type some random text
await page.keyboard.type( 'Typing in classic editor' );

// Switch to HTML mode
await page.click( '#content-html' );
await expect( page ).toClick( '#content-html' );

const textEditorContent = await page.$eval( '.wp-editor-area', ( element ) => element.value );
expect( textEditorContent ).toEqual( 'Typing in classic editor' );
Expand Down
1 change: 0 additions & 1 deletion test/e2e/specs/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe( 'undo', () => {
} );

it( 'Should undo to expected level intervals', async () => {
await page.waitForSelector( '.editor-default-block-appender__content' );
await clickBlockAppender();

await page.keyboard.type( 'This' );
Expand Down
11 changes: 8 additions & 3 deletions test/e2e/support/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const { PUPPETEER_TIMEOUT } = process.env;
// The Jest timeout is increased because these tests are a bit slow
jest.setTimeout( PUPPETEER_TIMEOUT || 100000 );

async function setupBrowser() {
await clearLocalStorage();
await setViewport( 'large' );
}

// Before every test suite run, delete all content created by the test. This ensures
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
// each other's side-effects.
Expand All @@ -45,11 +50,11 @@ beforeAll( async () => {
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
);
}
await setupBrowser();
} );

beforeEach( async () => {
await clearLocalStorage();
await setViewport( 'large' );
afterEach( async () => {
await setupBrowser();
} );

afterAll( () => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export async function ensureSidebarOpened() {
* Clicks the default block appender.
*/
export async function clickBlockAppender() {
await page.click( '.editor-default-block-appender__content' );
await expect( page ).toClick( '.editor-default-block-appender__content' );
}

/**
Expand Down Expand Up @@ -221,7 +221,7 @@ export async function pressWithModifier( modifier, key ) {
* @param {string} buttonLabel The label to search the button for.
*/
export async function clickOnMoreMenuItem( buttonLabel ) {
await page.click( '.edit-post-more-menu [aria-label="More"]' );
await expect( page ).toClick( '.edit-post-more-menu [aria-label="More"]' );
const itemButton = ( await page.$x( `//button[contains(text(), '${ buttonLabel }')]` ) )[ 0 ];
await itemButton.click( 'button' );
}
Expand Down

0 comments on commit 6e7f7de

Please sign in to comment.