Skip to content

Commit

Permalink
[javascript] Using json output with Selenium Manager
Browse files Browse the repository at this point in the history
Work done for #11365
  • Loading branch information
diemol committed Mar 20, 2023
1 parent 00a2624 commit 6d94706
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
11 changes: 3 additions & 8 deletions javascript/node/selenium-webdriver/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ class ServiceBuilder extends chromium.ServiceBuilder {
let exe = opt_exe || locateSynchronously()

if (!exe) {
console.log(
` The ChromeDriver could not be found on the current PATH, trying Selenium Manager`
)

try {
exe = driverLocation(Browser.CHROME)
} catch (err) {
Expand All @@ -173,10 +169,9 @@ class ServiceBuilder extends chromium.ServiceBuilder {

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

Expand Down
22 changes: 15 additions & 7 deletions javascript/node/selenium-webdriver/common/seleniumManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,30 @@ function driverLocation(browser) {
)
}

let args = [getBinary(), '--browser', browser]
let result
let args = [getBinary(), '--browser', browser, '--output', 'json']
let output

try {
result = execSync(args.join(' ')).toString()
output = JSON.parse(execSync(args.join(' ')).toString())
} catch (e) {
let error
try {
error = JSON.parse(e.stdout.toString()).result.message
} catch (e) {
error = e.toString()
}
throw new Error(
`Error executing command with ${args}\n${e.stdout.toString()}${e.stderr.toString()}`
`Error executing command with ${args}: ${error}`
)
}

if (!result.startsWith('INFO\t')) {
throw new Error(`Unsuccessful command executed: ${args}\n${result}`)
for (const key in output.logs){
if (output.logs[key].level === 'WARN') {
console.warn(`${output.logs[key].message}`)
}
}

return result.replace('INFO\t', '').trim()
return output.result.message
}

// PUBLIC API
Expand Down
12 changes: 3 additions & 9 deletions javascript/node/selenium-webdriver/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ class ServiceBuilder extends chromium.ServiceBuilder {
let exe = opt_exe || locateSynchronously()

if (!exe) {
console.log(
`The WebDriver for Edge could not be found on the current PATH, trying Selenium Manager`
)

try {
exe = driverLocation('edge')
} catch (err) {
Expand All @@ -122,13 +118,11 @@ class ServiceBuilder extends chromium.ServiceBuilder {

if (!exe) {
throw Error(
`The WebDriver for Edge could not be found on the current PATH. Please download the ` +
`latest version of ${EDGEDRIVER_CHROMIUM_EXE} from ` +
`https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ ` +
`and ensure it can be found on your PATH.`
`MSEdgeDriver could not be found on the PATH.
For more information on how to install drivers see
https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/.`
)
}

super(exe)
this.setLoopback(true)
}
Expand Down
10 changes: 3 additions & 7 deletions javascript/node/selenium-webdriver/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,6 @@ function findGeckoDriver() {
let exe = locateSynchronously()

if (!exe) {
console.log(
`The ${GECKO_DRIVER_EXE} executable could not be found on the current PATH, trying Selenium Manager`
)

try {
exe = driverLocation(Browser.FIREFOX)
} catch (err) {
Expand All @@ -487,9 +483,9 @@ function findGeckoDriver() {

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

Expand Down
11 changes: 3 additions & 8 deletions javascript/node/selenium-webdriver/ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,6 @@ function createServiceFromCapabilities(capabilities) {

let exe = locateSynchronously()
if (!exe) {
console.log(
`The ${IEDRIVER_EXE} executable could not be found on the current PATH, trying Selenium Manager`
)

try {
exe = driverLocation('iexplorer')
} catch (err) {
Expand All @@ -414,10 +410,9 @@ function createServiceFromCapabilities(capabilities) {

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

Expand Down

0 comments on commit 6d94706

Please sign in to comment.