Adding a Role for logging in
As we already learned from Chapter 2, Exploring TestCafe under the Hood, TestCafe has a built-in user role mechanism that emulates user actions for logging in to a website. The role mechanism saves the logged-in state of each user in a separate role that can then be reused in any part of your tests to switch between user accounts.
So, let's start by adding a Role
to optimize and speed up the logging-in process that we perform in each test:
const { Selector, ClientFunction, Role } = require('testcafe');// ...const regularUser = Role('http://demo.redmine.org/', async (t) => {Â Â Â Â await t.click('.login')Â Â Â Â Â Â Â Â .typeText('#username', `test_user_testcafe_ poc${randomDigits1}@sharklasers.com`)Â Â Â Â Â Â Â Â .typeText('#password', 'test_user_testcafe_poc')Â Â Â Â Â Â Â ...