Skip to content

Commit 632849c

Browse files
gravityvidiemol
andauthored
[JS] kill chromium service on quit (#10796)
* [JS] kill chromium service on quit * create new default service for every driver instance in chrome * modify getDefaultService to return new service in edge and chrome driver Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent ae46fd8 commit 632849c

File tree

3 files changed

+19
-66
lines changed

3 files changed

+19
-66
lines changed

javascript/node/selenium-webdriver/chrome.js

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ const CHROMEDRIVER_EXE =
140140
process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver'
141141

142142
/** @type {remote.DriverService} */
143-
let defaultService = null
144143

145144
/**
146145
* Creates {@link selenium-webdriver/remote.DriverService} instances that manage
@@ -240,6 +239,14 @@ class Driver extends chromium.Driver {
240239
super.createSession(caps, opt_serviceExecutor)
241240
)
242241
}
242+
243+
/**
244+
* returns new instance chrome driver service
245+
* @returns {remote.DriverService}
246+
*/
247+
static getDefaultService() {
248+
return new ServiceBuilder().build()
249+
}
243250
}
244251

245252
/**
@@ -252,46 +259,14 @@ function locateSynchronously() {
252259
return io.findInPath(CHROMEDRIVER_EXE, true)
253260
}
254261

255-
/**
256-
* Sets the default service to use for new ChromeDriver instances.
257-
* @param {!remote.DriverService} service The service to use.
258-
* @throws {Error} If the default service is currently running.
259-
*/
260-
function setDefaultService(service) {
261-
if (defaultService && defaultService.isRunning()) {
262-
throw Error(
263-
`The previously configured ChromeDriver service is still running. ` +
264-
`You must shut it down before you may adjust its configuration.`
265-
)
266-
}
267-
defaultService = service
268-
}
269-
270-
/**
271-
* Returns the default ChromeDriver service. If such a service has not been
272-
* configured, one will be constructed using the default configuration for
273-
* a ChromeDriver executable found on the system PATH.
274-
* @return {!remote.DriverService} The default ChromeDriver service.
275-
*/
276-
function getDefaultService() {
277-
if (!defaultService) {
278-
defaultService = new ServiceBuilder().build()
279-
}
280-
return defaultService
281-
}
282-
283262
Options.prototype.CAPABILITY_KEY = 'goog:chromeOptions'
284263
Options.prototype.BROWSER_NAME_VALUE = Browser.CHROME
285-
Driver.getDefaultService = getDefaultService
286264
Driver.prototype.VENDOR_COMMAND_PREFIX = 'goog'
287265

288266
// PUBLIC API
289-
290267
module.exports = {
291268
Driver: Driver,
292269
Options,
293270
ServiceBuilder,
294-
getDefaultService,
295-
setDefaultService,
296271
locateSynchronously,
297272
}

javascript/node/selenium-webdriver/chromium.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,13 @@ class Driver extends webdriver.WebDriver {
661661
*/
662662
static createSession(caps, opt_serviceExecutor) {
663663
let executor
664+
let onQuit
664665
if (opt_serviceExecutor instanceof http.Executor) {
665666
executor = opt_serviceExecutor
666667
configureExecutor(executor, this.VENDOR_COMMAND_PREFIX)
667668
} else {
668669
let service = opt_serviceExecutor || this.getDefaultService()
670+
onQuit = () => service.kill()
669671
executor = createExecutor(service.start(), this.VENDOR_COMMAND_PREFIX)
670672
}
671673

@@ -679,7 +681,7 @@ class Driver extends webdriver.WebDriver {
679681
}
680682
}
681683

682-
return /** @type {!Driver} */ (super.createSession(executor, caps))
684+
return /** @type {!Driver} */ (super.createSession(executor, caps, onQuit))
683685
}
684686

685687
/**

javascript/node/selenium-webdriver/edge.js

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ const EDGEDRIVER_CHROMIUM_EXE =
9090
process.platform === 'win32' ? 'msedgedriver.exe' : 'msedgedriver'
9191

9292
/** @type {remote.DriverService} */
93-
let defaultService = null
9493

9594
/**
9695
* Creates {@link selenium-webdriver/remote.DriverService} instances that manage
@@ -157,6 +156,14 @@ class Driver extends chromium.Driver {
157156
)
158157
}
159158

159+
/**
160+
* returns new instance of edge driver service
161+
* @returns {remote.DriverService}
162+
*/
163+
static getDefaultService() {
164+
return new ServiceBuilder().build()
165+
}
166+
160167
/**
161168
* This function is a no-op as file detectors are not supported by this
162169
* implementation.
@@ -165,34 +172,6 @@ class Driver extends chromium.Driver {
165172
setFileDetector() {}
166173
}
167174

168-
/**
169-
* Sets the default service to use for new Edge instances.
170-
* @param {!remote.DriverService} service The service to use.
171-
* @throws {Error} If the default service is currently running.
172-
*/
173-
function setDefaultService(service) {
174-
if (defaultService && defaultService.isRunning()) {
175-
throw Error(
176-
'The previously configured EdgeDriver service is still running. ' +
177-
'You must shut it down before you may adjust its configuration.'
178-
)
179-
}
180-
defaultService = service
181-
}
182-
183-
/**
184-
* Returns the default Microsoft Edge driver service. If such a service has
185-
* not been configured, one will be constructed using the default configuration
186-
* for a MicrosoftWebDriver executable found on the system PATH.
187-
* @return {!remote.DriverService} The default Microsoft Edge driver service.
188-
*/
189-
function getDefaultService() {
190-
if (!defaultService) {
191-
defaultService = new ServiceBuilder().build()
192-
}
193-
return defaultService
194-
}
195-
196175
/**
197176
* _Synchronously_ attempts to locate the chromedriver executable on the current
198177
* system.
@@ -206,15 +185,12 @@ function locateSynchronously() {
206185
Options.prototype.BROWSER_NAME_VALUE = Browser.EDGE
207186
Options.prototype.CAPABILITY_KEY = 'ms:edgeOptions'
208187
Driver.prototype.VENDOR_CAPABILITY_PREFIX = 'ms'
209-
Driver.getDefaultService = getDefaultService
210188

211189
// PUBLIC API
212190

213191
module.exports = {
214192
Driver,
215193
Options,
216194
ServiceBuilder,
217-
getDefaultService,
218-
setDefaultService,
219195
locateSynchronously,
220196
}

0 commit comments

Comments
 (0)