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 8, 2018
1 parent d8c1f97 commit d29fe22
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
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 @@ -226,7 +226,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 d29fe22

Please sign in to comment.