Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow switching between Chrome and Firefox in e2e tests #224

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading