Skip to content

Instantly share code, notes, and snippets.

@AlexanderMoskovkin
Created February 26, 2020 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderMoskovkin/2197aceec9cfb01a95f3cb808d731f81 to your computer and use it in GitHub Desktop.
Save AlexanderMoskovkin/2197aceec9cfb01a95f3cb808d731f81 to your computer and use it in GitHub Desktop.
TestCafe Studio Roles using (Case 1)
var tc = require('testcafe');
var Role = tc.Role;
var Selector = tc.Selector;
var RoleHelper = require('./role-helper-1');
await t.useRole(RoleHelper.getEmptyRole(Selector, Role));
run in recording - works OK
run from testcafe console - works OK
run from TestCafe Studio play button - An unhandled error occurred in the custom script:
The "role" argument is expected to be a Role instance, but it was object.
{"fixtures":[{"name":"Roles Demo","pageUrl":"https://reportse2e.iszolea.net/","tests":[{"name":"Case 1","commands":[{"callsite":"0","expression":"var tc = require('testcafe');\r\nvar Role = tc.Role;\r\nvar Selector = tc.Selector;\r\n\r\nvar RoleHelper = require('./role-helper-1');\r\n\r\nawait t.useRole(RoleHelper.getEmptyRole(Selector, Role));","studio":{},"type":"execute-async-expression"}]}]}]}
var useRole = async (Selector, t, login, password) => {
await t
.click(Selector('span').withText('SIGN IN'))
.typeText(Selector('.login-form').find('[name="Username"]'), login)
.typeText(Selector('.login-form').find('[name="Password"]'), password)
.click(Selector('span').withText('Login'));
}
module.exports.getEmptyRole = (Selector, Role) => {
var role = Role('https://reportse2e.iszolea.net/', async t => {
await useRole(Selector, t, 'E2EUserEmpty', 'E2EUserEmpty!');
});
return role;
}
@AlexanderMoskovkin
Copy link
Author

NOTES:
Case1.testcafe - test with only one step. It's a script step. I'm trying to call UseRole inside that step. I keep the Role object in a separated file (role-helper-1.js).
You can see the code of this step in the case1 - script step.txt

You can try to run it in three ways (from studio via recording and via play button and from console testcafe app). Results of running are in the case1 results.txt. So the problem it works in two cases but doesnt work in the third

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment