Search code examples
testingautomationautomated-testse2e-testingtestcafe

Strict mode testcafe


I have an external login page with OAuth. I would like to use it with Testcafe for running e2e tests. In a normal scenario I can login without any issues. No errors are given. If I run testcafe, I get the following error:

- Error in Role initializer -
      A JavaScript error occurred on ...
Repeat test actions in the browser and check the console for errors.
      If you see this error, it means that the tested website caused it. You can fix it or disable tracking JavaScript errors in TestCafe. To do the
      latter, enable the "--skip-js-errors" option.
      If this error does not occur, please write a new issue at:
      "https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md".
      
      JavaScript error details:
      SyntaxError: In strict mode code, functions can only be declared at top level or inside a block.

      Browser: Chrome 88.0.4324.146 / macOS 10.15.7

Skipping errors is not a solution, as the script won't load, and I cannot login to the site.

The test looks like the following:

export const adminRole = Role(
  `https://url of the oauth site`,
  async (t) => {
    await t
      .typeText(Selector('#username'), 'username')
      .typeText(Selector('#password'), 'strongpassword')
      .click(Selector('#mainButton'));
  },
  { preserveUrl: true }
);

fixture('Home page');

test('Show profile page', async (t) => {
  await t.useRole(adminRole);
  await t.navigateTo('http://tested site/profile');
  await waitForAngular();
});

Solution

  • This is a bug. You can catch up on Github.