bigbite / wp-cypress

WordPress end to end testing with Cypress.io.
MIT License
86 stars 19 forks source link

Allow for manual user switching. #62

Closed ampersarnie closed 3 years ago

ampersarnie commented 3 years ago

Description

Fixes #59 - This PR opens up a number of functions to allow for some more comprehensive user switching and authentication. switchUser() has been expanded upon to allow for passwords to be defined so a manual login can take place, and logout() is added to allow for logging out the current user. With both methods, they will first attempt to remove the .userid file which is used for by-passing authentication and then clear cookies before redirecting back to the login page.

In addition to changing the user switchUser() will perform a manual login attempt via completing the login form. This will also check for Jetpack SSO and click the login link if found. This happens by providing a second parameter on switchUser() of a password. If a password is used then a login attempt will be made.

Usage Example

Spec

describe("Posts.", () => {
  it("I can add a new post as an author.", () => {
    cy.switchUser('author', 'password');
    cy.visit("/wp-admin/post-new.php");
    // ...
    cy.logout();
  });
});

Change Log

Screenshots/Videos

If PR includes visual changes, please include a screenshot (or short video if applicable).

Types of changes (if applicable):

Checklist (if applicable):