jasmine / jasmine-browser-runner

Serve and run your Jasmine specs in a browser
50 stars 25 forks source link

Error running tests in Firefox on ubuntu-latest via GH Actions #56

Closed alexgibson closed 5 months ago

alexgibson commented 5 months ago

I'm hitting what I believe is this issue https://github.com/SeleniumHQ/selenium/issues/13169 when trying to run jasmine-browser-runner via GitHub Actions on Ubuntu >= 22.0.4. From my understanding, it is due to Firefox snap being the new default on Ubuntu, but it is installed in a different location.

Jasmine server is running here: http://localhost:9876
Jasmine tests are here:         /home/runner/work/dnt-helper/dnt-helper/tests/dist
Source files are here:          /home/runner/work/dnt-helper/dnt-helper/tests/dist
Running tests in the browser...
InvalidArgumentError: binary is not a Firefox executable
    at Object.throwDecodedError (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/error.js:521:15)
    at parseHttpResponse (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:514:13)
    at Executor.execute (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:446:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: ''
}
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^
InvalidArgumentError: binary is not a Firefox executable
    at Object.throwDecodedError (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/error.js:521:15)
    at parseHttpResponse (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:514:13)
    at Executor.execute (/home/runner/work/dnt-helper/dnt-helper/node_modules/selenium-webdriver/lib/http.js:446:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: ''
}

This is a basic GitHub action template that can reproduce the issue:

name: "CI"
on:
  pull_request:
    branches:
    - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: "Install framebuffer (xvfb), Firefox and Chromium"
        run: |
          sudo apt-get update
          sudo apt-get install chromium-browser firefox xvfb
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: "Install JS dependencies"
        run: npm ci
      - name: "Run JS tests"
        run: xvfb-run npm test

From the issue I linked to it does not look like this is something Selenium will fix, since it supports passing alternate paths to the driver/executable already. However given that, I'm not quite sure how I can tell jasmine-browser-runner to instruct Selenium to use a different browser/driver path?

sgravrock commented 5 months ago

I haven't had time to try this myself yet, but I wonder if setting the PATH would work, e.g by changing npm ci to PATH=/snap/bin:$PATH npm ci (assuming that things are getting installed in /snap/bin).

alexgibson commented 5 months ago

I haven't had time to try this myself yet, but I wonder if setting the PATH would work, e.g by changing npm ci to PATH=/snap/bin:$PATH npm ci (assuming that things are getting installed in /snap/bin).

I tried adding /snap/bin/firefox to PATH, but unfortunately it does not seem to make a difference. So I'm not 100% sure if Selenium is looking here when it gets initiated.

sgravrock commented 5 months ago

I was able to get it working with this change:

--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -5,10 +5,10 @@ jobs:
   test:
     runs-on: ubuntu-latest
     steps:
-      - name: "Install framebuffer (xvfb), Firefox and Chromium"
+      - name: "Install framebuffer (xvfb) and Chromium"
         run: |
           sudo apt-get update
-          sudo apt-get install chromium-browser firefox xvfb
+          sudo apt-get install chromium-browser xvfb
       - uses: actions/checkout@v4
       - uses: actions/setup-node@v4
         with:

It turns out that the image you're using already includes Firefox and Geckodriver.

alexgibson commented 5 months ago

Ah, wonderful - thank you!

sgravrock commented 5 months ago

I'm glad to hear it worked. My hope and expectation is that most people will be in a similar situation, since CI providers ought to have images with working webdriver setups. Making the browser and driver paths configurable is possible but a little ugly, so I'm hoping we won't have to go there.