Skip to content

Commit 3faf729

Browse files
committed
defensive crash if chromedriver fails to start
1 parent 3a3ab1e commit 3faf729

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test:e2e": "jest --testMatch \"**/packages/**/__tests__/**/*.e2e.js\"",
1616
"lint": "yarn lint:scripts",
1717
"lint:scripts": "eslint --ignore-pattern node_modules --ignore-pattern third-party --ignore-pattern dist --ignore-pattern build --ignore-pattern json --ext .ts,.tsx --ext .js packages/",
18-
"test:side-runner": "./node_modules/@seleniumhq/side-runner/dist/bin.js ./tests/examples/*.side",
18+
"test:side-runner": "./node_modules/@seleniumhq/side-runner/dist/bin.js ./tests/examples/simple-parent.side",
1919
"typecheck": "tsc --noEmit --composite false",
2020
"watch": "run-p watch:ts watch:webpack",
2121
"watch:webpack": "lerna run --parallel --stream --scope @seleniumhq/selenium-ide --loglevel verbose watch",

packages/selenium-ide/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/selenium-ide",
3-
"version": "4.0.0-alpha.6",
3+
"version": "4.0.0-alpha.7",
44
"private": true,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",

packages/selenium-ide/src/main/session/controllers/Driver/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { WebDriverExecutor } from '@seleniumhq/side-runtime'
33
import { ChildProcess } from 'child_process'
44
import { BrowserInfo, Session } from 'main/types'
55
import downloadDriver from './download'
6-
import startDriver, { WebdriverDebugLog } from './start'
6+
import startDriver, { port, WebdriverDebugLog } from './start'
77
import BaseController from '../Base'
88

99
// Escape hatch to avoid dealing with rootDir complexities in TS
@@ -59,7 +59,7 @@ export default class DriverController extends BaseController {
5959
},
6060
},
6161
// The "9515" is the port opened by chrome driver.
62-
server = 'http://localhost:9515',
62+
server = 'http://localhost:' + port,
6363
}: DriverOptions): Promise<WebDriverExecutor> {
6464
const driver: WebDriverExecutor = new WebDriverExecutor({
6565
capabilities: {
@@ -136,6 +136,7 @@ export default class DriverController extends BaseController {
136136
this.driverProcess = results.driver
137137
return null
138138
}
139+
console.error('Failed to start chromedriver process', results.error)
139140
return results.error
140141
}
141142

packages/selenium-ide/src/main/session/controllers/Driver/start.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolveDriverName } from '@seleniumhq/get-driver'
22
import { ChildProcess, spawn } from 'child_process'
3+
import { app } from 'electron'
34
import * as fs from 'fs-extra'
45
import { BrowserInfo, Session } from 'main/types'
56
import * as path from 'path'
@@ -19,6 +20,8 @@ export interface DriverStartFailure {
1920
export const WebdriverDebugLog = vdebuglog('webdriver', COLOR_MAGENTA)
2021
export const WebdriverDebugLogErr = vdebuglog('webdriver-error', COLOR_YELLOW)
2122

23+
export const port = app.isPackaged ? 9516 : 9515
24+
2225
/**
2326
* This module is just an async function that does the following:
2427
* 1. Grab driver from the node_modules, as fetched by electron-driver
@@ -57,9 +60,9 @@ export type StartDriver = (
5760
session: Session
5861
) => (info: BrowserInfo) => Promise<DriverStartSuccess | DriverStartFailure>
5962
const startDriver: StartDriver = () => (info) =>
60-
new Promise((resolve, reject) => {
63+
new Promise((resolve) => {
6164
let initialized = false
62-
const args = ['--verbose']
65+
const args = ['--verbose', `--port=${port}`]
6366
const driverPath = getDriver(info)
6467
if (fs.existsSync(driverPath)) {
6568
const driver = spawn(driverPath.replace(/\s/g, '\ '), args, {
@@ -85,9 +88,12 @@ const startDriver: StartDriver = () => (info) =>
8588
})
8689
driver.on('close', (code: number) => {
8790
if (code) {
88-
WebdriverDebugLogErr(`driver has exited with code${code}`)
91+
WebdriverDebugLogErr(`driver has exited with code ${code}`)
8992
if (!initialized) {
90-
reject(code)
93+
resolve({
94+
success: false,
95+
error: 'Process has exited before starting with code ' + code,
96+
})
9197
}
9298
}
9399
})

packages/selenium-ide/src/main/session/controllers/System/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export default class SystemController extends BaseController {
1111
}
1212
async startup() {
1313
if (this.isDown) {
14-
// await this.session.windows.open('chromedriver')
15-
await this.session.driver.startProcess()
14+
const startupError = await this.session.driver.startProcess()
15+
if (startupError) {
16+
await this.crash(`Unable to startup due to chromedriver error: ${startupError}`);
17+
}
1618
await this.session.projects.select(firstTime)
1719
this.isDown = false
1820
firstTime = false

packages/selenium-ide/src/main/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const COLOR_CYAN = '\x1b[36m'
1111
export const COLOR_WHITE = '\x1b[37m'
1212

1313
export const vdebuglog = (namespace: string, color: string) => {
14-
const isBin = app.isPackaged
14+
const isBin = true || app.isPackaged
1515
const prefix = isBin ? `${namespace}: ` : color
1616
const log = isBin ? console.log : debuglog(namespace)
1717
const suffix = isBin ? '' : '\x1b[0m'

0 commit comments

Comments
 (0)