Skip to content
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

Handle timeout when waiting for page readiness #30

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/agent/driver-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { AgentMessage } from './messages.js';

const AFTER_NAVIGATION_DELAY = 1000;
const AFTER_KEYS_DELAY = 5000;
const AFTER_RUN_TEST_SETUP_BUTTON_DELAY = 5000;
const RUN_TEST_SETUP_BUTTON_TIMEOUT = 1000;

export class DriverTestRunner {
Expand Down Expand Up @@ -58,23 +57,25 @@ export class DriverTestRunner {
await this.webDriver.navigate().to(url.toString());

try {
const loaded = this.webDriver.executeAsyncScript(function (callback) {
new Promise(resolve => {
window.addEventListener('load', () => resolve());
})
// Wait until after any microtasks registered by other 'load' event
// handlers.
.then(() => Promise.resolve())
.then(callback);
await this.webDriver.executeAsyncScript(function (callback) {
if (document.readyState === 'complete') {
callback();
} else {
new Promise(resolve => {
window.addEventListener('load', () => resolve());
})
// Wait until after any microtasks registered by other 'load' event
// handlers.
.then(() => Promise.resolve())
.then(callback);
}
});

const runTestSetup = await this.webDriver.wait(
until.elementLocated(By.className('button-run-test-setup')),
RUN_TEST_SETUP_BUTTON_TIMEOUT
);
// TODO: Replace loaded and timeout race with a deterministic signal that
// the page is ready. This likely needs a change in aria-at's process.
await Promise.race([loaded, timeout(AFTER_RUN_TEST_SETUP_BUTTON_DELAY)]);

await runTestSetup.click();
} catch ({}) {
await this.log(AgentMessage.NO_RUN_TEST_SETUP, { referencePage });
Expand Down