Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: Optimize e2e testing path navigation #3333

Merged
merged 2 commits into from
Nov 6, 2017

Conversation

aduth
Copy link
Member

@aduth aduth commented Nov 3, 2017

Related: #3069

This pull request seeks to improve e2e testing performance in two ways:

  • Creating a generic visitAdmin command which automatically handles login behavior, preserving redirect_to of the desired screen to avoid navigating from the admin dashboard root after a login.
  • Preserving the WordPress session cookies between tests via a Cypress.Cookies.defaults whitelist, to avoid logins between tests

Testing instructions:

Verify that e2e tests pass:

If you don't already have the local Docker environment set-up, first ensure Docker is installed, then run ./bin/setup-local-env.sh

Finally, run npm run test-e2e

@aduth aduth added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Nov 3, 2017
@@ -1,13 +1,9 @@
describe( 'Hello Gutenberg', () => {
before( () => {
cy.login();
cy.newPost();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly decided to avoid the newPost command in this test. Usually, when you have commands like those. You have one test performing this manually and an optimized version as a command to reuse across other tests. The reusable version can use any trick (fake APIs, direct URL access to speed up the behavior).

For this one specifically, I think it's fine to drop the manual testing, it's not that important but I just wanted to explain.

Copy link
Member Author

@aduth aduth Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have one test performing this manually and an optimized version as a command to reuse across other tests.

Yeah, that made sense, with one of the ideas of this pull request being that if we can consolidate the optimization within newPost, visitAdmin (i.e. try navigating directly, handle login but only if encountered) then the individual tests benefit by having a consistent interface and not relying on any other tests to have handled specific steps.


Cypress.Commands.add( 'visitAdmin', ( adminPath ) => {
cy.visit( '/wp-admin/' + adminPath ).location( 'pathname' ).then( ( path ) => {
if ( path === '/wp-login.php' ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization 👍

@aduth aduth merged commit 4e61b96 into master Nov 6, 2017
@aduth aduth deleted the update/e2e-new-post-login-redirect branch November 6, 2017 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants