Bug
There is a script error thrown in Firefox, IE, and Edge when using a Role that is causing the test to fail. Using the skipJsErrors option is a work-around for this issue for Firefox and IE, but I don't understand why there is an error in these browsers but not Chrome. I also only see the error when using a Role.
This is the output I see:
1) - Error in Role initializer -
Error on page "https://beta.cesium.com/signin":
Error: Script error for "main"
http://requirejs.org/docs/errors.html#scripterror
Browser: Firefox 55.0.0 / Windows 10 0.0.0
The tests does not fail
Run this test:
'use strict';
var testcafe = require('testcafe');
var Role = testcafe.Role;
fixture('SignIn')
.page('https://beta.cesium.com/signin');
var user = new Role('https://beta.cesium.com/signin', function (tc) {
return tc
.typeText('input[type="text"]', 'fake user')
.typeText('input[type="password"]', 'fake password')
.click('button.btn-primary');
});
test('Signs in', function(tc) {
return tc
.useRole(user);
});
I updated my original post. I'm able to reproduce this in Firefox, IE and Edge.
For Edge in particular, I keep seeing this error:
Error while restoring configuration after Role switch -
Error on page "https://beta.cesium.com/signin":
Script error for "main"
http://requirejs.org/docs/errors.html#scripterror
Browser: Edge 15.15063.0 / Windows 10 0.0.0
It seems to be related to using roles.
Thanks for looking into this!
Hi @hpinkos,
Thanks a lot for you clarification. I've reproduced the problem and we will try to fix it. It seems it's related to the Role mechanism because it's all ok if I perform the same actions without Role:
const login = async t => {
await t
.typeText('input[type="text"]', 'fake user')
.typeText('input[type="password"]', 'fake password')
.click('button.btn-primary');
};
test('Signs in', function (tc) {
//return tc.useRole(user);
return login(tc);
});
Yep, I noticed that too. Thanks @AlexanderMoskovkin!
Hi @hpinkos,
I just got back to issue. I've found that I can reproduce it on the original page without TestCafe. It's reproduced if I force page reload during it's loading (see the screencast).
This is a way how Roles work. When you call t.useRole it loads the page that is set as the URL of the login page. The page raises the error in this moment. So you can fix it on your side. Or you can use the following workaround. Wait while the page is loaded before calling useRole:
import { Role, Selector } from 'testcafe';
fixture('SignIn')
.page('https://beta.cesium.com/signin')
.beforeEach(async t => {
await t.expect(Selector('input[type="text"]').exists).ok({ timeout: 10000 });
});
var user = new Role('https://beta.cesium.com/signin', function (tc) {
return tc
.typeText('input[type="text"]', 'fake user')
.typeText('input[type="password"]', 'fake password')
.click('button.btn-primary');
});
test('Signs in', function(tc) {
return tc
.useRole(user);
});
Thanks for looking into it @AlexanderMoskovkin!
The suggested workaround solves this for us as well. We're seeing the same issue in Firefox (we haven't tried IE11/Edge yet).
Can you clarify what you mean with "you can fix it on your side"?
We're using requirejs as it's documented so I'm not clear what we'd "fix" on our end.
Thanks!
@viveleroi, the page from the original post throws an error when a user navigates from it to a different page while it is still being loaded. So Alex's suggestion was about fixing the error that occurs when page loading is interrupted. If you think that it is a requirejs problem, you can contact the requirejs team and ask how this error can be avoided.
Is there a way to detect app-side when it's being run inside a testcafe context?
I can filter out these errors using the requirejs onError method but I'd rather only do that when being run inside testcafe. I suppose I can set a window.isTestCafe bool myself with ClientFunction but I hoped there was something already.
@viveleroi, you can check if window['%hammerhead%'] is not undefined.
Since the original problem is resolved, please consider creating a new issue or asking a question on Stack Overflow if you need any assistance.