-
Notifications
You must be signed in to change notification settings - Fork 36
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
Wait for promises explicitly, rather than putting them on the control flow #68
Comments
I think we should wait not only for the promise to get resolved, but also for all the control flow task queues to finish their execution. |
That will happen automatically because the |
See angular#68 for details
To be clear, this won't solve all issues with browser.wait(() => {
return (await elem.getText()) == 'go go go';
}); still has exactly the same problem. So I'm going to leave in the advice about leaving |
I'm not that sure after @jleyba 's explanations. The queues are independent. |
See angular#68 for details
So it doesn't wait for the rest of the scheduled tasks. |
We don't use the promise returned by the control flow to synchronize, we use the flow itself. |
What about this example? 'use strict';
const {promise} = require('selenium-webdriver');
const flow = promise.controlFlow();
flow.execute(() => {
console.log('a');
return promise.delayed(10);
});
flow.execute(() => console.log('b'));
flow.execute(() => console.log('c'));
setTimeout(() => {
// This is a new turn of the event loop, so tasks are scheduled in
// a separate queue
flow.execute(() => console.log('d'));
flow.execute(() => console.log('e'));
}, 0);
// a
// d
// e
// b
// c Inside the |
If you did: it('', (done) => {
flow.execute(() => {
check1()
return promise.delayed(10);
});
flow.execute(() => check2);
flow.execute(() => check3);
setTimeout(() => {
// This is a new turn of the event loop, so tasks are scheduled in
// a separate queue
flow.execute(() => check4);
flow.execute(() => check5);
done();
}, 0);
}) Then everything will work fine. You'll still have it('', () => { // No callback or returned promise
setTimeout(() => {
flow.execute(() => {
...
});
}, 10);
}) You could have problems. But there's nothing we can really do about this case |
We can. We should subscribe to the
|
I see your point that such tests are clearly a bad idea, but the idea of the current issue (as I see it) is to isolate bad tests as best as possible. Why not use the |
And this timeline:
|
Of course, it won't help in such a case. It won't give us a 100% protection. But it's still better than nothing. What I have in mind is code like my initial example from SeleniumHQ/selenium#3037: const savedAllScriptsTimeout = browser.allScriptsTimeout;
browser.allScriptsTimeout = 25000;
await browser.get('web2.aspx/DB/METAGANTT/ALL');
browser.allScriptsTimeout = savedAllScriptsTimeout;
$('.foo').click();
$('.bar').click();
// ... Basically, it's a mix of the async and sync styles. And |
Your case will be handled by my change already. Async will cause the |
The thing is that this returned promise won't wait for the tasks scheduled by |
Hmm, I'm not sure. The code: it('', async function() {
const savedAllScriptsTimeout = browser.allScriptsTimeout;
browser.allScriptsTimeout = 25000;
await browser.get('web2.aspx/DB/METAGANTT/ALL');
browser.allScriptsTimeout = savedAllScriptsTimeout;
$('.foo').click();
$('.bar').click();
}); Compiles to: const savedAllScriptsTimeout = browser.allScriptsTimeout;
browser.allScriptsTimeout = 25000;
it('', () => {
const savedAllScriptsTimeout = browser.allScriptsTimeout;
browser.allScriptsTimeout = 25000;
return browser.get('web2.aspx/DB/METAGANTT/ALL').then(() => {
browser.allScriptsTimeout = savedAllScriptsTimeout;
$('.foo').click();
$('.bar').click();
});
});
|
|
I know 😄 |
You're right 😞 |
See angular#68 for details
@thorn0 The PR has been updated to wait on the idle event |
See angular#68 for details
See angular#68 for details
See angular#68 for details
See angular#68 for details
See angular#68 for details
Right now if an
it()
block returns a promise, it gets put directly on the control flow, which causes problems if it isn't a WebDriver promise. Instead, we should explicitly use the promise's.then()
block. This will also help with the transition to supportingSELENIUM_PROMISE_MANAGER=0
The text was updated successfully, but these errors were encountered: