Skip to content

Commit

Permalink
Merge pull request #3333 from WordPress/update/e2e-new-post-login-red…
Browse files Browse the repository at this point in the history
…irect

Testing: Optimize e2e testing path navigation
  • Loading branch information
aduth authored Nov 6, 2017
2 parents dd710b3 + 63ed28c commit 4e61b96
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
6 changes: 1 addition & 5 deletions test/e2e/integration/001-hello-gutenberg.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
describe( 'Hello Gutenberg', () => {
before( () => {
cy.login();
cy.newPost();
} );

it( 'Should show the New Post Page in Gutenberg', () => {
// Navigate to New Post
cy.get( '.wp-menu-name' ).contains( 'Posts' ).click();
cy.get( '.wp-submenu a' ).contains( 'Add New' ).click();

// Assertions
cy.url().should( 'include', 'post-new.php' );
cy.get( '[placeholder="Add title"]' ).should( 'exist' );
Expand Down
1 change: 0 additions & 1 deletion test/e2e/integration/002-adding-blocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe( 'Adding blocks', () => {
before( () => {
cy.login();
cy.newPost();
} );

Expand Down
10 changes: 9 additions & 1 deletion test/e2e/support/gutenberg-commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Cypress.Commands.add( 'newPost', () => {
cy.visit( '/wp-admin/post-new.php' );
cy.visitAdmin( '/post-new.php' );
} );

Cypress.Commands.add( 'visitAdmin', ( adminPath ) => {
cy.visit( '/wp-admin/' + adminPath ).location( 'pathname' ).then( ( path ) => {
if ( path === '/wp-login.php' ) {
cy.login();
}
} );
} );
4 changes: 4 additions & 0 deletions test/e2e/support/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
import './user-commands';
import './gutenberg-commands';

Cypress.Cookies.defaults( {
whitelist: /^wordpress_/,
} );
6 changes: 5 additions & 1 deletion test/e2e/support/user-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ Cypress.Commands.add( 'login', ( username = Cypress.env( 'username' ), password
// and fake it by calling an API and setting a cookie
// (not sure this is possible in WP)

cy.visit( '/wp-admin' );
cy.location( 'pathname' ).then( ( path ) => {
if ( path !== '/wp-login.php' ) {
cy.visit( '/wp-login.php' );
}
} );
cy.get( '#user_login' ).type( username );
cy.get( '#user_pass' ).type( password );
cy.get( '#wp-submit' ).click();
Expand Down

0 comments on commit 4e61b96

Please sign in to comment.