Skip to content
Merged
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
37 changes: 22 additions & 15 deletions javascript/node/selenium-webdriver/common/seleniumManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const { platform } = require('process')
const path = require('path')
const fs = require('fs')
const execSync = require('child_process').execSync
const spawnSync = require('child_process').spawnSync

/**
* currently supported browsers for selenium-manager
Expand Down Expand Up @@ -53,7 +53,6 @@ function getBinary() {
} else {
seleniumManagerBasePath = path.join(__dirname, '..', '/bin')
}
console.log(seleniumManagerBasePath)

const filePath = path.join(seleniumManagerBasePath, directory, file)

Expand All @@ -77,7 +76,7 @@ function driverLocation(options) {
)
}

let args = [getBinary(), '--browser', options.getBrowserName(), '--output', 'json']
let args = ['--browser', options.getBrowserName(), '--output', 'json']

if (options.getBrowserVersion() && options.getBrowserVersion() !== "") {
args.push("--browser-version", options.getBrowserVersion())
Expand All @@ -89,22 +88,30 @@ function driverLocation(options) {
args.push("--browser-path", '"' + vendorOptions.binary + '"')
}

const smBinary = getBinary()
const spawnResult = spawnSync(smBinary, args)
let output
try {
output = JSON.parse(execSync(args.join(' ')).toString())
} catch (e) {
let error
try {
error = JSON.parse(e.stdout.toString()).result.message
} catch (e) {
if (e instanceof SyntaxError) {
error = e.stdout.toString()
} else {
error = e.toString()
if (spawnResult.status) {
let errorMessage
if (spawnResult.stderr.toString()) {
errorMessage = spawnResult.stderr.toString()
}
if (spawnResult.stdout.toString()) {
try {
output = JSON.parse(spawnResult.stdout.toString())
errorMessage = output.result.message
} catch (e) {
errorMessage = e.toString()
}
}
throw new Error(`Error executing command with ${args}: ${error}`)
throw new Error(`Error executing command for ${smBinary} with ${args}: ${errorMessage}`)
}
try {
output = JSON.parse(spawnResult.stdout.toString())
} catch (e) {
throw new Error(`Error executing command for ${smBinary} with ${args}: ${e.toString()}`)
}


for (const key in output.logs) {
if (output.logs[key].level === 'WARN') {
Expand Down