Skip to content

Commit

Permalink
Merge pull request #438 from GuillaumeGomez/fix-navigation-bug
Browse files Browse the repository at this point in the history
Fix navigation bug
  • Loading branch information
GuillaumeGomez authored Feb 23, 2023
2 parents 7fa65fe + 9ad44b8 commit c54e43a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
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;
}
</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

0 comments on commit c54e43a

Please sign in to comment.