diff --git a/javascript/node/selenium-webdriver/common/seleniumManager.js b/javascript/node/selenium-webdriver/common/seleniumManager.js index 9db638474c4da..7e253b6277f3f 100644 --- a/javascript/node/selenium-webdriver/common/seleniumManager.js +++ b/javascript/node/selenium-webdriver/common/seleniumManager.js @@ -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 @@ -53,7 +53,6 @@ function getBinary() { } else { seleniumManagerBasePath = path.join(__dirname, '..', '/bin') } - console.log(seleniumManagerBasePath) const filePath = path.join(seleniumManagerBasePath, directory, file) @@ -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()) @@ -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') {