Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 23165a4

Browse files
committedOct 12, 2024
un-firefoxify
1 parent a214cab commit 23165a4

File tree

7 files changed

+28
-37
lines changed

7 files changed

+28
-37
lines changed
 

‎build.sbt

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import org.openqa.selenium.firefox.FirefoxOptions
2-
import org.openqa.selenium.firefox.FirefoxDriver
31
import sbt.Keys._
42

53
import org.scalajs.sbtplugin.ScalaJSCrossVersion
64

75
import org.openqa.selenium.Capabilities
86

97
import org.scalajs.jsenv.selenium.SeleniumJSEnv
10-
import org.scalajs.jsenv.selenium.TestCapabilities
8+
import org.scalajs.jsenv.selenium.TestDrivers
119

1210
// we're breaking bincompat with the bump to selenium 4
1311
val previousVersion: Option[String] = None
@@ -63,12 +61,8 @@ val previousArtifactSetting = Def.settings(
6361
}
6462
)
6563

66-
val jsEnvCapabilities = settingKey[org.openqa.selenium.Capabilities](
67-
"Capabilities of the SeleniumJSEnv")
68-
6964
val testSettings: Seq[Setting[_]] = commonSettings ++ Seq(
70-
jsEnvCapabilities := TestCapabilities.fromEnv,
71-
jsEnv := new SeleniumJSEnv(jsEnvCapabilities.value, SeleniumJSEnv.Config().withDriverFactory(caps => new FirefoxDriver(new FirefoxOptions(caps)))),
65+
jsEnv := new SeleniumJSEnv(SeleniumJSEnv.Config().withDriverFactory(TestDrivers.fromEnv)),
7266
scalaJSUseMainModuleInitializer := true
7367
)
7468

@@ -140,10 +134,9 @@ lazy val seleniumJSHttpEnvTest: Project = project.
140134
settings(
141135
jsEnv := {
142136
new SeleniumJSEnv(
143-
jsEnvCapabilities.value,
144137
SeleniumJSEnv.Config()
145138
.withMaterializeInServer("tmp", "http://localhost:8080/tmp/")
146-
.withDriverFactory((caps) => new FirefoxDriver(new FirefoxOptions(caps)))
139+
.withDriverFactory(TestDrivers.fromEnv)
147140
)
148141
},
149142
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }

‎project/build.sbt

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")
1111
libraryDependencies ~=
1212
("org.seleniumhq.selenium" % "selenium-java" % "4.25.0" +: _)
1313

