1

when using roles in TestCafe I can't seem to get roles to correctly logout. Or, more importantly I can't get two consecutive tests to execute using the same Role.

A little background:

I am testing an enterprise website (Sorry, cannot share) that requires a login. When using t.useRole(account) the login works perfectly. My issue arises when I have two consecutive tests that log in with the same account. The first login will succeed and the second will fail. When this happened I added console logs to tell when the login block gets called and I don't receive from the second test. When reading the User Roles documentation it shows that when a role is initialized a cookie is generated and subsequent useRole calls will reload the page for the given account. For some reason, this doesn't work in my environment as the page I'm testing is redirected to the login page.
At this point my solution was to issue a logout method but this didn't help. I have also tried to switch to an Anonymous user as part of my logout, again with no success.

Example logout Code (using page model):

async function logout (t) {
await t
    .expect(accountDropdown.exists).ok()
    .click(accountDropdown)
    .expect(accountLogout.exists).ok()
    .click(accountLogout)
    .useRole(Role.anonymous());
};

Example Role Code:

const normalUser = Role(`${url}`, async t=>{
console.log(' - Logging in as Normal User')
await t
    .expect(await loginEmail.exists).ok()
    .click(loginEmail)
    .typeText(loginEmail, env.Email)
    .click(loginPassword)
    .typeText(loginPassword, env.Password)
    .click(loginSubmit)
    if( manageAccount.exists ) {
        await t.click(manageAccount)
    } 
}, { preserveUrl: true });

At this point I am stumped. Any help or suggestions is greatly appreciated.

Liam
  • 11
  • 2
  • TestCafe should work properly with this scenario. At the same time, we have been informed that some of our users encountered a similar issue. Unfortunately, we could not reproduce the problem locally as none of the users provided an example. Would you please emulate this issue with a brand new project and send a link to us? It is possible there is a bug, which is reproduced under specific settings. You can also send us a private message with a link to your real web site with temporary login details at https://www.devexpress.com/Support/Center/Question/Create – Marion Aug 02 '18 at 10:28
  • Thank you. I have sent a private message with a project sample that reproduces the issue. – Liam Aug 02 '18 at 15:09

1 Answers1

0

The issue is caused by simultaneous use of the preserveUrl and pageUrl functions. We are going to investigate this issue further in the context of the following issue:

The preserveUrl and pageUrl functions do not work together

For now, I suggest you delete pageUrl as it is not necessary when using preserveUrl:

 const normalUser = Role(`${url}`, async t=>{
      console.log(' - Logging in as Normal User')
      // ...
 }, { preserveUrl: true });

 fixture `LiveManager` 
     //.page`URL`  
     .beforeEach( async t => {
       await t.setTestSpeed(0.85);
 })
Marion
  • 1,074
  • 5
  • 10
  • Thank you, I have made the suggested changes and it works most of the time. The times it does not work the proxy fails to load the page when doing a Role switch and I get an error of `Error while restoring configuration after Role switch`. – Liam Aug 07 '18 at 14:10
  • We've never been informed about a similar issue before. Would you please send us the modified project to our Support Center for research? – Marion Aug 08 '18 at 11:14
  • Hello, I have been trying to get a project that reproduces this issue. However, this error is intermittent and I have not had success at consistently reproducing the error. Does the proxy produce any logs for troubleshooting? – Liam Aug 13 '18 at 15:11
  • Just realized I omitted some information that might be useful. I'm using testcafe-live with the following command `testcafe-live chrome .\tests\.js --assertion-timeout 5000 --debug-on-fail`. When the failure occurs I get a blank screen in Chrome and the stack error of `Error while restoring configuration after Role switch` – Liam Aug 13 '18 at 19:36