Skip to content

Commit 0b05332

Browse files
authored
chore/connect to CDP based on ENV selenium address var (#10255)
1 parent fa87376 commit 0b05332

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

‎javascript/node/selenium-webdriver/lib/http.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function requireAtom(module, bazelTarget) {
6363
console.log(ex2)
6464
throw Error(
6565
`Failed to import atoms module ${module}. If running in dev mode, you` +
66-
` need to run \`bazel build ${bazelTarget}\` from the project` +
67-
`root: ${ex}`
66+
` need to run \`bazel build ${bazelTarget}\` from the project` +
67+
`root: ${ex}`
6868
)
6969
}
7070
}
@@ -197,7 +197,6 @@ function toExecuteAtomCommand(command, atom, ...params) {
197197

198198
/** @const {!Map<string, (CommandSpec|CommandTransformer)>} */
199199
const W3C_COMMAND_MAP = new Map([
200-
201200
// Session management.
202201
[cmd.Name.NEW_SESSION, post('/session')],
203202
[cmd.Name.QUIT, del('/session/:sessionId')],
@@ -245,7 +244,6 @@ const W3C_COMMAND_MAP = new Map([
245244
[cmd.Name.CLEAR_ACTIONS, del('/session/:sessionId/actions')],
246245
[cmd.Name.PRINT_PAGE, post('/session/:sessionId/print')],
247246

248-
249247
// Locating elements.
250248
[cmd.Name.GET_ACTIVE_ELEMENT, get('/session/:sessionId/element/active')],
251249
[cmd.Name.FIND_ELEMENT, post('/session/:sessionId/element')],
@@ -266,7 +264,10 @@ const W3C_COMMAND_MAP = new Map([
266264
],
267265
// Element interaction.
268266
[cmd.Name.GET_ELEMENT_TAG_NAME, get('/session/:sessionId/element/:id/name')],
269-
[cmd.Name.GET_DOM_ATTRIBUTE, get('/session/:sessionId/element/:id/attribute/:name')],
267+
[
268+
cmd.Name.GET_DOM_ATTRIBUTE,
269+
get('/session/:sessionId/element/:id/attribute/:name'),
270+
],
270271
[
271272
cmd.Name.GET_ELEMENT_ATTRIBUTE,
272273
(cmd) => {
@@ -363,7 +364,7 @@ class Client {
363364
* @return {!Promise<Response>} A promise that will be fulfilled with the
364365
* server's response.
365366
*/
366-
send(httpRequest) { } // eslint-disable-line
367+
send(httpRequest) {} // eslint-disable-line
367368
}
368369

369370
/**
@@ -609,5 +610,5 @@ module.exports = {
609610
Request: Request,
610611
Response: Response,
611612
// Exported for testing.
612-
buildPath: buildPath
613+
buildPath: buildPath,
613614
}

‎javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,14 +1197,25 @@ class WebDriver {
11971197
* @return {!Promise<resolved>} A new CDP instance.
11981198
*/
11991199
async createCDPConnection(target) {
1200+
let debuggerUrl = null
1201+
12001202
const caps = await this.getCapabilities()
1201-
const seCdp = caps['map_'].get('se:cdp')
1202-
const vendorInfo =
1203-
caps['map_'].get(this.VENDOR_COMMAND_PREFIX + ':chromeOptions') ||
1204-
caps['map_'].get(this.VENDOR_CAPABILITY_PREFIX + ':edgeOptions') ||
1205-
caps['map_'].get('moz:debuggerAddress') ||
1206-
new Map()
1207-
const debuggerUrl = seCdp || vendorInfo['debuggerAddress'] || vendorInfo
1203+
1204+
if (process.env.SELENIUM_REMOTE_URL) {
1205+
const host = new URL(process.env.SELENIUM_REMOTE_URL).host
1206+
const sessionId = await this.getSession().then((session) =>
1207+
session.getId()
1208+
)
1209+
debuggerUrl = `ws://${host}/session/${sessionId}/se/cdp`
1210+
} else {
1211+
const seCdp = caps['map_'].get('se:cdp')
1212+
const vendorInfo =
1213+
caps['map_'].get(this.VENDOR_COMMAND_PREFIX + ':chromeOptions') ||
1214+
caps['map_'].get(this.VENDOR_CAPABILITY_PREFIX + ':edgeOptions') ||
1215+
caps['map_'].get('moz:debuggerAddress') ||
1216+
new Map()
1217+
debuggerUrl = seCdp || vendorInfo['debuggerAddress'] || vendorInfo
1218+
}
12081219
this._wsUrl = await this.getWsUrl(debuggerUrl, target, caps)
12091220
return new Promise((resolve, reject) => {
12101221
try {
@@ -1945,14 +1956,10 @@ class Window {
19451956
* @return {!Promise<{x: number, y: number, width: number, height: number}>}
19461957
* A promise that will resolve to the window rect of the current window.
19471958
*/
1948-
async getRect() {
1949-
try {
1950-
return await this.driver_.execute(
1951-
new command.Command(command.Name.GET_WINDOW_RECT)
1952-
)
1953-
} catch (ex) {
1954-
throw ex
1955-
}
1959+
getRect() {
1960+
return this.driver_.execute(
1961+
new command.Command(command.Name.GET_WINDOW_RECT)
1962+
)
19561963
}
19571964

19581965
/**
@@ -1969,19 +1976,15 @@ class Window {
19691976
* A promise that will resolve to the current window's updated window
19701977
* rect.
19711978
*/
1972-
async setRect({ x, y, width, height }) {
1973-
try {
1974-
return await this.driver_.execute(
1975-
new command.Command(command.Name.SET_WINDOW_RECT).setParameters({
1976-
x,
1977-
y,
1978-
width,
1979-
height,
1980-
})
1981-
)
1982-
} catch (ex) {
1983-
throw ex
1984-
}
1979+
setRect({ x, y, width, height }) {
1980+
return this.driver_.execute(
1981+
new command.Command(command.Name.SET_WINDOW_RECT).setParameters({
1982+
x,
1983+
y,
1984+
width,
1985+
height,
1986+
})
1987+
)
19851988
}
19861989

19871990
/**
@@ -2544,7 +2547,10 @@ class WebElement {
25442547
keys.join('')
25452548
)
25462549
} catch (ex) {
2547-
console.log('Error trying parse string as a file with file detector; sending keys instead' + ex)
2550+
console.log(
2551+
'Error trying parse string as a file with file detector; sending keys instead' +
2552+
ex
2553+
)
25482554
}
25492555

25502556
return this.execute_(
@@ -2715,14 +2721,8 @@ class WebElement {
27152721
* @return {!Promise<{width: number, height: number, x: number, y: number}>}
27162722
* A promise that will resolve with the element's rect.
27172723
*/
2718-
async getRect() {
2719-
try {
2720-
return await this.execute_(
2721-
new command.Command(command.Name.GET_ELEMENT_RECT)
2722-
)
2723-
} catch (err) {
2724-
throw err;
2725-
}
2724+
getRect() {
2725+
return this.execute_(new command.Command(command.Name.GET_ELEMENT_RECT))
27262726
}
27272727

27282728
/**

0 commit comments

Comments
 (0)