Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Detect port #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ Type: `Object`

Default: `{}`

### port
This service will automatically launch the standalone server on the port specified in your WebDriverIO configuration file.

For example:
```js
port: 4441,
seleniumArgs: {
javaArgs: [
"-Xmx1024m"
]
}
```
This is useful for specifying custom ports on the command line when running tests, allowing multiple instances of the standalone server to run concurrently.


----

For more information on WebdriverIO see the [homepage](http://webdriver.io).
21 changes: 17 additions & 4 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ class SeleniumStandaloneLauncher {
}

onPrepare (config) {
this.seleniumArgs = config.seleniumArgs || {}
this.seleniumInstallArgs = config.seleniumInstallArgs || {}
this.seleniumLogs = config.seleniumLogs
this.logToStdout = config.logToStdout
this._getConfig(config)

return this._installSeleniumDependencies(this.seleniumInstallArgs).then(() => new Promise((resolve, reject) => Selenium.start(this.seleniumArgs, (err, process) => {
if (err) {
Expand All @@ -38,6 +35,22 @@ class SeleniumStandaloneLauncher {
}
}

_getConfig (config) {
this.seleniumArgs = config.seleniumArgs || {}
this.seleniumInstallArgs = config.seleniumInstallArgs || {}
this.seleniumLogs = config.seleniumLogs
this.logToStdout = config.logToStdout

if (config.port) {
if (this.seleniumArgs.seleniumArgs === undefined) {
this.seleniumArgs.seleniumArgs = []
}
if (this.seleniumArgs.seleniumArgs.indexOf('-port') < 0) {
this.seleniumArgs.seleniumArgs.push('-port', config.port)
}
}
}

_installSeleniumDependencies (seleniumInstallArgs) {
return new Promise((resolve, reject) => Selenium.install(seleniumInstallArgs, (err) => {
if (err) {
Expand Down
35 changes: 35 additions & 0 deletions test/unit/launcher/launcher.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import launcher from '../../../lib/launcher'
import path from 'path'
import assert from 'assert'

describe('getFilePath', function () {
it('should add custom port to seleniumArgs', function() {
const config = {
port: 4441,
seleniumArgs: {},
seleniumLogs: './logs',
services: ['selenium-standalone']
}
const launch = new launcher()
launch._getConfig(config)

const portIndex = launch.seleniumArgs.seleniumArgs.indexOf('-port')
assert.ok(portIndex >= 0 && launch.seleniumArgs.seleniumArgs[portIndex + 1] === 4441)
})

it('should not override custom port already in seleniumArgs', function() {
const config = {
port: 4441,
seleniumArgs: {
seleniumArgs: ['-port', 4444]
},
seleniumLogs: './logs',
services: ['selenium-standalone']
}
const launch = new launcher()
launch._getConfig(config)

const portIndex = launch.seleniumArgs.seleniumArgs.indexOf('-port')
assert.ok(portIndex >= 0 && launch.seleniumArgs.seleniumArgs[portIndex + 1] === 4444)
})
})