chore: implement goBack/goForward for WebDriver BiDi (#11447)

This commit is contained in:
Alex Rudenko 2023-11-27 12:38:59 +01:00 committed by GitHub
parent bbff323edf
commit f8f1a0f06f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 10 deletions

View File

@ -97,6 +97,10 @@ export interface Commands {
params: Bidi.BrowsingContext.SetViewportParameters; params: Bidi.BrowsingContext.SetViewportParameters;
returnType: Bidi.EmptyResult; returnType: Bidi.EmptyResult;
}; };
'browsingContext.traverseHistory': {
params: Bidi.BrowsingContext.TraverseHistoryParameters;
returnType: Bidi.EmptyResult;
};
'input.performActions': { 'input.performActions': {
params: Bidi.Input.PerformActionsParameters; params: Bidi.Input.PerformActionsParameters;

View File

@ -31,6 +31,7 @@ import {
import type {CDPSession} from '../api/CDPSession.js'; import type {CDPSession} from '../api/CDPSession.js';
import type {BoundingBox} from '../api/ElementHandle.js'; import type {BoundingBox} from '../api/ElementHandle.js';
import type {WaitForOptions} from '../api/Frame.js'; import type {WaitForOptions} from '../api/Frame.js';
import type {HTTPResponse} from '../api/HTTPResponse.js';
import { import {
Page, Page,
PageEvent, PageEvent,
@ -65,6 +66,7 @@ import type {Viewport} from '../common/Viewport.js';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js'; import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js'; import {disposeSymbol} from '../util/disposable.js';
import {isErrorLike} from '../util/ErrorLike.js';
import type {BidiBrowser} from './Browser.js'; import type {BidiBrowser} from './Browser.js';
import type {BidiBrowserContext} from './BrowserContext.js'; import type {BidiBrowserContext} from './BrowserContext.js';
@ -905,12 +907,40 @@ export class BidiPage extends Page {
throw new UnsupportedOperation(); throw new UnsupportedOperation();
} }
override goBack(): never { override async goBack(
throw new UnsupportedOperation(); options: WaitForOptions = {}
): Promise<HTTPResponse | null> {
return await this.#go(-1, options);
} }
override goForward(): never { override async goForward(
throw new UnsupportedOperation(); options: WaitForOptions = {}
): Promise<HTTPResponse | null> {
return await this.#go(+1, options);
}
async #go(
delta: number,
options: WaitForOptions
): Promise<HTTPResponse | null> {
try {
const result = await Promise.all([
this.waitForNavigation(options),
this.#connection.send('browsingContext.traverseHistory', {
delta,
context: this.mainFrame()._id,
}),
]);
return result[0];
} catch (err) {
// TODO: waitForNavigation should be cancelled if an error happens.
if (isErrorLike(err)) {
if (err.message.includes('no such history entry')) {
return null;
}
}
throw err;
}
} }
override waitForDevicePrompt(): never { override waitForDevicePrompt(): never {

View File

@ -131,12 +131,6 @@
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["PASS"] "expectations": ["PASS"]
}, },
{
"testIdPattern": "[navigation.spec] navigation Page.goBack *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"]
},
{ {
"testIdPattern": "[network.spec] network *", "testIdPattern": "[network.spec] network *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -767,6 +761,18 @@
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[navigation.spec] navigation Page.goBack *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[navigation.spec] navigation Page.goBack *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{ {
"testIdPattern": "[navigation.spec] navigation Page.goto should fail when navigating to bad SSL", "testIdPattern": "[navigation.spec] navigation Page.goto should fail when navigating to bad SSL",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],