Skip to content

Auth and Users

Liam Defty edited this page Jul 8, 2020 · 5 revisions

Default users

By default there are five users generated one for each default user role:

Admin

  • Username: admin
  • Password: password

Editor

  • Username: editor
  • Password: password

Author

  • Username: author
  • Password: password

Contributor

  • Username: contributor
  • Password: password

Subscriber

  • Username: subscriber
  • Password: password

Authentification

To save time on tests and so you don't have to perform any login/authentification logic, by default login will be bypassed with wp-cypress and the user will be logged in as the admin user. If you wish to change user you can use the cypress command cy.switchUser('<username>', '<password>') to programatically switch users at specific points during your test.

Creating a user

You can generate other users when seeding your database with test data. You can make use of the existing User fixture or perform any custom logic that may required.

An example of using a fixture:

To learn more about using a seed see Seeds and Fixtures

public function run() {
    $user = new Fixtures\User( [
        'role'         => 'admin',
        'user_login'   => 'exampleuser',
        'user_pass'    => 'password123',
        'display_name' => $this->faker->name(),
        'first_name'   => $this->faker->firstName(),
    ] );

    $user->create( 1 );
}

Then to log in as this user in your cypress tests you can use the switchUser command:

cy.switchUser('exampleuser', 'password123');