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

Fix navigation bug #438

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ function waitUntilEnterPressed(error_log) {
readline.question('Press ENTER to continue...');
}

async function runInstruction(loadedInstruction, page, extras) {
try {
await loadedInstruction(page, extras);
return;
} catch (err) { // execution error
if (err.message && err.message.indexOf
&& err.message.indexOf('Execution context was destroyed') === 0) {
// Puppeteer error so this time we wait until the document is ready before trying
// again.
await page.waitForFunction('document.readyState === "complete"');
} else {
// Not a context error because of navigation, throwing it again.
throw err;
}
}
// We give it another chance...
await loadedInstruction(page, extras);
}

async function runAllCommands(loaded, logs, options, browser) {
logs.append(loaded['file'] + '... ');
const context_parser = loaded['parser'];
Expand Down Expand Up @@ -229,7 +248,6 @@ async function runAllCommands(loaded, logs, options, browser) {
return checkPageErrors('failOnRequestError', 'requestErrors', 'request failed');
};


let error_log = '';
const warnings = [];
let current_url = '';
Expand Down Expand Up @@ -276,7 +294,7 @@ async function runAllCommands(loaded, logs, options, browser) {
break command_loop;
}
try {
await loadedInstruction(page, extras);
await runInstruction(loadedInstruction, page, extras);
} catch (err) { // execution error
if (err === commands_parser.COLOR_CHECK_ERROR) {
error_log += `[ERROR] (line ${line_number}): ${err}\n`;
Expand Down
42 changes: 42 additions & 0 deletions tests/html_files/change-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<html>
<head>
<title>change page</title>
<style type="text/css">
body {
margin: 0;
background-color: #eee;
}
header {
background-color: #111;
width: 100%;
text-align: center;
font-size: 1.3em;
color: #fff;
}
.content {
text-align: center;
}
.content > a {
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #fff;
text-decoration: none;
color: #111;
}
Comment on lines +5 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any of this actually necessary?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just copied/pasted another file. Could be removed.

</style>
</head>
<body>
<header>change page</header>
<button id="js-wait-nav" onclick="changePage()">hey</button>
<script>
function changePage() {
setTimeout(() => {
const parts = document.location.pathname.split('/').filter(x => x.length > 0);
parts[parts.length - 1] = 'elements.html';
document.location.pathname = parts.join('/');
}, 250);
}
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions tests/ui-tests/page-change-in-wait.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This test ensures that the script is working as expecting even through browser navigation and
// page changes.
goto: "file://" + |CURRENT_DIR| + "/" + |DOC_PATH| + "/change-page.html"
assert-document-property: {"title": "change page"}
click: "#js-wait-nav"
wait-for-document-property: {"title": "Other page"}
5 changes: 5 additions & 0 deletions tests/ui-tests/page-change-in-wait.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=> Starting doc-ui tests...

page-change-in-wait... ok

<= doc-ui tests done: 1 succeeded, 0 failed