From 6e7f7de0c1e9e973e6fd5655aae5cd0933f46e8c Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 7 Aug 2018 15:50:19 +0200 Subject: [PATCH] Tests: Improve stability of e2e tests --- package.json | 2 +- test/e2e/specs/classic-editor.test.js | 6 +++--- test/e2e/specs/undo.test.js | 1 - test/e2e/support/setup-test-framework.js | 11 ++++++++--- test/e2e/support/utils.js | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index cdf2ab7200911e..bbb3fdb8ef91a3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/e2e/specs/classic-editor.test.js b/test/e2e/specs/classic-editor.test.js index e6664bcf098ea3..0d51c93e5b3420 100644 --- a/test/e2e/specs/classic-editor.test.js +++ b/test/e2e/specs/classic-editor.test.js @@ -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' ); diff --git a/test/e2e/specs/undo.test.js b/test/e2e/specs/undo.test.js index 66e4dc941718c0..0c2eb1357695d1 100644 --- a/test/e2e/specs/undo.test.js +++ b/test/e2e/specs/undo.test.js @@ -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' ); diff --git a/test/e2e/support/setup-test-framework.js b/test/e2e/support/setup-test-framework.js index ad0b4a2996fc46..6651900f628769 100644 --- a/test/e2e/support/setup-test-framework.js +++ b/test/e2e/support/setup-test-framework.js @@ -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. @@ -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( () => { diff --git a/test/e2e/support/utils.js b/test/e2e/support/utils.js index ebb2669f40f6f8..c42881983f63bd 100644 --- a/test/e2e/support/utils.js +++ b/test/e2e/support/utils.js @@ -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' ); } /** @@ -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' ); }