TestCafe: User Role logs out the user in the first test

大城市里の小女人 提交于 2020-01-24 20:38:06

问题


I'm trying to implement User Role in my existing tests as I don't want to login in every tests. Here is what my tests look like:

const accountUser = Role('https://localhost:9000', async (t) => {
  await t.wait(1000);
  await loginPage.login(inputData.emailId, inputData.password);
}, { preserveUrl: true });

fixture`login-test`
  .meta('testingType', 'regression')
  .requestHooks(mock)

test('Add a person', async (t) => {
  await t.useRole(accountUser);
  await loginPage.goToPeopleList(inputData.testAccountFirst);

test('Unable to add a person', async (t) => {
  await t.useRole(accountUser);
  await loginPage.goToPeopleList(inputData.testAccountFirst);

Error:

✖ Add a person

   1) The specified selector does not match any element in the DOM tree.

       > | Selector('td')
         |   .withText('automation test')

      Browser: Chrome 79.0.3945 / Mac OS X 10.14.6

         258 |  }
         259 |
         260 |  async goToPeopleList(account) {
         261 |    // people list
         262 |    await t
       > 263 |      .click(accountManager.selectTestAccount(account))

What happens here is :

  • test 1: User is logged in and then fails at await loginPage.goToPeopleList(inputData.testAccountFirst); because the user is logged out
  • test 2: User is not even logged in and is expecting the already logged in page so it fails at step await loginPage.goToPeopleList(inputData.testAccountFirst);

Looked at the troubleshooting documentation and tried but still it kicks out the logged in user.

I don't know why user is logged out just after this step await t.useRole(accountUser);. The authentication token is stored in the cookie after login when I see it manually. At the very least I would expect first test to pass as it already logged in the user.

来源:https://stackoverflow.com/questions/59631796/testcafe-user-role-logs-out-the-user-in-the-first-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!