Skip to content

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

feat(goto): assume http:// for localhost navigations (#825)

Pavel Feldmanbdf8e39786c3
diff --git a/src/frames.ts b/src/frames.ts
index 94cc0bb154..23d4c9378b 100644
--- a/src/frames.ts
+++ b/src/frames.ts
@@ -381,7 +381,7 @@ export class Frame {
referer = options.referer;
}
const watcher = new LifecycleWatcher(this, options, false /* supportUrlMatch */);
-
+ url = helper.completeUserURL(url);
let navigateResult: GotoResult;
const navigate = async () => {
try {
diff --git a/src/helper.ts b/src/helper.ts
index c68af5e8a1..bf4e8f2bb4 100644
--- a/src/helper.ts
+++ b/src/helper.ts
@@ -211,6 +211,12 @@ class Helper {
tokens.push('$');
return new RegExp(tokens.join(''));
}
+
+ static completeUserURL(urlString: string): string {
+ if (urlString.startsWith('localhost') || urlString.startsWith('127.0.0.1'))
+ urlString = 'http://' + urlString;
+ return urlString;
+ }
}
export function assert(value: any, message?: string) {
diff --git a/test/navigation.spec.js b/test/navigation.spec.js
index 0213d2b17f..37607a14f9 100644
--- a/test/navigation.spec.js
+++ b/test/navigation.spec.js
@@ -28,6 +28,10 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
await page.goto(server.EMPTY_PAGE);
expect(page.url()).toBe(server.EMPTY_PAGE);
});
+ 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);
+ });
it('should work cross-process', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
expect(page.url()).toBe(server.EMPTY_PAGE);