14-
unmanagedSourceDirectories in Compile ++= {
14+
Compile / unmanagedSourceDirectories ++= {
1515
val root = baseDirectory.value.getParentFile
1616
Seq(root / "seleniumJSEnv/src/main/scala")
1717
}
1818

19-
sources in Compile += {
19+
Compile / sources += {
2020
val root = baseDirectory.value.getParentFile
21-
root / "seleniumJSEnv/src/test/scala/org/scalajs/jsenv/selenium/TestCapabilities.scala"
21+
root / "seleniumJSEnv/src/test/scala/org/scalajs/jsenv/selenium/TestDrivers.scala"
2222
}

‎seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/SeleniumJSEnv.scala

+4-13
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,9 @@ import org.openqa.selenium.WebDriver
1111
import org.openqa.selenium.JavascriptExecutor
1212
import org.openqa.selenium.Platform
1313

14-
final class SeleniumJSEnv(capabilities: Capabilities, config: SeleniumJSEnv.Config) extends JSEnv {
14+
final class SeleniumJSEnv(config: SeleniumJSEnv.Config) extends JSEnv {
1515

16-
def this(capabilities: Capabilities) =
17-
this(capabilities, SeleniumJSEnv.Config())
18-
19-
private val augmentedCapabilities = {
20-
val x = new DesiredCapabilities(capabilities)
21-
// x.setJavascriptEnabled(true)
22-
x
23-
}
24-
25-
val name: String = s"SeleniumJSEnv ($capabilities)"
16+
val name: String = s"SeleniumJSEnv ($config)"
2617

2718
def start(input: Seq[Input], runConfig: RunConfig): JSRun =
2819
SeleniumRun.start(newDriver _, input, config, runConfig)
@@ -32,7 +23,7 @@ final class SeleniumJSEnv(capabilities: Capabilities, config: SeleniumJSEnv.Conf
3223

3324
private def newDriver() = {
3425
val driver: WebDriver =
35-
config.driverFactory(augmentedCapabilities)
26+
config.driverFactory()
3627

3728
/* The first `asInstanceOf`s are a fail-fast for the second one, which
3829
* scalac partially erases, so that we're sure right now that the last
@@ -60,7 +51,7 @@ object SeleniumJSEnv {
6051
private def this() = this(
6152
keepAlive = false,
6253
materialization = Config.Materialization.Temp,
63-
driverFactory = caps => sys.error("No driver factory configured")
54+
driverFactory = () => sys.error("No driver factory configured")
6455
)
6556

6657
/** Materializes purely virtual files into a temp directory.

‎seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/package.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import org.openqa.selenium.WebDriver
44
import org.openqa.selenium.Capabilities
55

66
package object selenium {
7-
type DriverFactory = Capabilities => WebDriver
7+
type DriverFactory = () => WebDriver
88
}

‎seleniumJSEnv/src/test/scala/org/scalajs/jsenv/selenium/KeepAliveTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class KeepAliveTest {
5555
private final class MockInjector(driver: WebDriver) extends DriverFactory {
5656
var used = false
5757

58-
def apply(caps: Capabilities): WebDriver = {
58+
def apply(): WebDriver = {
5959
require(!used)
6060
used = true
6161
driver
@@ -68,7 +68,7 @@ class KeepAliveTest {
6868
val config = SeleniumJSEnv.Config()
6969
.withDriverFactory(factory)
7070
.withKeepAlive(keepAlive)
71-
val env = new SeleniumJSEnv(new DesiredCapabilities, config)
71+
val env = new SeleniumJSEnv(config)
7272

7373
(driver, factory, env)
7474
}

‎seleniumJSEnv/src/test/scala/org/scalajs/jsenv/selenium/SeleniumJSSuite.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ import org.openqa.selenium.firefox.FirefoxOptions
1414

1515
@RunWith(classOf[JSEnvSuiteRunner])
1616
class SeleniumJSSuite extends JSEnvSuite(
17-
JSEnvSuiteConfig(new SeleniumJSEnv(TestCapabilities.fromEnv, SeleniumJSEnv.Config().withDriverFactory(caps => new FirefoxDriver(new FirefoxOptions(caps)))))
17+
JSEnvSuiteConfig(new SeleniumJSEnv(SeleniumJSEnv.Config().withDriverFactory(TestDrivers.fromEnv)))
1818
)

‎seleniumJSEnv/src/test/scala/org/scalajs/jsenv/selenium/TestCapabilities.scala ‎seleniumJSEnv/src/test/scala/org/scalajs/jsenv/selenium/TestDrivers.scala

+14-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@ import org.openqa.selenium.firefox.{FirefoxOptions, FirefoxDriverLogLevel}
55
import org.openqa.selenium.chrome.ChromeOptions
66

77
import java.util.logging.{Logger, Level}
8+
import org.openqa.selenium.WebDriver
9+
import org.openqa.selenium.firefox.FirefoxDriver
10+
import org.openqa.selenium.chrome.ChromeDriver
811

9-
object TestCapabilities {
12+
object TestDrivers {
1013
// Lower the logging level for Selenium to avoid spam.
1114
Logger.getLogger("org.openqa.selenium").setLevel(Level.WARNING)
1215

13-
def fromEnv: Capabilities = nameFromEnv match {
16+
val fromEnv: DriverFactory = () => nameFromEnv match {
1417
case "firefox" =>
15-
new FirefoxOptions()
16-
.addArguments("--headless")
17-
.setLogLevel(FirefoxDriverLogLevel.ERROR)
18+
new FirefoxDriver(
19+
new FirefoxOptions()
20+
.addArguments("--headless")
21+
.setLogLevel(FirefoxDriverLogLevel.ERROR)
22+
)
1823

1924
case "chrome" =>
20-
new ChromeOptions()
21-
.addArguments("--headless")
25+
new ChromeDriver(
26+
new ChromeOptions()
27+
.addArguments("--headless")
28+
)
2229

2330
case name =>
2431
throw new IllegalArgumentException(s"Unknown browser $name")

0 commit comments

Comments
 (0)
Please sign in to comment.