Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add webdriver bidi support #206

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
pattern: '{.renovaterc.json,renovate/default.json}'
test:
needs:
needs:
- lint
- prepare_matrix
strategy:
Expand Down Expand Up @@ -77,9 +77,9 @@ jobs:
shell: bash
run: |
if ["$RUNNER_OS" == "Windows"]; then
npm run test:ci
TEST_PLATFORM="$RUNNER_OS" npm run test:ci
else
DISPLAY=:99 npm run test:ci
DISPLAY=:99 TEST_PLATFORM="$RUNNER_OS" npm run test:ci
fi
release:
if: github.ref == 'refs/heads/main'
Expand Down
27 changes: 21 additions & 6 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CD_CONSTRAINTS = /** @type {const} */ ({
logPath: { isString: true },
autodownloadEnabled: { isBoolean: true },
disableBuildCheck: { isBoolean: true },
browserName: { isString: true }
browserName: { isString: true },
});

const STANDARD_CAPS_LOWER = new Set([...STANDARD_CAPS].map((cap) => cap.toLowerCase()));
Expand All @@ -38,6 +38,11 @@ export class ChromiumDriver extends BaseDriver {
proxyReqRes;
proxyCommand;

doesSupportBidi = true;

/** @type {string|null} */
_bidiProxyUrl = null;

proxyActive() {
return this._proxyActive;
}
Expand All @@ -46,6 +51,11 @@ export class ChromiumDriver extends BaseDriver {
return true;
}

get bidiProxyUrl() {
return this._bidiProxyUrl;
}


/**
*
* @param {W3CChromiumDriverCaps} jsonwpDesiredCapabilities
Expand All @@ -59,14 +69,17 @@ export class ChromiumDriver extends BaseDriver {
jsonwpRequiredCaps,
w3cCapabilities,
) {
const [sessionId, caps] = /** @type {[string, ChromiumDriverCaps]} */(await super.createSession(jsonwpDesiredCapabilities, jsonwpRequiredCaps, w3cCapabilities));
await this.startChromedriverSession();
return [sessionId, caps];
const [sessionId,] = /** @type {[string, ChromiumDriverCaps]} */(await super.createSession(jsonwpDesiredCapabilities, jsonwpRequiredCaps, w3cCapabilities));
jlipps marked this conversation as resolved.
Show resolved Hide resolved
const returnedCaps = await this.startChromedriverSession();
if (returnedCaps.webSocketUrl) {
this._bidiProxyUrl = (/** @type {string|null} */(/** @type {unknown} */(returnedCaps.webSocketUrl)));
}
return [sessionId, returnedCaps];
}

getSessionCaps() {
return Object.keys(this.opts).reduce((acc, capName) => {
if (STANDARD_CAPS_LOWER.has(capName) || capName.startsWith(CHROME_VENDOR_PREFIX) || capName.startsWith(EDGE_VENDOR_PREFIX)) {
if (STANDARD_CAPS_LOWER.has(capName.toLowerCase()) || capName.startsWith(CHROME_VENDOR_PREFIX) || capName.startsWith(EDGE_VENDOR_PREFIX)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cap names are case sensitive, aren't they?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, I needed this to fix an issue where caps were not properly forwarded to chromedriver.

acc[capName] = this.opts[capName];
}
return acc;
Expand All @@ -88,10 +101,11 @@ export class ChromiumDriver extends BaseDriver {
};

this.cd = new Chromedriver(cdOpts);
await this.cd.start(this.getSessionCaps());
const cdStartRes = /** @type {ChromiumDriverCaps} */(await this.cd.start(this.getSessionCaps()));
jlipps marked this conversation as resolved.
Show resolved Hide resolved
this._proxyActive = true;
this.proxyReqRes = this.cd.proxyReq.bind(this.cd);
this.proxyCommand = this.cd.sendCommand.bind(this.cd);
return cdStartRes;
}

/**
Expand All @@ -104,6 +118,7 @@ export class ChromiumDriver extends BaseDriver {
// @ts-ignore
await super.deleteSession(sessionId, driverData);
this._proxyActive = false;
this._bidiProxyUrl = null;
this.proxyReqRes = null;
this.proxyCommand = null;
if (this.cd) {
Expand Down
Loading