Skip to content

Commit acfe949

Browse files
committed
Add ability to pass ChromeOptions to the ChromeDriver.
I'm running tests in a Docker container (https://hub.docker.com/r/gshakhn/sbt-firefox-chromium/). Chrome and Docker don't play well together unless you pass `--no-sandbox` to Chrome (elgalu/docker-selenium#9) This change lets me set pass in `ChromeOptions` with the custom argument to Chrome. This is a breaking change since `Chrome` is now a class instead of an object. Update readme to reflect that. Other than the above, this should be backwards compatible. The overloaded constructor of `ChromeDriver` just calls `options.toCapabilities`, which has the old `DesiredCapabilities.chrome` code.
1 parent 18b416b commit acfe949

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jsEnv := new org.scalajs.jsenv.selenium.SeleniumJSEnv(BROWSER)
1616
jsEnv in Test := new org.scalajs.jsenv.selenium.SeleniumJSEnv(BROWSER)
1717
```
1818
where the `BROWSER` can be either `org.scalajs.jsenv.selenium.Firefox` or
19-
`org.scalajs.jsenv.selenium.Chrome`.
19+
`new org.scalajs.jsenv.selenium.Chrome`.
2020

2121
When executing the program with `run` a new browser window will be created,
2222
the code will be executed in it and finally the browser will close itself.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package org.scalajs.jsenv.selenium
22

3-
import org.openqa.selenium.chrome.ChromeDriverService
3+
import org.openqa.selenium.chrome.{ChromeDriverService, ChromeOptions}
44
import org.openqa.selenium.remote._
55

6-
object Chrome extends SeleniumBrowser {
6+
class Chrome(chromeOptions: ChromeOptions = new ChromeOptions) extends SeleniumBrowser {
7+
78
def name: String = "Chrome"
89

910
def newDriver: BrowserDriver = new ChromeDriver
1011

1112
private class ChromeDriver extends BrowserDriver {
1213
protected def newDriver(): RemoteWebDriver = {
13-
val caps = DesiredCapabilities.chrome()
1414
val service = {
1515
/* Activate the silent ChromeDriverService silent mode,
1616
* see ChromeDriverService.createDefaultService
1717
*/
1818
new ChromeDriverService.Builder().withSilent(true).usingAnyFreePort.build
1919
}
20-
new org.openqa.selenium.chrome.ChromeDriver(service, caps)
20+
new org.openqa.selenium.chrome.ChromeDriver(service, chromeOptions)
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)