Skip to content

Commit

Permalink
Allow switching between Chrome and Firefox in e2e tests (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrdom authored Jul 1, 2024
1 parent 7708695 commit e5b906c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ jobs:
matrix:
jdk: [8, 11, 17, 21]
os: [ubuntu-latest, windows-latest]
browser: ["${{ vars.E2E_TEST_BROWSER }}"]
experimental: [false]
include:
- jdk: 11
os: macos-14
browser: chrome
experimental: true
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
Expand All @@ -40,5 +42,7 @@ jobs:
run: corepack prepare [email protected] --activate
- name: Run tests
uses: coactions/setup-xvfb@v1
env:
E2E_TEST_BROWSER: ${{ matrix.browser }}
with:
run: sbt scalafmtSbtCheck scalafmtCheckAll test "${{ steps.coursier-cache.outputs.cache-hit-coursier && 'scripted' || 'scriptedSequentialPerModule' }}${{ matrix.jdk == 8 && ' sbt-scalajs-esbuild/* sbt-scalajs-esbuild-electron/basic-project sbt-scalajs-esbuild-electron/e2e-test-playwright-node sbt-scalajs-esbuild-electron/electron-builder' || '' }}"
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
InputKey[Unit]("html") := {
val log = streams.value.log

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.scalatest.matchers.should.Matchers
Expand All @@ -22,10 +26,9 @@ InputKey[Unit]("html") := {
with Eventually
with IntegrationPatience
with Inside {
val webDriverOptions: FirefoxOptions = {
val value = new FirefoxOptions
implicit val webDriver: WebDriver = {
// arguments recommended by https://itnext.io/how-to-run-a-headless-chrome-browser-in-selenium-webdriver-c5521bc12bf0
value.addArguments(
val arguments = Seq(
"--disable-gpu",
"--window-size=1920,1200",
"--ignore-certificate-errors",
Expand All @@ -34,9 +37,19 @@ InputKey[Unit]("html") := {
"--disable-dev-shm-usage",
"--headless"
)
value
sys.env.get("E2E_TEST_BROWSER").map(_.toLowerCase).getOrElse("chrome") match {
case "chrome" =>
val options = new ChromeOptions
options.addArguments(arguments: _*)
new ChromeDriver(options)
case "firefox" =>
val options = new FirefoxOptions
options.addArguments(arguments: _*)
new FirefoxDriver(options)
case unhandled =>
sys.error(s"Unhandled browser [$unhandled]")
}
}
implicit val webDriver: WebDriver = new FirefoxDriver(webDriverOptions)
}
import webBrowser._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import scala.util.control.NonFatal

InputKey[Unit]("html") := {
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.scalatest.matchers.should.Matchers
Expand All @@ -24,10 +26,9 @@ InputKey[Unit]("html") := {
with Eventually
with IntegrationPatience
with Inside {
val webDriverOptions: FirefoxOptions = {
val value = new FirefoxOptions
implicit val webDriver: WebDriver = {
// arguments recommended by https://itnext.io/how-to-run-a-headless-chrome-browser-in-selenium-webdriver-c5521bc12bf0
value.addArguments(
val arguments = Seq(
"--disable-gpu",
"--window-size=1920,1200",
"--ignore-certificate-errors",
Expand All @@ -36,9 +37,19 @@ InputKey[Unit]("html") := {
"--disable-dev-shm-usage",
"--headless"
)
value
sys.env.get("E2E_TEST_BROWSER").map(_.toLowerCase).getOrElse("chrome") match {
case "chrome" =>
val options = new ChromeOptions
options.addArguments(arguments: _*)
new ChromeDriver(options)
case "firefox" =>
val options = new FirefoxOptions
options.addArguments(arguments: _*)
new FirefoxDriver(options)
case unhandled =>
sys.error(s"Unhandled browser [$unhandled]")
}
}
implicit val webDriver: WebDriver = new FirefoxDriver(webDriverOptions)
}
import webBrowser._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
InputKey[Unit]("html") := {
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.scalatest.matchers.should.Matchers
Expand All @@ -20,10 +22,9 @@ InputKey[Unit]("html") := {
with Matchers
with Eventually
with IntegrationPatience {
val webDriverOptions: FirefoxOptions = {
val value = new FirefoxOptions
implicit val webDriver: WebDriver = {
// arguments recommended by https://itnext.io/how-to-run-a-headless-chrome-browser-in-selenium-webdriver-c5521bc12bf0
value.addArguments(
val arguments = Seq(
"--disable-gpu",
"--window-size=1920,1200",
"--ignore-certificate-errors",
Expand All @@ -32,9 +33,19 @@ InputKey[Unit]("html") := {
"--disable-dev-shm-usage",
"--headless"
)
value
sys.env.get("E2E_TEST_BROWSER").map(_.toLowerCase).getOrElse("chrome") match {
case "chrome" =>
val options = new ChromeOptions
options.addArguments(arguments: _*)
new ChromeDriver(options)
case "firefox" =>
val options = new FirefoxOptions
options.addArguments(arguments: _*)
new FirefoxDriver(options)
case unhandled =>
sys.error(s"Unhandled browser [$unhandled]")
}
}
implicit val webDriver: WebDriver = new FirefoxDriver(webDriverOptions)
}
import webBrowser._

Expand Down

0 comments on commit e5b906c

Please sign in to comment.