Skip to content

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

test(firefox): support loading of file URLs (#1132)

Andrey Lushnikov22c28b661589
diff --git a/test/interception.spec.js b/test/interception.spec.js
index 90fa5e33b5..035f84295d 100644
--- a/test/interception.spec.js
+++ b/test/interception.spec.js
@@ -642,15 +642,3 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
});
});
};
-
-/**
- * @param {string} path
- * @return {string}
- */
-function pathToFileURL(path) {
- let pathName = path.replace(/\\/g, '/');
- // Windows drive letter must be prefixed with a slash.
- if (!pathName.startsWith('/'))
- pathName = '/' + pathName;
- return 'file://' + pathName;
-}
diff --git a/test/navigation.spec.js b/test/navigation.spec.js
index 3c94b42b94..5bf278171a 100644
--- a/test/navigation.spec.js
+++ b/test/navigation.spec.js
@@ -16,6 +16,8 @@
*/
const utils = require('./utils');
+const path = require('path');
+const url = require('url');
/**
* @type {PageTestSuite}
@@ -30,6 +32,12 @@ module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FF
await page.goto(server.EMPTY_PAGE);
expect(page.url()).toBe(server.EMPTY_PAGE);
});
+ it('should work with file URL', async({page, server}) => {
+ const fileurl = url.pathToFileURL(path.join(__dirname, 'assets', 'frames', 'two-frames.html')).href;
+ await page.goto(fileurl);
+ expect(page.url().toLowerCase()).toBe(fileurl.toLowerCase());
+ expect(page.frames().length).toBe(3);
+ });
it('should use http for no protocol', async({page, server}) => {
await page.goto(server.EMPTY_PAGE.substring('http://'.length));
expect(page.url()).toBe(server.EMPTY_PAGE);
@@ -978,3 +986,4 @@ module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FF
}
}
};
+