-
Notifications
You must be signed in to change notification settings - Fork 22
Auth and Users
By default there are five users generated one for each default user role:
-
Username:
admin
-
Password:
password
-
Username:
editor
-
Password:
password
-
Username:
author
-
Password:
password
-
Username:
contributor
-
Password:
password
-
Username:
subscriber
-
Password:
password
To save time on tests and so you don't have to perform any login/authentification logic, by default login will be bypassed 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>')
to programmatically switch users at specific points during your test.
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');
In some cases you may have situations where the login needs to go through the full process to execute any hooks or background processes as part of your site. The standard user switching method above will not work for these requirements. Instead a manual login will be required, forcing WP-Cypress to run through the wp-login.php
rather than bypassing the authentication as outlined above. A manual login can simply be achieved by adding a password as the optional second parameter to cy.switchUser()
.
cy.switchUser('exampleuser', 'password123');