Skip to content

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

feat(webkit): add page back/forward commands (#144)

Yury Semikhatsky25af050bd4bb
diff --git a/src/webkit/Page.ts b/src/webkit/Page.ts
index 2540d7122f..2b0d142b08 100644
--- a/src/webkit/Page.ts
+++ b/src/webkit/Page.ts
@@ -267,6 +267,24 @@ export class Page extends EventEmitter {
return response;
}
+ async goBack(): Promise<network.Response | null> {
+ return await this._go('Page.goBack');
+ }
+
+ async goForward(): Promise<network.Response | null> {
+ return await this._go('Page.goForward');
+ }
+
+ async _go<T extends keyof Protocol.CommandParameters>(command: T): Promise<network.Response | null> {
+ const [response, error] = await Promise.all([
+ this.waitForNavigation(),
+ this._session.send(command).then(() => null).catch(e => e),
+ ]);
+ if (error)
+ return null;
+ return response;
+ }
+
async waitForNavigation(): Promise<network.Response | null> {
return await this._frameManager.mainFrame().waitForNavigation();
}
diff --git a/test/navigation.spec.js b/test/navigation.spec.js
index 5af9c269c8..44ee32d46c 100644
--- a/test/navigation.spec.js
+++ b/test/navigation.spec.js
@@ -466,7 +466,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
response = await page.goForward();
expect(response).toBe(null);
});
- it.skip(WEBKIT)('should work with HistoryAPI', async({page, server}) => {
+ it('should work with HistoryAPI', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
history.pushState({}, '', '/first.html');