I'm investigating TestCafe to use as my test automation framework, and I've hit a bit of a stumbling block in regards to executing a function using the Rendr App on my AUT. With Cypress.io, Protractor and Puppeteer etc I'm able to run the same command... so I'm not too sure where I'm going wrong with TestCafe.
Essentially what I'm trying to execute is:
window.App.get('currentUser').set('login_state', 'someLoginState');
Cypress
cy.window().then((win) => {
win.App.get('currentUser').set('login_state', 'someState');
});
Protractor
function changeUserState() {
App.get('currentUser').set('login_state', 'someState');
}
browser.executeScript(changeUserState);
Puppeteer
function changeUserState() {
window.App.get('currentUser').set('login_state', 'someState');
}
await page.evaluate(changeUserState);
For TestCafe I've tried to use:
const changeUserState = ClientFunction((desiredState) => {
return App.get('currentUser').set('login_state', desiredState);
});
fixture `User states`
.page(url)
.afterEach( async t => {
await t
logout();
});
test('Change a users log in state', async t => {
await loginForm.loginViaUrl(userEmail, userPassword);
await changeUserState('SomeState');
await checkUserState('SomeState'); // Just an example of what I would do next
}
When running this, it throws a ReferenceError: App is not defined
error.
(I've also attempted the above options using 'window.App.get...': TypeError: Cannot read property 'get' of undefined
- Adding a wait prior to the calling the ClientFunction doesn't affect the oucome)
UPDATE
Based on comments, the t.eval(...)
option shouldn't be used as I'm accessing client side functionality.
I think the problem is related to the fact that the App variable is not defined. So you should wait until it becomes available. You can use the wait action with the fixed waiting time or use the following selector to wait until an element appears on the page:
UPD: Having examined the test example you provided in your Github issue, we found a solution for you. It is necessary to wait until the
App
variable appears. Add the following code before thechangeUserState
function call:UPD from the GitHub comment:
Result: