Skip to content

Commit 6d94706

Browse files
committed
[javascript] Using json output with Selenium Manager
Work done for #11365
1 parent 00a2624 commit 6d94706

5 files changed

Lines changed: 27 additions & 39 deletions

File tree

javascript/node/selenium-webdriver/chrome.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ class ServiceBuilder extends chromium.ServiceBuilder {
160160
let exe = opt_exe || locateSynchronously()
161161

162162
if (!exe) {
163-
console.log(
164-
` The ChromeDriver could not be found on the current PATH, trying Selenium Manager`
165-
)
166-
167163
try {
168164
exe = driverLocation(Browser.CHROME)
169165
} catch (err) {
@@ -173,10 +169,9 @@ class ServiceBuilder extends chromium.ServiceBuilder {
173169

174170
if (!exe) {
175171
throw Error(
176-
`The ChromeDriver could not be found on the current PATH.
177-
Please download the latest version of the ChromeDriver
178-
from http://chromedriver.storage.googleapis.com/index.html
179-
and ensure it can be found on your PATH.`
172+
`ChromeDriver could not be found on the PATH.
173+
For more information on how to install drivers see
174+
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/.`
180175
)
181176
}
182177

javascript/node/selenium-webdriver/common/seleniumManager.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,30 @@ function driverLocation(browser) {
6969
)
7070
}
7171

72-
let args = [getBinary(), '--browser', browser]
73-
let result
72+
let args = [getBinary(), '--browser', browser, '--output', 'json']
73+
let output
7474

7575
try {
76-
result = execSync(args.join(' ')).toString()
76+
output = JSON.parse(execSync(args.join(' ')).toString())
7777
} catch (e) {
78+
let error
79+
try {
80+
error = JSON.parse(e.stdout.toString()).result.message
81+
} catch (e) {
82+
error = e.toString()
83+
}
7884
throw new Error(
79-
`Error executing command with ${args}\n${e.stdout.toString()}${e.stderr.toString()}`
85+
`Error executing command with ${args}: ${error}`
8086
)
8187
}
8288

83-
if (!result.startsWith('INFO\t')) {
84-
throw new Error(`Unsuccessful command executed: ${args}\n${result}`)
89+
for (const key in output.logs){
90+
if (output.logs[key].level === 'WARN') {
91+
console.warn(`${output.logs[key].message}`)
92+
}
8593
}
8694

87-
return result.replace('INFO\t', '').trim()
95+
return output.result.message
8896
}
8997

9098
// PUBLIC API

javascript/node/selenium-webdriver/edge.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ class ServiceBuilder extends chromium.ServiceBuilder {
109109
let exe = opt_exe || locateSynchronously()
110110

111111
if (!exe) {
112-
console.log(
113-
`The WebDriver for Edge could not be found on the current PATH, trying Selenium Manager`
114-
)
115-
116112
try {
117113
exe = driverLocation('edge')
118114
} catch (err) {
@@ -122,13 +118,11 @@ class ServiceBuilder extends chromium.ServiceBuilder {
122118

123119
if (!exe) {
124120
throw Error(
125-
`The WebDriver for Edge could not be found on the current PATH. Please download the ` +
126-
`latest version of ${EDGEDRIVER_CHROMIUM_EXE} from ` +
127-
`https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ ` +
128-
`and ensure it can be found on your PATH.`
121+
`MSEdgeDriver could not be found on the PATH.
122+
For more information on how to install drivers see
123+
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/.`
129124
)
130125
}
131-
132126
super(exe)
133127
this.setLoopback(true)
134128
}

javascript/node/selenium-webdriver/firefox.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,6 @@ function findGeckoDriver() {
474474
let exe = locateSynchronously()
475475

476476
if (!exe) {
477-
console.log(
478-
`The ${GECKO_DRIVER_EXE} executable could not be found on the current PATH, trying Selenium Manager`
479-
)
480-
481477
try {
482478
exe = driverLocation(Browser.FIREFOX)
483479
} catch (err) {
@@ -487,9 +483,9 @@ function findGeckoDriver() {
487483

488484
if (!exe) {
489485
throw Error(
490-
`The ${GECKO_DRIVER_EXE} executable could not be found on the current PATH.
491-
Please download the latest version from https://github.com/mozilla/geckodriver/releases/
492-
and ensure it can be found on your PATH.`
486+
`GeckoDriver could not be found on the PATH.
487+
For more information on how to install drivers see
488+
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/.`
493489
)
494490
}
495491

javascript/node/selenium-webdriver/ie.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,6 @@ function createServiceFromCapabilities(capabilities) {
401401

402402
let exe = locateSynchronously()
403403
if (!exe) {
404-
console.log(
405-
`The ${IEDRIVER_EXE} executable could not be found on the current PATH, trying Selenium Manager`
406-
)
407-
408404
try {
409405
exe = driverLocation('iexplorer')
410406
} catch (err) {
@@ -414,10 +410,9 @@ function createServiceFromCapabilities(capabilities) {
414410

415411
if (!exe || !fs.existsSync(exe)) {
416412
throw Error(
417-
`${IEDRIVER_EXE} could not be found on the current PATH. Please ` +
418-
`download the latest version of ${IEDRIVER_EXE} from ` +
419-
'https://www.selenium.dev/downloads/ and ' +
420-
'ensure it can be found on your system PATH.'
413+
`IEDriver could not be found on the PATH.
414+
For more information on how to install drivers see
415+
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/.`
421416
)
422417
}
423418

0 commit comments

Comments
 (0)