Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test(goto): add failing load event test for webkit (#8809)

Joel Einbinder7fe30bb18221
diff --git a/tests/assets/load-event/load-event.html b/tests/assets/load-event/load-event.html
new file mode 100644
index 0000000000..edd5ae2260
--- /dev/null
+++ b/tests/assets/load-event/load-event.html
@@ -0,0 +1,23 @@
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Load Event Test</title>
+</head>
+<body>
+ <script>
+ window.results = [];
+ window.addEventListener('load', function() {
+ window.results.push('load');
+ });
+ window.addEventListener('DOMContentLoaded', function() {
+ window.results.push('DOMContentLoaded');
+ });
+ </script>
+ <script type="module" src="./module.js"></script>
+ <script>
+ window.results.push('script tag after after module');
+ </script>
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/assets/load-event/module.js b/tests/assets/load-event/module.js
new file mode 100644
index 0000000000..0418190a3c
--- /dev/null
+++ b/tests/assets/load-event/module.js
@@ -0,0 +1,3 @@
+import {foo} from '/slow.js';
+console.log('foo is', foo);
+window.results.push('module');
diff --git a/tests/page/page-goto.spec.ts b/tests/page/page-goto.spec.ts
index 9cca4f2d64..04a4e5a729 100644
--- a/tests/page/page-goto.spec.ts
+++ b/tests/page/page-goto.spec.ts
@@ -526,3 +526,21 @@ it('should not crash when RTCPeerConnection is used', async ({ page, server, bro
});
});
});
+
+it('should properly wait for load', async ({page, server, browserName}) => {
+ it.fixme(browserName === 'webkit', 'WebKit has a bug where Page.frameStoppedLoading is sent too early.');
+ server.setRoute('/slow.js', async (req, res) => {
+ await new Promise(x => setTimeout(x, 100));
+ res.writeHead(200, {'Content-Type': 'application/javascript'});
+ res.end(`window.results.push('slow module');export const foo = 'slow';`);
+ });
+ await page.goto(server.PREFIX + '/load-event/load-event.html');
+ const results = await page.evaluate('window.results');
+ expect(results).toEqual([
+ 'script tag after after module',
+ 'slow module',
+ 'module',
+ 'DOMContentLoaded',
+ 'load'
+ ]);
+});