-
Notifications
You must be signed in to change notification settings - Fork 674
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
Role has a large delay/wait after page load #3460
Comments
I've looked at your test code and at it seems valid to me. I would appreciate if you share your project with me. In this case, I'll be able to determine the cause of the issue more efficiently. |
I created a minimal working example The problem only occurs when I ask nock to intercept http traffic and if I then use a Rule. It does not occur if I run the rule as a test. Thus I think there is a difference when running a rule instead of a test, which is causing the delay. I tried using testcafe's Http mocking mechanism, but I couldn't get it to work and I found it harder to debug than nock, which offers logging out of the box. |
Hello, @inctec-leo. Thank you for providing additional information. I reproduced this issue on Windows 10, but I didn't reproduce it on another machine. I'm not sure if the issue is related to the Role mechanism. While we are working on it, you can use the following workaround: import { Role, RequestMock } from 'testcafe';
const authUserRole = Role('http://localhost:8080/login', async t => {
await t.typeText('#login-email', 'email');
await t.typeText('#login-password', 'password');
});
const mock = RequestMock()
.onRequestTo('/story/stories')
.respond('test', 200);
fixture(`Main Page`)
.page('http://localhost:8080/');
test
.requestHooks(mock)
('When logged in the user sees the list of stories', async t => {
await t.useRole(authUserRole);
// ...
}); |
Hi @Farfurix, fixture(`Login Page`)
.page('http://localhost:8080/login');
test('The user sends correct login information and is being logged in', async t => {
nock('http://localhost:8080')
.post('/auth/login')
.reply(200, { "token": "testtoken" });
await t.typeText('#login-email', 'email');
await t.typeText('#login-password', 'password');
}); then there is no delay at all. Edit: The proposed workaround does fix the delay, but it has no effect - http requests are not being mocked when using RequestMock. |
"http requests are not being mocked when using import { RequestMock } from "testcafe";
fixture `My Fixture`
.page `https://google.com`;
const mock = RequestMock()
.onRequestTo('https://google.com')
.respond('test', 200);
test
.requestHooks(mock)
('test', async (t) => {
await t
.wait(1000);
}); Could you please try to use Also I tested your test scenario with only |
Is there any update on this? I would really like to use testcafe with nock. The issue with RequestMock seems to be that I can't figure out why it's not matching my routes (the routes are being matched when using nock), however there are other reasons why I would prefer nock. Thanks. |
@inctec-leo Here is an example: test('test', async t => {
var t0 = performance.now();
nock('http://localhost:8080')
.get('/story/stories')
.reply(() => {
});
await t.debug();
var t1 = performance.now();
await t.navigateTo('http://localhost:8080');
var t2 = performance.now();
console.log("Navigate " + (t2 - t1) + " milliseconds.")
await t.debug();
}); It looks like the For the team: |
It's not a bug, it's the way There are a number of caveats when you use
|
That makes sense and fixes the issue, thanks for looking into this. |
Thank you for using TestCafe 😄 I lock this issue since the question is resolved. If you want to ask a new question - please create it on Stack Overflow. Also, don't hesitate to submit a new bug report or suggest an enhancement. |
Thanks for this great tool! I am experiencing a long delay when I am trying to use a Role to create a login token.
What is your Test Scenario?
I want to use
Role
to create a login token.What is the Current behavior?
Using a Role is taking unreasonably long after page load (>15 sec). Though the same code takes less than a second after page load when run as a test case.
What is the Expected behavior?
After page load, the Role callback should start right away, but it takes more than 15 seconds.
What is your web application and your TestCafe test code?
I have a simple form with mail and password fields, and a submit button. The submit button makes a post request, which I am mocking using nock. I am using node to serve the page.
If I run the code as a role, there is a waiting time of 15-17 seconds after the login page was loaded. This is the role:
This is how I am calling the role:
Your complete test report:
This is the test report for an empty test using the Rule
Steps to Reproduce:
Your Environment details:
EDIT: I just had the chance to run the test on Mac with Chrome, and the waiting time was significantly less, though there was still a recognizable delay of around 2-3 seconds after page load.
The text was updated successfully, but these errors were encountered: