From ed23e7ddcecf4176c5e03a91069a27fbacd76078 Mon Sep 17 00:00:00 2001 From: Domantas Petrauskas Date: Mon, 1 Jul 2024 20:50:00 +0300 Subject: [PATCH 1/4] Allow switching between chrome and firefox in e2e tests --- .../basic-web-project/html.sbt | 23 +++++++++++++++---- .../multiple-entry-points/html.sbt | 21 +++++++++++++---- .../basic-project/html.sbt | 21 +++++++++++++---- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt index 4f8e6443..81bde0f5 100644 --- a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt +++ b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt @@ -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 @@ -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", @@ -34,9 +37,19 @@ InputKey[Unit]("html") := { "--disable-dev-shm-usage", "--headless" ) - value + sys.env.get("E2E_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._ diff --git a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt index 09ca9e4a..5c89c3dd 100644 --- a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt +++ b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt @@ -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 @@ -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", @@ -36,9 +37,19 @@ InputKey[Unit]("html") := { "--disable-dev-shm-usage", "--headless" ) - value + sys.env.get("E2E_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._ diff --git a/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt b/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt index b3bc71dc..8d492587 100644 --- a/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt +++ b/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt @@ -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 @@ -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", @@ -32,9 +33,19 @@ InputKey[Unit]("html") := { "--disable-dev-shm-usage", "--headless" ) - value + sys.env.get("E2E_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._ From c0d085bf035aaff2dbf61ac78654d55b7eb77ec9 Mon Sep 17 00:00:00 2001 From: Domantas Petrauskas Date: Mon, 1 Jul 2024 20:57:19 +0300 Subject: [PATCH 2/4] Rename variable to E2E_TEST_BROWSER --- .../sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt | 2 +- .../sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt | 2 +- .../src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt index 81bde0f5..b4c4ca54 100644 --- a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt +++ b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/basic-web-project/html.sbt @@ -37,7 +37,7 @@ InputKey[Unit]("html") := { "--disable-dev-shm-usage", "--headless" ) - sys.env.get("E2E_BROWSER").map(_.toLowerCase).getOrElse("chrome") match { + sys.env.get("E2E_TEST_BROWSER").map(_.toLowerCase).getOrElse("chrome") match { case "chrome" => val options = new ChromeOptions options.addArguments(arguments: _*) diff --git a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt index 5c89c3dd..3ed689d0 100644 --- a/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt +++ b/sbt-scalajs-esbuild-web/src/sbt-test/sbt-scalajs-esbuild-web/multiple-entry-points/html.sbt @@ -37,7 +37,7 @@ InputKey[Unit]("html") := { "--disable-dev-shm-usage", "--headless" ) - sys.env.get("E2E_BROWSER").map(_.toLowerCase).getOrElse("chrome") match { + sys.env.get("E2E_TEST_BROWSER").map(_.toLowerCase).getOrElse("chrome") match { case "chrome" => val options = new ChromeOptions options.addArguments(arguments: _*) diff --git a/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt b/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt index 8d492587..29c26515 100644 --- a/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt +++ b/sbt-web-scalajs-esbuild/src/sbt-test/sbt-web-scalajs-esbuild/basic-project/html.sbt @@ -33,7 +33,7 @@ InputKey[Unit]("html") := { "--disable-dev-shm-usage", "--headless" ) - sys.env.get("E2E_BROWSER").map(_.toLowerCase).getOrElse("chrome") match { + sys.env.get("E2E_TEST_BROWSER").map(_.toLowerCase).getOrElse("chrome") match { case "chrome" => val options = new ChromeOptions options.addArguments(arguments: _*) From 8a9d29a7561f17c7a5c3612f5639eff8d05bdede Mon Sep 17 00:00:00 2001 From: Domantas Petrauskas Date: Mon, 1 Jul 2024 22:01:42 +0300 Subject: [PATCH 3/4] Add e2e test browser environment variable to workflow step that runs tests --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6893dda1..9359a11b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,5 +40,7 @@ jobs: run: corepack prepare pnpm@8.8.0 --activate - name: Run tests uses: coactions/setup-xvfb@v1 + env: + E2E_TEST_BROWSER: ${{ vars.E2E_TEST_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' || '' }}" From 516ab34b2d37ab201d03934f931c2c30077a422f Mon Sep 17 00:00:00 2001 From: Domantas Petrauskas Date: Mon, 1 Jul 2024 22:06:20 +0300 Subject: [PATCH 4/4] Add browser variable to workflow matrix strategy, set macos runner to use chrome --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9359a11b..61d3112c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} @@ -41,6 +43,6 @@ jobs: - name: Run tests uses: coactions/setup-xvfb@v1 env: - E2E_TEST_BROWSER: ${{ vars.E2E_TEST_BROWSER }} + 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' || '' }}"