-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setNativeDialogHandler
ignored when useRole
redirects to login page
#2969
Comments
Digging a little further, the problem may originate as in role's initialization the test run is switched to a clean state (which cleans testrun's Shouldn't the correct behaviour be?:
|
I've reproduced the issue. We'll see how we can improve this behavior. For now I recommend you use your workaround. In addition you can modify it in the following manner: import { Role, Selector } from 'testcafe';
const url = 'http://127.0.0.1:8080';
const user = new Role(`${url}/login.html`, async t => {
await t
.typeText('#user', 'user')
.typeText('#password', 'password')
.click('#submit');
});
fixture('Home')
test('My first test', async t => {
await t.setNativeDialogHandler((...args) => {
console.log('handler', args);
return true;
});
await t.useRole(user);
}); I've removed page declaration in the fixture. It'll start test from |
The example was just to provide a test escenario. In the real escenario, all the site's pages set I am eager to provide a PR with a fix, but idk what would be the correct approach :) |
As you previously mentioned, the issue occurs because test run is switched to a clean state before navigating to the login page. I think it is too early, so the correct approach will be to move const user = new Role(`${url}/login.html`, async t => {
await t.setNativeDialogHandler(...)
...
});
fixture('Home')
test('My first test', async t => {
await t.setNativeDialogHandler((...args) => {
console.log('handler', args);
return true;
});
await t.useRole(user);
}); You are welcome to make a PR with a fix if you want. |
If i navigate to the login page before switching to a clean run won't have the test run in an invalid state? (particularly regarding the current session). Isn't preferable to perform a navigation to a blank page, then switch to a clean run and finally perform the navigation to the login page? |
Navigation to the login page is a valid action. It does not lead to any internal changes in the test state because all internal states will be saved after role initialization. We consider this approach with the team as most acceptable. |
Which i meant with leaving the test run in an invalid state is, that, the problem of first navigating to the login page and then switching to a clean state is that the login page is loaded with the last used role. This will be a problem if the login page response depends on whether a user is logged or not. For example: const userA = ...;
const userB = ...;
test('Chat', async t => {
await t
.setNativeDialogHandler(() => true)
.useRole(userA)
// ...
.useRole(userB); // -> Fails
}); This test fails as the login page is loaded with This is why i'm suggesting to do:
|
We'd like to avoid navigating to the testRun.session.useStateSnapshot(null);
await this._navigateToLoginPage(testRun);
await testRun.switchToCleanRun(); |
@AlexKamaev is this issue still valid? I'm occurred this same issue now as @NickCis. |
@marcinlesek |
@AlexKamaev unfortunately, this workarounds mentioned here doesn't work for my case. Let's assume case as below (I couldn't pass urls to app because it's internal): // ...
const signInUrl = 'https://example.com';
const userData = {
email: 'email@email.com',
password: 'password',
};
const signIn = async (email, password) => {
const signInPage = new SignInPage();
await t.setNativeDialogHandler(() => true); // With or without
await signInPage.signIn(email, password);
};
const user = Role(
signInUrl,
async () => signIn(userData.email, userData.password)
);
const pageWithNativeDialogUrl = 'https://...';
const authCredentials = { ... };
const hook = new Hook(...);
fixture`role mechanics`
.page(pageWithNativeDialogUrl)
.httpAuth(authCredentials)
.requestHooks(hook);
test('test role mechanics', async (t) => {
const myPage = new MyPage();
const userPage = new UserPage();
await t.setNativeDialogHandler(() => true); // With or without
await myPage.firstAction();
await myPage.secondAction();
await t
.setNativeDialogHandler(() => true) // With or without
.useRole(user);
await userPage.firstActionAsUser();
await userPage.secondActionAsUser();
}); This case example made that test is performing actions on
I tried to add Thanks in advance! Best, |
@marcinlesek |
@AlexKamaev thanks for answer. Unfortunately, I couldn't provide any informations about project, above example is the most similar I could provide. Thanks for adding this issue to your current sprint, I hope it'll be fixed soon so we'll have opportunity to start using roles on our daily basis. Best, |
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow. |
…evExpress#2969) (DevExpress#3846) * reset dialog handlers only after test navigates to login page (closes DevExpress#2969) * refactor condition * refactor
Are you requesting a feature or reporting a bug?
Reporting a bug
What is the current behavior?
If the tested page has a listener to
beforeunload
(which returns a string),setNativeDialogHandler
is set up, anduseRole
is used, the test will always fail (note: only the tested page has thebeforeunload
listener, not the login one!).Console output:
What is the expected behavior?
setNativeDialogHandler
function is used, anduseRole
is performed correctly.How would you reproduce the current behavior (if this is a bug)?
Provide the test code and the tested page URL (if applicable)
Test case can be found on this gist:
A quick workarround is navigating to a page that hasn't attached the
beforeunload
:Specify your
Arch Linux (Kernel 4.18.12)
0.22.0
v10.0.0
The text was updated successfully, but these errors were encountered: