From 17c6a8bd08db74cbd7b1ac78bfe77980f69c8fcd Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 11:09:12 -0400 Subject: [PATCH 01/45] Add Github Action for running Selenium tests on Chrome --- .github/workflows/test.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..39e7e1724c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +name: Selenium Testing + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + env: + INFO: "Chrome" + BROWSER: "google-chrome-stable" + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install Browser Dependencies + run: | + sudo apt update + # Install Xvfb for GUI-based testing + sudo apt install -y xvfb + # Install Google Chrome + sudo apt install -y google-chrome-stable + + - name: Run Setup Script + run: ./scripts/setup_travis.sh + + - name: Run Tests + run: . ./scripts/run_travis.sh \ No newline at end of file From c9dc565e10ae18d858e81d6b0c9a40cb955ca5c2 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 11:48:17 -0400 Subject: [PATCH 02/45] Run on pushes to this feature branch for testing purposes --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 39e7e1724c..d8574e2baa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - travis-github-action pull_request: workflow_dispatch: From 176136e6c4037c2a065aabec1d20d1b2586bdd3e Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 13:23:13 -0400 Subject: [PATCH 03/45] Remove dot command to source run_travis script --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8574e2baa..bc4af4ff47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,4 +35,4 @@ jobs: run: ./scripts/setup_travis.sh - name: Run Tests - run: . ./scripts/run_travis.sh \ No newline at end of file + run: ./scripts/run_travis.sh \ No newline at end of file From 983860226cd5efa47ecaf3643f318b420108b4b9 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 13:28:51 -0400 Subject: [PATCH 04/45] Debug: check for chromedriver in run_travis.sh --- scripts/run_travis.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/run_travis.sh b/scripts/run_travis.sh index bd7d5aaa28..b140b46521 100755 --- a/scripts/run_travis.sh +++ b/scripts/run_travis.sh @@ -22,6 +22,12 @@ else case $BROWSER in *chrome*) echo "Running tests on Chrome" + # check that chromedriver is now present + type chromedriver >/dev/null 2>&1 || { + echo "Failed to install ChromeDriver!" + exit 1 + } + chromedriver --version run_selenium ;; *firefox*) From 78fc553c3075924e0e0fe1b216389ad2c487d7d4 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 13:43:13 -0400 Subject: [PATCH 05/45] Try adding unique --user-data-dir option to Chrome webdriver --- tests/selenium/pbtest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 85b917a5e2..10d815d81a 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -164,6 +164,7 @@ def on_travis(self): def chrome_manager(self): opts = ChromeOptions() opts.add_argument("--load-extension=" + self.extension_path) + opts.add_argument(f"--user-data-dir={mkdtemp()}") opts.binary_location = self.browser_path # TODO not yet in Firefox (w/o hacks anyway): From 21a47ad00ff690b7934bebe8ca43f0cc97dc0cc6 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 13:48:54 -0400 Subject: [PATCH 06/45] Switch to tempfile.TemporaryDirectory() --- tests/selenium/pbtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 10d815d81a..5cf455e740 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -164,7 +164,7 @@ def on_travis(self): def chrome_manager(self): opts = ChromeOptions() opts.add_argument("--load-extension=" + self.extension_path) - opts.add_argument(f"--user-data-dir={mkdtemp()}") + opts.add_argument(f"--user-data-dir={tempfile.TemporaryDirectory()}") opts.binary_location = self.browser_path # TODO not yet in Firefox (w/o hacks anyway): From 3cbd0d88a885f809a2bf4cfe92f63fcd06929407 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 14:25:38 -0400 Subject: [PATCH 07/45] Add matrix for multiple browser jobs and test Firefox and Edge Beta instead of Chrome --- .github/workflows/test.yml | 52 +++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc4af4ff47..19495ed92c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,9 +11,23 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + job: [lint, firefox, edge-beta] + include: + - job: lint + INFO: "lint" + # No BROWSER variable needed for linting + # Don't test Chrome in non-mv3 codebase + - job: firefox + INFO: "Firefox" + BROWSER: "firefox" + - job: edge-beta + INFO: "Edge Beta" + BROWSER: "microsoft-edge-beta" env: - INFO: "Chrome" - BROWSER: "google-chrome-stable" + INFO: ${{ matrix.INFO }} + BROWSER: ${{ matrix.BROWSER }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -23,13 +37,37 @@ jobs: with: python-version: '3.11' - - name: Install Browser Dependencies + - name: Set up Node.js for linting + if: matrix.job == 'lint' + uses: actions/setup-node@v4 + with: + node-version: '18.18.0' # Minimum version for eslint: https://eslint.org/docs/latest/use/getting-started + + - name: Install Browser Dependencies # Firefox documentation run: | sudo apt update - # Install Xvfb for GUI-based testing - sudo apt install -y xvfb - # Install Google Chrome - sudo apt install -y google-chrome-stable + # Install Xvfb (replacing xvfb in Travis services) + sudo apt-get install -y xvfb + # Install browsers as needed: + if [[ "${BROWSER}" == "firefox" ]]; then + sudo install -d -m 0755 /etc/apt/keyrings + wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null + gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}' + echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null + echo ' + Package: * + Pin: origin packages.mozilla.org + Pin-Priority: 1000 + ' | sudo tee /etc/apt/preferences.d/mozilla + sudo apt-get update && sudo apt-get install firefox + elif [[ "${BROWSER}" == "microsoft-edge-beta" ]]; then + curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg + sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ + sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-beta.list' + sudo rm microsoft.gpg + sudo apt update + sudo apt install microsoft-edge-beta + fi - name: Run Setup Script run: ./scripts/setup_travis.sh From ea7917db49ea98c0f8d25d7c7af5f7a0143d4408 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 15:08:56 -0400 Subject: [PATCH 08/45] Add debugging print statements to Firefox install, and add explicit user-data-dir for Edge driver --- .github/workflows/test.yml | 6 ++++++ tests/selenium/pbtest.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19495ed92c..d5b1428141 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,6 +60,12 @@ jobs: Pin-Priority: 1000 ' | sudo tee /etc/apt/preferences.d/mozilla sudo apt-get update && sudo apt-get install firefox + # Print the Firefox binary path + echo "Firefox binary path:" + which firefox + ls -l "$(which firefox)" + # Print the version to confirm it's installed correctly + firefox --version elif [[ "${BROWSER}" == "microsoft-edge-beta" ]]; then curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 5cf455e740..a4388685e2 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -164,7 +164,6 @@ def on_travis(self): def chrome_manager(self): opts = ChromeOptions() opts.add_argument("--load-extension=" + self.extension_path) - opts.add_argument(f"--user-data-dir={tempfile.TemporaryDirectory()}") opts.binary_location = self.browser_path # TODO not yet in Firefox (w/o hacks anyway): @@ -190,6 +189,7 @@ def chrome_manager(self): def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) + opts.add_argument(f"--user-data-dir={tempfile.TemporaryDirectory()}") opts.binary_location = self.browser_path for i in range(5): From aae8332e724f81b36713b2bf51a1332eab765076 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 15:17:41 -0400 Subject: [PATCH 09/45] Check for and remove snap package --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5b1428141..4944a0de7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,11 @@ jobs: - name: Install Browser Dependencies # Firefox documentation run: | + snap list firefox # Check if Firefox is installed as a Snap package + which firefox # Find the current Firefox binary location + ls -l "$(which firefox)" # See if it's a symlink to Snap sudo apt update + sudo snap remove firefox # Install Xvfb (replacing xvfb in Travis services) sudo apt-get install -y xvfb # Install browsers as needed: From b9e968b45a894a2b5addf5f0e421ea433130c159 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 1 Apr 2025 15:38:26 -0400 Subject: [PATCH 10/45] Switch to ubuntu 22.04 to match Travis jammy distro --- .github/workflows/test.yml | 6 +----- tests/selenium/pbtest.py | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4944a0de7a..d0afb39407 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ on: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: job: [lint, firefox, edge-beta] @@ -45,11 +45,7 @@ jobs: - name: Install Browser Dependencies # Firefox documentation run: | - snap list firefox # Check if Firefox is installed as a Snap package - which firefox # Find the current Firefox binary location - ls -l "$(which firefox)" # See if it's a symlink to Snap sudo apt update - sudo snap remove firefox # Install Xvfb (replacing xvfb in Travis services) sudo apt-get install -y xvfb # Install browsers as needed: diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index a4388685e2..85b917a5e2 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -189,7 +189,6 @@ def chrome_manager(self): def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) - opts.add_argument(f"--user-data-dir={tempfile.TemporaryDirectory()}") opts.binary_location = self.browser_path for i in range(5): From 467c45a352512eebd608dd01b1e13212c50f2247 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Wed, 2 Apr 2025 18:44:29 -0400 Subject: [PATCH 11/45] Try existing github actions for firefox and geckodriver setup --- .github/workflows/test.yml | 75 ++++++++++++++++++++++---------------- scripts/setup_travis.sh | 2 +- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0afb39407..139d71a6dd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,8 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - job: [lint, firefox, edge-beta] + job: [firefox] + # job: [lint, firefox, edge-beta] include: - job: lint INFO: "lint" @@ -43,37 +44,47 @@ jobs: with: node-version: '18.18.0' # Minimum version for eslint: https://eslint.org/docs/latest/use/getting-started - - name: Install Browser Dependencies # Firefox documentation - run: | - sudo apt update - # Install Xvfb (replacing xvfb in Travis services) - sudo apt-get install -y xvfb - # Install browsers as needed: - if [[ "${BROWSER}" == "firefox" ]]; then - sudo install -d -m 0755 /etc/apt/keyrings - wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null - gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}' - echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null - echo ' - Package: * - Pin: origin packages.mozilla.org - Pin-Priority: 1000 - ' | sudo tee /etc/apt/preferences.d/mozilla - sudo apt-get update && sudo apt-get install firefox - # Print the Firefox binary path - echo "Firefox binary path:" - which firefox - ls -l "$(which firefox)" - # Print the version to confirm it's installed correctly - firefox --version - elif [[ "${BROWSER}" == "microsoft-edge-beta" ]]; then - curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg - sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ - sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-beta.list' - sudo rm microsoft.gpg - sudo apt update - sudo apt install microsoft-edge-beta - fi + - name: Set up Firefox + if: matrix.job == 'firefox' + uses: browser-actions/setup-firefox@v1 + with: + firefox-version: 'latest' + + - name: Install Gecko Driver + if: matrix.job == 'firefox' + uses: browser-actions/setup-geckodriver@latest + run: geckodriver --version + # - name: Install Browser Dependencies # Firefox documentation + # run: | + # sudo apt update + # # Install Xvfb (replacing xvfb in Travis services) + # sudo apt-get install -y xvfb + # # Install browsers as needed: + # if [[ "${BROWSER}" == "firefox" ]]; then + # sudo install -d -m 0755 /etc/apt/keyrings + # wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null + # gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}' + # echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null + # echo ' + # Package: * + # Pin: origin packages.mozilla.org + # Pin-Priority: 1000 + # ' | sudo tee /etc/apt/preferences.d/mozilla + # sudo apt-get update && sudo apt-get install firefox + # # Print the Firefox binary path + # echo "Firefox binary path:" + # which firefox + # ls -l "$(which firefox)" + # # Print the version to confirm it's installed correctly + # firefox --version + # elif [[ "${BROWSER}" == "microsoft-edge-beta" ]]; then + # curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg + # sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ + # sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-beta.list' + # sudo rm microsoft.gpg + # sudo apt update + # sudo apt install microsoft-edge-beta + # fi - name: Run Setup Script run: ./scripts/setup_travis.sh diff --git a/scripts/setup_travis.sh b/scripts/setup_travis.sh index f45ab24628..52d5fe9c42 100755 --- a/scripts/setup_travis.sh +++ b/scripts/setup_travis.sh @@ -84,7 +84,7 @@ case $INFO in ;; *Firefox*) check_browser - install_geckodriver + # install_geckodriver install_python_deps ;; *Edge*) From 8262f29ebfc11a39ffbaf8e002616475652c6d6c Mon Sep 17 00:00:00 2001 From: lenacohen Date: Wed, 2 Apr 2025 18:50:48 -0400 Subject: [PATCH 12/45] Fix combined step error --- .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 139d71a6dd..351714b303 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,9 @@ jobs: - name: Install Gecko Driver if: matrix.job == 'firefox' uses: browser-actions/setup-geckodriver@latest - run: geckodriver --version + - run: | + geckodriver --version + firefox --version # - name: Install Browser Dependencies # Firefox documentation # run: | # sudo apt update From 34607fdcf8c0c9d10707f72fcf7174062ce491ec Mon Sep 17 00:00:00 2001 From: lenacohen Date: Wed, 2 Apr 2025 18:54:56 -0400 Subject: [PATCH 13/45] Add lint job --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 351714b303..88ae9c1ec5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - job: [firefox] + job: [lint, firefox] # job: [lint, firefox, edge-beta] include: - job: lint From 56571bd00891d1725dcc94689eb6037f0f80427c Mon Sep 17 00:00:00 2001 From: lenacohen Date: Wed, 2 Apr 2025 18:57:04 -0400 Subject: [PATCH 14/45] Temporarily remove Edge tests --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88ae9c1ec5..afbdd61f67 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,9 +23,9 @@ jobs: - job: firefox INFO: "Firefox" BROWSER: "firefox" - - job: edge-beta - INFO: "Edge Beta" - BROWSER: "microsoft-edge-beta" + # - job: edge-beta + # INFO: "Edge Beta" + # BROWSER: "microsoft-edge-beta" env: INFO: ${{ matrix.INFO }} BROWSER: ${{ matrix.BROWSER }} From 771cb7cb9ca878e5b48bac0bb442b98bd1312262 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Wed, 2 Apr 2025 19:05:35 -0400 Subject: [PATCH 15/45] Try headless option and enable trace logging for geckodriver --- .github/workflows/test.yml | 3 ++- tests/selenium/pbtest.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index afbdd61f67..c1dc97e15e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,8 @@ jobs: - name: Install Gecko Driver if: matrix.job == 'firefox' uses: browser-actions/setup-geckodriver@latest - - run: | + - name: Check that Gecko Driver and Firefox are installed + run: | geckodriver --version firefox --version # - name: Install Browser Dependencies # Firefox documentation diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 85b917a5e2..a5a59140e8 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -231,12 +231,15 @@ def firefox_manager(self): # disable JSON viewer as it breaks parsing JSON pages opts.set_preference("devtools.jsonview.enabled", False) + opts.add_argument("--headless") + # to produce a trace-level geckodriver.log, # remove the log_output argument to FirefoxService() # and uncomment the line below - #opts.log.level = "trace" + opts.log.level = "trace" + service = FirefoxService() - service = FirefoxService(log_output=os.path.devnull) + # service = FirefoxService(log_output=os.path.devnull) driver = webdriver.Firefox(options=opts, service=service) except WebDriverException as e: From c6a6c1b1d8aa43e9595f1c75bda3286af1765ee2 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 00:33:53 -0400 Subject: [PATCH 16/45] Add jobs for other versions of Firefox --- .github/workflows/test.yml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1dc97e15e..a1a0b50f82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - job: [lint, firefox] + job: [lint, firefox, firefox-beta, firefox-nightly, firefox-esr] # job: [lint, firefox, edge-beta] include: - job: lint @@ -23,6 +23,19 @@ jobs: - job: firefox INFO: "Firefox" BROWSER: "firefox" + FIREFOX_VERSION: "latest" + - job: firefox-beta + INFO: "Firefox Beta" + BROWSER: "firefox" + FIREFOX_VERSION: "latest-beta" + - job: firefox-nightly + INFO: "Firefox Nightly" + BROWSER: "firefox" + FIREFOX_VERSION: "latest-nightly" + - job: firefox-esr + INFO: "Firefox ESR" + BROWSER: "firefox" + FIREFOX_VERSION: "latest-esr" # - job: edge-beta # INFO: "Edge Beta" # BROWSER: "microsoft-edge-beta" @@ -45,18 +58,15 @@ jobs: node-version: '18.18.0' # Minimum version for eslint: https://eslint.org/docs/latest/use/getting-started - name: Set up Firefox - if: matrix.job == 'firefox' + if: ${{ matrix.BROWSER == 'firefox' }} uses: browser-actions/setup-firefox@v1 with: - firefox-version: 'latest' + firefox-version: ${{ matrix.FIREFOX_VERSION }} - name: Install Gecko Driver - if: matrix.job == 'firefox' + if: ${{ matrix.BROWSER == 'firefox' }} uses: browser-actions/setup-geckodriver@latest - - name: Check that Gecko Driver and Firefox are installed - run: | - geckodriver --version - firefox --version + # - name: Install Browser Dependencies # Firefox documentation # run: | # sudo apt update From 0ae7159fbd1088efdf99593c100dc306fbb4eb2b Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 09:56:44 -0400 Subject: [PATCH 17/45] Try Firefox tests without headless argument --- tests/selenium/pbtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index a5a59140e8..05f818fe7c 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -231,7 +231,7 @@ def firefox_manager(self): # disable JSON viewer as it breaks parsing JSON pages opts.set_preference("devtools.jsonview.enabled", False) - opts.add_argument("--headless") + # opts.add_argument("--headless") # to produce a trace-level geckodriver.log, # remove the log_output argument to FirefoxService() From 5cda133c6938d793c73b47065b655f143d6bf1af Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 11:04:37 -0400 Subject: [PATCH 18/45] Add Edge Beta tests --- .github/workflows/test.yml | 16 ++++++++++++---- scripts/setup_travis.sh | 1 + tests/selenium/pbtest.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1a0b50f82..e25b066c38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - job: [lint, firefox, firefox-beta, firefox-nightly, firefox-esr] + job: [lint, firefox, firefox-beta, firefox-nightly, firefox-esr, edge-beta] # job: [lint, firefox, edge-beta] include: - job: lint @@ -36,9 +36,9 @@ jobs: INFO: "Firefox ESR" BROWSER: "firefox" FIREFOX_VERSION: "latest-esr" - # - job: edge-beta - # INFO: "Edge Beta" - # BROWSER: "microsoft-edge-beta" + - job: edge-beta + INFO: "Edge Beta" + BROWSER: "microsoft-edge-beta" env: INFO: ${{ matrix.INFO }} BROWSER: ${{ matrix.BROWSER }} @@ -67,6 +67,14 @@ jobs: if: ${{ matrix.BROWSER == 'firefox' }} uses: browser-actions/setup-geckodriver@latest + - name: Set up Edge + if: ${{ matrix.BROWSER == 'microsoft-edge-beta' }} + uses: browser-actions/setup-edge@v1 + with: + edge-version: beta + # Why do we test with Edge Beta but not Edge? + + # - run: Xvfb :99 & # - name: Install Browser Dependencies # Firefox documentation # run: | # sudo apt update diff --git a/scripts/setup_travis.sh b/scripts/setup_travis.sh index 52d5fe9c42..48b64cd109 100755 --- a/scripts/setup_travis.sh +++ b/scripts/setup_travis.sh @@ -84,6 +84,7 @@ case $INFO in ;; *Firefox*) check_browser + # sudo apt-get install -y xvfb # install_geckodriver install_python_deps ;; diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 05f818fe7c..a5a59140e8 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -231,7 +231,7 @@ def firefox_manager(self): # disable JSON viewer as it breaks parsing JSON pages opts.set_preference("devtools.jsonview.enabled", False) - # opts.add_argument("--headless") + opts.add_argument("--headless") # to produce a trace-level geckodriver.log, # remove the log_output argument to FirefoxService() From 912f09eef99e8e0db1524a77eb0250dbba1c71e8 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 11:09:38 -0400 Subject: [PATCH 19/45] Try adding --edge-skip-compat-layer-relaunch flag --- tests/selenium/pbtest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index a5a59140e8..9c25fc30fb 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -189,6 +189,7 @@ def chrome_manager(self): def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) + opts.add_argument("--edge-skip-compat-layer-relaunch") # https://github.com/SeleniumHQ/selenium/issues/15340#issuecomment-2689372248 opts.binary_location = self.browser_path for i in range(5): From bf922a6e5765906203af537ee962990682040a95 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 12:35:26 -0400 Subject: [PATCH 20/45] Try making edge headless --- tests/selenium/pbtest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 9c25fc30fb..b60e44246b 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -189,6 +189,7 @@ def chrome_manager(self): def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) + opts.add_argument("--headless") opts.add_argument("--edge-skip-compat-layer-relaunch") # https://github.com/SeleniumHQ/selenium/issues/15340#issuecomment-2689372248 opts.binary_location = self.browser_path From 57db217bd5422bb0e9564f4a3e59134574ad8ad2 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 14:11:01 -0400 Subject: [PATCH 21/45] Add Chrome stable and beta tests --- .github/workflows/test.yml | 55 ++++++++++++++------------------------ scripts/setup_travis.sh | 2 +- tests/selenium/pbtest.py | 2 +- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e25b066c38..c382a1cb81 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,8 +18,6 @@ jobs: include: - job: lint INFO: "lint" - # No BROWSER variable needed for linting - # Don't test Chrome in non-mv3 codebase - job: firefox INFO: "Firefox" BROWSER: "firefox" @@ -39,6 +37,15 @@ jobs: - job: edge-beta INFO: "Edge Beta" BROWSER: "microsoft-edge-beta" + # Move Chrome tests into mv3 repo after testing: + - job: chrome + INFO: "Chrome" + BROWSER: "google-chrome-stable" + CHROME_VERSION: "stable" + - job: chrome-beta + INFO: "Chrome Beta" + BROWSER: "google-chrome-beta" + CHROME_VERSION: "beta" env: INFO: ${{ matrix.INFO }} BROWSER: ${{ matrix.BROWSER }} @@ -73,39 +80,17 @@ jobs: with: edge-version: beta # Why do we test with Edge Beta but not Edge? - - # - run: Xvfb :99 & - # - name: Install Browser Dependencies # Firefox documentation - # run: | - # sudo apt update - # # Install Xvfb (replacing xvfb in Travis services) - # sudo apt-get install -y xvfb - # # Install browsers as needed: - # if [[ "${BROWSER}" == "firefox" ]]; then - # sudo install -d -m 0755 /etc/apt/keyrings - # wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null - # gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}' - # echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null - # echo ' - # Package: * - # Pin: origin packages.mozilla.org - # Pin-Priority: 1000 - # ' | sudo tee /etc/apt/preferences.d/mozilla - # sudo apt-get update && sudo apt-get install firefox - # # Print the Firefox binary path - # echo "Firefox binary path:" - # which firefox - # ls -l "$(which firefox)" - # # Print the version to confirm it's installed correctly - # firefox --version - # elif [[ "${BROWSER}" == "microsoft-edge-beta" ]]; then - # curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg - # sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ - # sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-beta.list' - # sudo rm microsoft.gpg - # sudo apt update - # sudo apt install microsoft-edge-beta - # fi + + - name: Set up Chrome + if: ${{ contains(matrix.BROWSER, 'chrome') }} + uses: browser-actions/setup-chrome@v1 + with: + chrome-version: ${{ matrix.CHROME_VERSION }} + install-chromedriver: true + + # - name: Install Chrome Driver + # if: ${{ contains(matrix.BROWSER, 'chrome') }} + # uses: browser-actions/setup-geckodriver@latest - name: Run Setup Script run: ./scripts/setup_travis.sh diff --git a/scripts/setup_travis.sh b/scripts/setup_travis.sh index 48b64cd109..4248a2c616 100755 --- a/scripts/setup_travis.sh +++ b/scripts/setup_travis.sh @@ -79,7 +79,7 @@ check_browser() { case $INFO in *Chrome*) check_browser - "$toplevel"/scripts/chromedriver.sh "$BROWSER" || exit 1 + # "$toplevel"/scripts/chromedriver.sh "$BROWSER" || exit 1 install_python_deps ;; *Firefox*) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index b60e44246b..55edfdca57 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -190,7 +190,7 @@ def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) opts.add_argument("--headless") - opts.add_argument("--edge-skip-compat-layer-relaunch") # https://github.com/SeleniumHQ/selenium/issues/15340#issuecomment-2689372248 + # opts.add_argument("--edge-skip-compat-layer-relaunch") # https://github.com/SeleniumHQ/selenium/issues/15340#issuecomment-2689372248 opts.binary_location = self.browser_path for i in range(5): From 32e505a75dd2663d110943beb1a378418dd5544e Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 14:17:20 -0400 Subject: [PATCH 22/45] Use headless Chrome --- tests/selenium/pbtest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 55edfdca57..f75b5d3f01 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -163,6 +163,7 @@ def on_travis(self): @contextmanager def chrome_manager(self): opts = ChromeOptions() + opts.add_argument("--headless") opts.add_argument("--load-extension=" + self.extension_path) opts.binary_location = self.browser_path From 337601d2ef77e54116fc133ac9bbc9df128afbc8 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 15:26:55 -0400 Subject: [PATCH 23/45] Check installed path --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c382a1cb81..4647bdaa02 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,6 +87,11 @@ jobs: with: chrome-version: ${{ matrix.CHROME_VERSION }} install-chromedriver: true + - run: | + ${{ steps.setup-chrome.outputs.chrome-path }} --version + chrome --version + google-chrome --version + ${{ matrix.BROWSER }} --version # - name: Install Chrome Driver # if: ${{ contains(matrix.BROWSER, 'chrome') }} From 162c25bbb707e84dc218c30b6b9c41f043f1836f Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 15:31:16 -0400 Subject: [PATCH 24/45] Only verify Chrome Installation for Chrome --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4647bdaa02..be303e3bf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,11 +87,13 @@ jobs: with: chrome-version: ${{ matrix.CHROME_VERSION }} install-chromedriver: true - - run: | + - name: Verify Chrome Installation + if: ${{ contains(matrix.BROWSER, 'chrome') }} + run: | ${{ steps.setup-chrome.outputs.chrome-path }} --version + ${{ matrix.BROWSER }} --version chrome --version google-chrome --version - ${{ matrix.BROWSER }} --version # - name: Install Chrome Driver # if: ${{ contains(matrix.BROWSER, 'chrome') }} From f6536b2b0020dc179993a88b6b39d2a98c5da055 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 15:36:26 -0400 Subject: [PATCH 25/45] Add missing step id --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be303e3bf5..5046f9295f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,6 +87,7 @@ jobs: with: chrome-version: ${{ matrix.CHROME_VERSION }} install-chromedriver: true + id: setup-chrome - name: Verify Chrome Installation if: ${{ contains(matrix.BROWSER, 'chrome') }} run: | From 81670f10951c5a42669c522859b04d1b28769ae9 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 16:29:23 -0400 Subject: [PATCH 26/45] Overwrite system Chrome to fix Chrome Driver and Chrome version incompatibility error --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5046f9295f..072b49aca4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,6 +95,11 @@ jobs: ${{ matrix.BROWSER }} --version chrome --version google-chrome --version + - name: Overwrite system Chrome + if: ${{ contains(matrix.BROWSER, 'chrome') }} + run: | + sudo rm -f /usr/bin/google-chrome + sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome # - name: Install Chrome Driver # if: ${{ contains(matrix.BROWSER, 'chrome') }} From 25e762e7a432d77706fea1bfd9fb9e3501138fea Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 3 Apr 2025 16:39:25 -0400 Subject: [PATCH 27/45] Overwrite version-specific system chrome --- .github/workflows/test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 072b49aca4..0813ac2247 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -99,7 +99,17 @@ jobs: if: ${{ contains(matrix.BROWSER, 'chrome') }} run: | sudo rm -f /usr/bin/google-chrome + sudo rm -f /usr/bin/${{ matrix.BROWSER }} sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome + sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/${{ matrix.BROWSER }} + + - name: Check Chrome Installation after overwriting system Chrome + if: ${{ contains(matrix.BROWSER, 'chrome') }} + run: | + ${{ steps.setup-chrome.outputs.chrome-path }} --version + ${{ matrix.BROWSER }} --version + chrome --version + google-chrome --version # - name: Install Chrome Driver # if: ${{ contains(matrix.BROWSER, 'chrome') }} From fa8e6957afbf82b6736467cd87e8a2eb1462bac8 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Fri, 4 Apr 2025 11:39:30 -0400 Subject: [PATCH 28/45] Separate Github Action changes from Travis code --- .github/workflows/test.yml | 18 +++------ scripts/run_travis.sh | 6 --- scripts/setup_ga_tests.sh | 75 ++++++++++++++++++++++++++++++++++++++ scripts/setup_travis.sh | 5 +-- tests/selenium/pbtest.py | 6 +-- 5 files changed, 85 insertions(+), 25 deletions(-) create mode 100755 scripts/setup_ga_tests.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0813ac2247..07a79da831 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,20 +1,21 @@ -name: Selenium Testing +name: Tests on: push: branches: - master - travis-github-action + - travis-github-action-mv3 pull_request: workflow_dispatch: jobs: test: runs-on: ubuntu-22.04 + continue-on-error: ${{ matrix.job != 'lint' }} strategy: matrix: - job: [lint, firefox, firefox-beta, firefox-nightly, firefox-esr, edge-beta] - # job: [lint, firefox, edge-beta] + job: [lint, firefox, firefox-beta, firefox-nightly, firefox-esr, edge-beta, chrome, chrome-beta] include: - job: lint INFO: "lint" @@ -37,7 +38,6 @@ jobs: - job: edge-beta INFO: "Edge Beta" BROWSER: "microsoft-edge-beta" - # Move Chrome tests into mv3 repo after testing: - job: chrome INFO: "Chrome" BROWSER: "google-chrome-stable" @@ -79,7 +79,6 @@ jobs: uses: browser-actions/setup-edge@v1 with: edge-version: beta - # Why do we test with Edge Beta but not Edge? - name: Set up Chrome if: ${{ contains(matrix.BROWSER, 'chrome') }} @@ -88,6 +87,7 @@ jobs: chrome-version: ${{ matrix.CHROME_VERSION }} install-chromedriver: true id: setup-chrome + - name: Verify Chrome Installation if: ${{ contains(matrix.BROWSER, 'chrome') }} run: | @@ -102,7 +102,6 @@ jobs: sudo rm -f /usr/bin/${{ matrix.BROWSER }} sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/${{ matrix.BROWSER }} - - name: Check Chrome Installation after overwriting system Chrome if: ${{ contains(matrix.BROWSER, 'chrome') }} run: | @@ -110,13 +109,8 @@ jobs: ${{ matrix.BROWSER }} --version chrome --version google-chrome --version - - # - name: Install Chrome Driver - # if: ${{ contains(matrix.BROWSER, 'chrome') }} - # uses: browser-actions/setup-geckodriver@latest - - name: Run Setup Script - run: ./scripts/setup_travis.sh + run: ./scripts/setup_ga_tests.sh - name: Run Tests run: ./scripts/run_travis.sh \ No newline at end of file diff --git a/scripts/run_travis.sh b/scripts/run_travis.sh index b140b46521..bd7d5aaa28 100755 --- a/scripts/run_travis.sh +++ b/scripts/run_travis.sh @@ -22,12 +22,6 @@ else case $BROWSER in *chrome*) echo "Running tests on Chrome" - # check that chromedriver is now present - type chromedriver >/dev/null 2>&1 || { - echo "Failed to install ChromeDriver!" - exit 1 - } - chromedriver --version run_selenium ;; *firefox*) diff --git a/scripts/setup_ga_tests.sh b/scripts/setup_ga_tests.sh new file mode 100755 index 0000000000..50b9fb84b8 --- /dev/null +++ b/scripts/setup_ga_tests.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +toplevel=$(git rev-parse --show-toplevel) + +install_edge_webdriver() { + edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) + edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" + edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) + if [ -z "$edgedriver_version" ]; then + echo "Failed to retrieve Edge WebDriver version!" + exit 1 + fi + + echo "Installing Edge WebDriver version $edgedriver_version ..." + wget "https://msedgedriver.azureedge.net/${edgedriver_version}/edgedriver_linux64.zip" + unzip edgedriver_linux64.zip + sudo mv msedgedriver /usr/local/bin/ + sudo chmod a+x /usr/local/bin/msedgedriver + + # check that Edge WebDriver is now present + type msedgedriver >/dev/null 2>&1 || { + echo "Failed to install Edge WebDriver!" + exit 1 + } +} + +install_python_deps() { + pip install -r "$toplevel"/tests/requirements.txt +} + +install_node_deps() { + # "--production" to skip installing devDependencies modules + npm ci --production || exit 1 +} + +# check that the desired browser is present as it might fail to install +# for example: https://travis-ci.org/EFForg/privacybadger/jobs/362381214 +check_browser() { + type "$BROWSER" >/dev/null 2>&1 || { + echo "$BROWSER seems to be missing!" + exit 1 + } + + # print the version + echo "Found $("$BROWSER" --version)" +} + +case $INFO in + *Chrome*) + check_browser + # check that chromedriver is present + type chromedriver >/dev/null 2>&1 || { + echo "Failed to install ChromeDriver!" + exit 1 + } + chromedriver --version + install_python_deps + ;; + *Firefox*) + check_browser + install_geckodriver + install_python_deps + ;; + *Edge*) + check_browser + install_python_deps + ;; + *lint*) + install_node_deps + ;; + *) + echo "bad INFO variable, got $INFO" + exit 1 + ;; +esac diff --git a/scripts/setup_travis.sh b/scripts/setup_travis.sh index 4248a2c616..f45ab24628 100755 --- a/scripts/setup_travis.sh +++ b/scripts/setup_travis.sh @@ -79,13 +79,12 @@ check_browser() { case $INFO in *Chrome*) check_browser - # "$toplevel"/scripts/chromedriver.sh "$BROWSER" || exit 1 + "$toplevel"/scripts/chromedriver.sh "$BROWSER" || exit 1 install_python_deps ;; *Firefox*) check_browser - # sudo apt-get install -y xvfb - # install_geckodriver + install_geckodriver install_python_deps ;; *Edge*) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index f75b5d3f01..c67e62c153 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -191,7 +191,6 @@ def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) opts.add_argument("--headless") - # opts.add_argument("--edge-skip-compat-layer-relaunch") # https://github.com/SeleniumHQ/selenium/issues/15340#issuecomment-2689372248 opts.binary_location = self.browser_path for i in range(5): @@ -239,10 +238,9 @@ def firefox_manager(self): # to produce a trace-level geckodriver.log, # remove the log_output argument to FirefoxService() # and uncomment the line below - opts.log.level = "trace" - service = FirefoxService() + # opts.log.level = "trace" - # service = FirefoxService(log_output=os.path.devnull) + service = FirefoxService(log_output=os.path.devnull) driver = webdriver.Firefox(options=opts, service=service) except WebDriverException as e: From dce23d1d98110aa1bd1f069b39813091ed596e15 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 8 Apr 2025 18:53:09 -0400 Subject: [PATCH 29/45] Limit headless mode argument to Github Actions --- .github/workflows/test.yml | 15 ++------------- tests/selenium/pbtest.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07a79da831..1630932b7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -88,27 +88,16 @@ jobs: install-chromedriver: true id: setup-chrome - - name: Verify Chrome Installation - if: ${{ contains(matrix.BROWSER, 'chrome') }} - run: | - ${{ steps.setup-chrome.outputs.chrome-path }} --version - ${{ matrix.BROWSER }} --version - chrome --version - google-chrome --version - - name: Overwrite system Chrome + - name: Overwrite system Chrome and verify Chrome installation if: ${{ contains(matrix.BROWSER, 'chrome') }} run: | sudo rm -f /usr/bin/google-chrome sudo rm -f /usr/bin/${{ matrix.BROWSER }} sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/${{ matrix.BROWSER }} - - name: Check Chrome Installation after overwriting system Chrome - if: ${{ contains(matrix.BROWSER, 'chrome') }} - run: | ${{ steps.setup-chrome.outputs.chrome-path }} --version ${{ matrix.BROWSER }} --version - chrome --version - google-chrome --version + - name: Run Setup Script run: ./scripts/setup_ga_tests.sh diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index c67e62c153..54778f33d2 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -160,12 +160,19 @@ def on_travis(self): return True return False + @property + def on_github_actions(self): + if "GITHUB_ACTIONS" in os.environ: + return True + return False + @contextmanager def chrome_manager(self): opts = ChromeOptions() - opts.add_argument("--headless") opts.add_argument("--load-extension=" + self.extension_path) opts.binary_location = self.browser_path + if self.on_github_actions: + opts.add_argument("--headless") # TODO not yet in Firefox (w/o hacks anyway): # https://github.com/mozilla/geckodriver/issues/284#issuecomment-456073771 @@ -190,8 +197,9 @@ def chrome_manager(self): def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) - opts.add_argument("--headless") opts.binary_location = self.browser_path + if self.on_github_actions: + opts.add_argument("--headless") for i in range(5): try: @@ -233,12 +241,13 @@ def firefox_manager(self): # disable JSON viewer as it breaks parsing JSON pages opts.set_preference("devtools.jsonview.enabled", False) - opts.add_argument("--headless") + if self.on_github_actions: + opts.add_argument("--headless") # to produce a trace-level geckodriver.log, # remove the log_output argument to FirefoxService() # and uncomment the line below - # opts.log.level = "trace" + #opts.log.level = "trace" service = FirefoxService(log_output=os.path.devnull) driver = webdriver.Firefox(options=opts, service=service) From c61c90b1b3489b67ff60aac31229600431ea9b2b Mon Sep 17 00:00:00 2001 From: lenacohen Date: Tue, 8 Apr 2025 19:38:53 -0400 Subject: [PATCH 30/45] Run on pushes to mv3-chrome branch and restore color --- .github/workflows/test.yml | 1 + scripts/run_travis.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1630932b7a..4c370db3ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - mv3-chrome - travis-github-action - travis-github-action-mv3 pull_request: diff --git a/scripts/run_travis.sh b/scripts/run_travis.sh index bd7d5aaa28..e6a9f65022 100755 --- a/scripts/run_travis.sh +++ b/scripts/run_travis.sh @@ -12,7 +12,7 @@ run_lint() { run_selenium() { # autodiscover and run the tests - pytest --capture=no --verbose --durations=10 "$testdir" + pytest --capture=no --color=yes --verbose --durations=10 "$testdir" } if [ "$INFO" == "lint" ]; then From fd8dff5dcfdce7b739e9ab5ed7dcbd9e33c003b6 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 10 Apr 2025 10:34:46 -0400 Subject: [PATCH 31/45] Address PR feedback to simplify the config and remove Chrome steps from MV2 codebase --- .github/workflows/test.yml | 83 +++++++++++++++++--------------------- scripts/edge_webdriver.sh | 21 ++++++++++ 2 files changed, 57 insertions(+), 47 deletions(-) create mode 100755 scripts/edge_webdriver.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c370db3ee..0608505c8e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,25 +1,32 @@ name: Tests -on: - push: - branches: - - master - - mv3-chrome - - travis-github-action - - travis-github-action-mv3 - pull_request: - workflow_dispatch: +on: [pull_request, push, workflow_dispatch] jobs: + lint: + runs-on: ubuntu-22.04 + steps: + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18.18.0' # Minimum version for eslint: https://eslint.org/docs/latest/use/getting-started + - name: Run Lint + # "--production" to skip installing devDependencies modules + run: | + npm ci --production || exit 1 + toplevel=$(git rev-parse --show-toplevel) + if ! make -C "$toplevel" lint; then + echo "Linting errors" + exit 1 + fi + test: runs-on: ubuntu-22.04 - continue-on-error: ${{ matrix.job != 'lint' }} + continue-on-error: true strategy: matrix: - job: [lint, firefox, firefox-beta, firefox-nightly, firefox-esr, edge-beta, chrome, chrome-beta] + job: [firefox, firefox-beta, firefox-nightly, firefox-esr, edge-beta] include: - - job: lint - INFO: "lint" - job: firefox INFO: "Firefox" BROWSER: "firefox" @@ -39,14 +46,7 @@ jobs: - job: edge-beta INFO: "Edge Beta" BROWSER: "microsoft-edge-beta" - - job: chrome - INFO: "Chrome" - BROWSER: "google-chrome-stable" - CHROME_VERSION: "stable" - - job: chrome-beta - INFO: "Chrome Beta" - BROWSER: "google-chrome-beta" - CHROME_VERSION: "beta" + env: INFO: ${{ matrix.INFO }} BROWSER: ${{ matrix.BROWSER }} @@ -59,11 +59,10 @@ jobs: with: python-version: '3.11' - - name: Set up Node.js for linting - if: matrix.job == 'lint' - uses: actions/setup-node@v4 - with: - node-version: '18.18.0' # Minimum version for eslint: https://eslint.org/docs/latest/use/getting-started + - name: Install python dependencies + run: | + toplevel=$(git rev-parse --show-toplevel) + pip install -r "$toplevel"/tests/requirements.txt - name: Set up Firefox if: ${{ matrix.BROWSER == 'firefox' }} @@ -81,26 +80,16 @@ jobs: with: edge-version: beta - - name: Set up Chrome - if: ${{ contains(matrix.BROWSER, 'chrome') }} - uses: browser-actions/setup-chrome@v1 - with: - chrome-version: ${{ matrix.CHROME_VERSION }} - install-chromedriver: true - id: setup-chrome - - - name: Overwrite system Chrome and verify Chrome installation - if: ${{ contains(matrix.BROWSER, 'chrome') }} - run: | - sudo rm -f /usr/bin/google-chrome - sudo rm -f /usr/bin/${{ matrix.BROWSER }} - sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome - sudo ln -s ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/${{ matrix.BROWSER }} - ${{ steps.setup-chrome.outputs.chrome-path }} --version - ${{ matrix.BROWSER }} --version - - - name: Run Setup Script - run: ./scripts/setup_ga_tests.sh + - name: Instal Edge WebDriver + if: ${{ matrix.BROWSER == 'microsoft-edge-beta' }} + run: ./scripts/edge_webdriver.sh - name: Run Tests - run: ./scripts/run_travis.sh \ No newline at end of file + run: | + type "$BROWSER" >/dev/null 2>&1 || { + echo "$BROWSER seems to be missing!" + exit 1 + } + echo "Found $("$BROWSER" --version)" + testdir=${toplevel}/tests/selenium + pytest --capture=no --color=yes --verbose --durations=10 "$testdir" \ No newline at end of file diff --git a/scripts/edge_webdriver.sh b/scripts/edge_webdriver.sh new file mode 100755 index 0000000000..c56bf496e5 --- /dev/null +++ b/scripts/edge_webdriver.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) +edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" +edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) +if [ -z "$edgedriver_version" ]; then + echo "Failed to retrieve Edge WebDriver version!" + exit 1 +fi + +echo "Installing Edge WebDriver version $edgedriver_version ..." +wget "https://msedgedriver.azureedge.net/${edgedriver_version}/edgedriver_linux64.zip" +unzip edgedriver_linux64.zip +sudo mv msedgedriver /usr/local/bin/ +sudo chmod a+x /usr/local/bin/msedgedriver + +# check that Edge WebDriver is now present +type msedgedriver >/dev/null 2>&1 || { + echo "Failed to install Edge WebDriver!" + exit 1 +} \ No newline at end of file From 3b2eac076d1b3a9eba9ecf82cef26dbe24d41333 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 10 Apr 2025 10:36:11 -0400 Subject: [PATCH 32/45] Remove Travis code and references --- .travis.yml | 36 -------------- doc/tests.md | 8 +-- scripts/chromedriver.sh | 56 --------------------- scripts/run_travis.sh | 40 --------------- scripts/setup_ga_tests.sh | 75 ---------------------------- scripts/setup_travis.sh | 102 -------------------------------------- 6 files changed, 4 insertions(+), 313 deletions(-) delete mode 100644 .travis.yml delete mode 100755 scripts/chromedriver.sh delete mode 100755 scripts/run_travis.sh delete mode 100755 scripts/setup_ga_tests.sh delete mode 100755 scripts/setup_travis.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7f1540fbf1..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -sudo: required -language: python -os: linux -dist: jammy -python: 3.11 -jobs: - fast_finish: true - include: - - env: INFO="lint" - node_js: node - - env: INFO="Firefox" BROWSER=firefox - addons: - firefox: latest - - env: INFO="Firefox Beta" BROWSER=firefox - addons: - firefox: latest-beta - - env: INFO="Firefox Nightly" BROWSER=firefox - addons: - firefox: latest-nightly - - env: INFO="Firefox ESR" BROWSER=firefox - addons: - firefox: latest-esr - - env: INFO="Edge Beta" BROWSER=microsoft-edge-beta - # from https://www.microsoftedgeinsider.com/en-us/download?platform=linux-deb - install: - - curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg - - sudo install -o root -g root -m 644 microsoft.gpg /usr/share/keyrings/ - - sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-beta.list' - - sudo rm microsoft.gpg - - sudo apt update - - sudo apt install microsoft-edge-beta - -before_script: travis_retry ./scripts/setup_travis.sh -script: . ./scripts/run_travis.sh -services: - - xvfb diff --git a/doc/tests.md b/doc/tests.md index b8847fc69a..aa2647e48b 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -5,13 +5,13 @@ There are two types of tests: * [Unit tests](/doc/tests.md#unit-tests) for exercising isolated units of code * [Functional tests](/doc/tests.md#functional-tests) for verifying high-level extension functionality -[Travis CI](/doc/tests.md#travis-ci) runs unit and functional tests on every pull request on Chrome, Firefox and Edge. +[Github Actions](/doc/tests.md#github-actions-ci) runs unit and functional tests on every pull request on Chrome, Firefox and Edge. -## Travis CI +## Github Actions CI -Every pull request runs the [full suite of tests on Travis CI](https://app.travis-ci.com/github/EFForg/privacybadger/branches). We test on latest stable Chrome and Firefox releases, as well as on Chrome Beta, Edge Beta, Firefox Beta and Firefox ESR. +Every pull request runs the full suite of tests on Github Actions. We test on latest stable Chrome and Firefox releases, as well as on Chrome Beta, Edge Beta, Firefox Beta and Firefox ESR. -See [`.travis.yml`](/.travis.yml) for Travis configuration, [`scripts/setup_travis.sh`](/scripts/setup_travis.sh) for test setup, and [`scripts/run_travis.sh`](/scripts/run_travis.sh) for test execution procedures. +See [`test.yml`](/.github/workflows/test.yml) for the Github Actions configuration. We use [ESLint](https://eslint.org) to flag potential JavaScript errors and style issues. Please see our [developer guide](/doc/develop.md#lint-your-changes) for setup instructions. diff --git a/scripts/chromedriver.sh b/scripts/chromedriver.sh deleted file mode 100755 index 33afbb3756..0000000000 --- a/scripts/chromedriver.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -# installs the appropriate version of ChromeDriver for a given Chrome version - -TEMPDIR=$(mktemp -d) -trap 'rm -rf $TEMPDIR' EXIT - -# one of google-chrome, google-chrome-stable, -# google-chrome-beta, or google-chrome-unstable -CHROME="${1:-google-chrome}" - -major_version=$("$CHROME" --product-version | cut -d . -f 1) - -if [ -z "$major_version" ]; then - echo "Failed to look up version of $CHROME" - exit 1 -fi - -if [ "$major_version" -lt 115 ]; then - echo "This script supports installing ChromeDriver for Chrome 115+ only" - exit 1 -fi - -channel=Stable -case "$CHROME" in - *beta*) - channel=Beta - ;; - *unstable*) - channel=Dev - ;; -esac -json_url=https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json -json=$(wget "$json_url" -q -O -) -chromedriver_version=$(echo "$json" | python3 -c "import sys, json; print(json.load(sys.stdin)['channels']['$channel']['version'])") -chromedriver_url=$(echo "$json" | python3 -c "import sys, json; print(next(i['url'] for i in json.load(sys.stdin)['channels']['$channel']['downloads']['chromedriver'] if i['platform'] == 'linux64'))") - -if [ -z "$chromedriver_version" ]; then - echo "Failed to retrieve ChromeDriver version" - exit 1 -fi - -echo "Setting up ChromeDriver version $chromedriver_version ..." - -wget -q -O "$TEMPDIR/chromedriver.zip" "$chromedriver_url" \ - && unzip -q -o "$TEMPDIR/chromedriver.zip" chromedriver-linux64/chromedriver -d "$TEMPDIR" \ - && sudo mv "$TEMPDIR/chromedriver-linux64/chromedriver" /usr/local/bin/chromedriver \ - && sudo chmod a+x /usr/local/bin/chromedriver - -# check that chromedriver is now present -type chromedriver >/dev/null 2>&1 || { - echo "Failed to install ChromeDriver!" - exit 1 -} - -chromedriver --version diff --git a/scripts/run_travis.sh b/scripts/run_travis.sh deleted file mode 100755 index e6a9f65022..0000000000 --- a/scripts/run_travis.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -toplevel=$(git rev-parse --show-toplevel) -testdir=${toplevel}/tests/selenium - -run_lint() { - if ! make -C "$toplevel" lint; then - echo "Linting errors" - exit 1 - fi -} - -run_selenium() { - # autodiscover and run the tests - pytest --capture=no --color=yes --verbose --durations=10 "$testdir" -} - -if [ "$INFO" == "lint" ]; then - echo "Running lint" - run_lint -else - case $BROWSER in - *chrome*) - echo "Running tests on Chrome" - run_selenium - ;; - *firefox*) - echo "Running tests on Firefox" - run_selenium - ;; - *edge*) - echo "Running tests on Edge" - run_selenium - ;; - *) - echo "Unknown BROWSER value: $BROWSER" - exit 1 - ;; - esac -fi diff --git a/scripts/setup_ga_tests.sh b/scripts/setup_ga_tests.sh deleted file mode 100755 index 50b9fb84b8..0000000000 --- a/scripts/setup_ga_tests.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash - -toplevel=$(git rev-parse --show-toplevel) - -install_edge_webdriver() { - edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) - edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" - edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) - if [ -z "$edgedriver_version" ]; then - echo "Failed to retrieve Edge WebDriver version!" - exit 1 - fi - - echo "Installing Edge WebDriver version $edgedriver_version ..." - wget "https://msedgedriver.azureedge.net/${edgedriver_version}/edgedriver_linux64.zip" - unzip edgedriver_linux64.zip - sudo mv msedgedriver /usr/local/bin/ - sudo chmod a+x /usr/local/bin/msedgedriver - - # check that Edge WebDriver is now present - type msedgedriver >/dev/null 2>&1 || { - echo "Failed to install Edge WebDriver!" - exit 1 - } -} - -install_python_deps() { - pip install -r "$toplevel"/tests/requirements.txt -} - -install_node_deps() { - # "--production" to skip installing devDependencies modules - npm ci --production || exit 1 -} - -# check that the desired browser is present as it might fail to install -# for example: https://travis-ci.org/EFForg/privacybadger/jobs/362381214 -check_browser() { - type "$BROWSER" >/dev/null 2>&1 || { - echo "$BROWSER seems to be missing!" - exit 1 - } - - # print the version - echo "Found $("$BROWSER" --version)" -} - -case $INFO in - *Chrome*) - check_browser - # check that chromedriver is present - type chromedriver >/dev/null 2>&1 || { - echo "Failed to install ChromeDriver!" - exit 1 - } - chromedriver --version - install_python_deps - ;; - *Firefox*) - check_browser - install_geckodriver - install_python_deps - ;; - *Edge*) - check_browser - install_python_deps - ;; - *lint*) - install_node_deps - ;; - *) - echo "bad INFO variable, got $INFO" - exit 1 - ;; -esac diff --git a/scripts/setup_travis.sh b/scripts/setup_travis.sh deleted file mode 100755 index f45ab24628..0000000000 --- a/scripts/setup_travis.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bash - -toplevel=$(git rev-parse --show-toplevel) - -install_edge_webdriver() { - edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) - edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" - edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) - if [ -z "$edgedriver_version" ]; then - echo "Failed to retrieve Edge WebDriver version!" - exit 1 - fi - - echo "Installing Edge WebDriver version $edgedriver_version ..." - wget "https://msedgedriver.azureedge.net/${edgedriver_version}/edgedriver_linux64.zip" - unzip edgedriver_linux64.zip - sudo mv msedgedriver /usr/local/bin/ - sudo chmod a+x /usr/local/bin/msedgedriver - - # check that Edge WebDriver is now present - type msedgedriver >/dev/null 2>&1 || { - echo "Failed to install Edge WebDriver!" - exit 1 - } -} - -install_geckodriver() { - # Install the latest version of geckodriver - version=$(curl -sI https://github.com/mozilla/geckodriver/releases/latest | grep -i "^Location: " | sed 's/.*\///' | tr -d '\r') - - # check that we got something - if [ -z "$version" ]; then - echo "Failed to determine the latest geckodriver version!" - exit 1 - fi - - # Geckodriver distribution is MacOS or Linux specific - os="$(uname -s)" - if [[ $os == "Darwin" ]]; then - os_dist="macos.tar.gz" - else - os_dist="linux64.tar.gz" - fi - - echo "Setting up geckodriver version $version ..." - url="https://github.com/mozilla/geckodriver/releases/download/${version}/geckodriver-${version}-${os_dist}" - wget -q -O /tmp/geckodriver.tar.gz "$url" - sudo tar -xvf /tmp/geckodriver.tar.gz -C /usr/local/bin/ - sudo chmod a+x /usr/local/bin/geckodriver - - # check that geckodriver is now present - type geckodriver >/dev/null 2>&1 || { - echo "Failed to install geckodriver!" - exit 1 - } -} - -install_python_deps() { - pip install -r "$toplevel"/tests/requirements.txt -} - -install_node_deps() { - # "--production" to skip installing devDependencies modules - npm ci --production || exit 1 -} - -# check that the desired browser is present as it might fail to install -# for example: https://travis-ci.org/EFForg/privacybadger/jobs/362381214 -check_browser() { - type "$BROWSER" >/dev/null 2>&1 || { - echo "$BROWSER seems to be missing!" - exit 1 - } - - # print the version - echo "Found $("$BROWSER" --version)" -} - -case $INFO in - *Chrome*) - check_browser - "$toplevel"/scripts/chromedriver.sh "$BROWSER" || exit 1 - install_python_deps - ;; - *Firefox*) - check_browser - install_geckodriver - install_python_deps - ;; - *Edge*) - check_browser - install_edge_webdriver - install_python_deps - ;; - *lint*) - install_node_deps - ;; - *) - echo "bad INFO variable, got $INFO" - exit 1 - ;; -esac From 0abef94a9db649a13c82246332497f2e01760843 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 10 Apr 2025 10:53:13 -0400 Subject: [PATCH 33/45] Fix missing steps --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0608505c8e..c67d7dd2da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,8 @@ jobs: lint: runs-on: ubuntu-22.04 steps: + - name: Checkout repository + uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: @@ -90,6 +92,7 @@ jobs: echo "$BROWSER seems to be missing!" exit 1 } + toplevel=$(git rev-parse --show-toplevel) echo "Found $("$BROWSER" --version)" testdir=${toplevel}/tests/selenium pytest --capture=no --color=yes --verbose --durations=10 "$testdir" \ No newline at end of file From 137985a553b282e7bbfa59ec82efc4c047f4bd0b Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 10 Apr 2025 12:15:42 -0400 Subject: [PATCH 34/45] Remove Travis references from pbtest --- tests/selenium/pbtest.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index 54778f33d2..b03219f102 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -145,7 +145,7 @@ def fix_chrome_extension_id(self): @property def wants_xvfb(self): - if self.on_travis or bool(int(os.environ.get('ENABLE_XVFB', 0))): + if bool(int(os.environ.get('ENABLE_XVFB', 0))): try: Xvfb except NameError: @@ -154,12 +154,6 @@ def wants_xvfb(self): return True return False - @property - def on_travis(self): - if "TRAVIS" in os.environ: - return True - return False - @property def on_github_actions(self): if "GITHUB_ACTIONS" in os.environ: From ebc7eea1301465dde34899e130408c6706fa2fb2 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 10 Apr 2025 12:26:58 -0400 Subject: [PATCH 35/45] Switch from --headless to Xvfb --- .github/workflows/test.yml | 8 +++++++- tests/selenium/pbtest.py | 9 +-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c67d7dd2da..04756d67ff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,6 +86,12 @@ jobs: if: ${{ matrix.BROWSER == 'microsoft-edge-beta' }} run: ./scripts/edge_webdriver.sh + - name: Install xvfb + run: | + sudo apt-get update + sudo apt-get install -y xvfb + which Xvfb + - name: Run Tests run: | type "$BROWSER" >/dev/null 2>&1 || { @@ -95,4 +101,4 @@ jobs: toplevel=$(git rev-parse --show-toplevel) echo "Found $("$BROWSER" --version)" testdir=${toplevel}/tests/selenium - pytest --capture=no --color=yes --verbose --durations=10 "$testdir" \ No newline at end of file + xvfb-run --auto-servernum pytest --capture=no --color=yes --verbose --durations=10 "$testdir" \ No newline at end of file diff --git a/tests/selenium/pbtest.py b/tests/selenium/pbtest.py index b03219f102..c477160610 100644 --- a/tests/selenium/pbtest.py +++ b/tests/selenium/pbtest.py @@ -145,7 +145,7 @@ def fix_chrome_extension_id(self): @property def wants_xvfb(self): - if bool(int(os.environ.get('ENABLE_XVFB', 0))): + if self.on_github_actions or bool(int(os.environ.get('ENABLE_XVFB', 0))): try: Xvfb except NameError: @@ -165,8 +165,6 @@ def chrome_manager(self): opts = ChromeOptions() opts.add_argument("--load-extension=" + self.extension_path) opts.binary_location = self.browser_path - if self.on_github_actions: - opts.add_argument("--headless") # TODO not yet in Firefox (w/o hacks anyway): # https://github.com/mozilla/geckodriver/issues/284#issuecomment-456073771 @@ -192,8 +190,6 @@ def edge_manager(self): opts = EdgeOptions() opts.add_argument("--load-extension=" + self.extension_path) opts.binary_location = self.browser_path - if self.on_github_actions: - opts.add_argument("--headless") for i in range(5): try: @@ -235,9 +231,6 @@ def firefox_manager(self): # disable JSON viewer as it breaks parsing JSON pages opts.set_preference("devtools.jsonview.enabled", False) - if self.on_github_actions: - opts.add_argument("--headless") - # to produce a trace-level geckodriver.log, # remove the log_output argument to FirefoxService() # and uncomment the line below From 52dfebc5a9d724f4a93e7152a03f99e6404a1553 Mon Sep 17 00:00:00 2001 From: lenacohen Date: Thu, 10 Apr 2025 13:31:02 -0400 Subject: [PATCH 36/45] Restore branch limit to trigger runs only on pushes to master --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 04756d67ff..3140fc9052 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,11 @@ name: Tests -on: [pull_request, push, workflow_dispatch] +on: + push: + branches: + - master + pull_request: + workflow_dispatch: jobs: lint: From ab3314b7e25d9a5271c7ec64ab46b81b77cf8d7e Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 15:55:23 -0400 Subject: [PATCH 37/45] Tweak lint job --- .github/workflows/test.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3140fc9052..04fc5603b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,16 +16,12 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: '18.18.0' # Minimum version for eslint: https://eslint.org/docs/latest/use/getting-started + node-version: 'lts/*' - name: Run Lint - # "--production" to skip installing devDependencies modules run: | + # "--production" to skip installing devDependencies modules npm ci --production || exit 1 - toplevel=$(git rev-parse --show-toplevel) - if ! make -C "$toplevel" lint; then - echo "Linting errors" - exit 1 - fi + make lint test: runs-on: ubuntu-22.04 @@ -106,4 +102,4 @@ jobs: toplevel=$(git rev-parse --show-toplevel) echo "Found $("$BROWSER" --version)" testdir=${toplevel}/tests/selenium - xvfb-run --auto-servernum pytest --capture=no --color=yes --verbose --durations=10 "$testdir" \ No newline at end of file + xvfb-run --auto-servernum pytest --capture=no --color=yes --verbose --durations=10 "$testdir" From e81971bdbf972460522fd0d6dd3419e75c4a3642 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 15:57:16 -0400 Subject: [PATCH 38/45] Restore ChromeDriver script (useful for local dev) --- scripts/chromedriver.sh | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/chromedriver.sh diff --git a/scripts/chromedriver.sh b/scripts/chromedriver.sh new file mode 100644 index 0000000000..33afbb3756 --- /dev/null +++ b/scripts/chromedriver.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# installs the appropriate version of ChromeDriver for a given Chrome version + +TEMPDIR=$(mktemp -d) +trap 'rm -rf $TEMPDIR' EXIT + +# one of google-chrome, google-chrome-stable, +# google-chrome-beta, or google-chrome-unstable +CHROME="${1:-google-chrome}" + +major_version=$("$CHROME" --product-version | cut -d . -f 1) + +if [ -z "$major_version" ]; then + echo "Failed to look up version of $CHROME" + exit 1 +fi + +if [ "$major_version" -lt 115 ]; then + echo "This script supports installing ChromeDriver for Chrome 115+ only" + exit 1 +fi + +channel=Stable +case "$CHROME" in + *beta*) + channel=Beta + ;; + *unstable*) + channel=Dev + ;; +esac +json_url=https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json +json=$(wget "$json_url" -q -O -) +chromedriver_version=$(echo "$json" | python3 -c "import sys, json; print(json.load(sys.stdin)['channels']['$channel']['version'])") +chromedriver_url=$(echo "$json" | python3 -c "import sys, json; print(next(i['url'] for i in json.load(sys.stdin)['channels']['$channel']['downloads']['chromedriver'] if i['platform'] == 'linux64'))") + +if [ -z "$chromedriver_version" ]; then + echo "Failed to retrieve ChromeDriver version" + exit 1 +fi + +echo "Setting up ChromeDriver version $chromedriver_version ..." + +wget -q -O "$TEMPDIR/chromedriver.zip" "$chromedriver_url" \ + && unzip -q -o "$TEMPDIR/chromedriver.zip" chromedriver-linux64/chromedriver -d "$TEMPDIR" \ + && sudo mv "$TEMPDIR/chromedriver-linux64/chromedriver" /usr/local/bin/chromedriver \ + && sudo chmod a+x /usr/local/bin/chromedriver + +# check that chromedriver is now present +type chromedriver >/dev/null 2>&1 || { + echo "Failed to install ChromeDriver!" + exit 1 +} + +chromedriver --version From b1e1b349776c66c5fbee3f3a9e7d28e0a0f386f2 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 16:55:07 -0400 Subject: [PATCH 39/45] Tweak Selenium tests job --- .github/workflows/test.yml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 04fc5603b3..46ec1e4539 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: npm ci --production || exit 1 make lint - test: + selenium: runs-on: ubuntu-22.04 continue-on-error: true strategy: @@ -62,10 +62,8 @@ jobs: with: python-version: '3.11' - - name: Install python dependencies - run: | - toplevel=$(git rev-parse --show-toplevel) - pip install -r "$toplevel"/tests/requirements.txt + - name: Install Python dependencies + run: pip install -r tests/requirements.txt - name: Set up Firefox if: ${{ matrix.BROWSER == 'firefox' }} @@ -73,7 +71,7 @@ jobs: with: firefox-version: ${{ matrix.FIREFOX_VERSION }} - - name: Install Gecko Driver + - name: Install Geckodriver if: ${{ matrix.BROWSER == 'firefox' }} uses: browser-actions/setup-geckodriver@latest @@ -83,15 +81,12 @@ jobs: with: edge-version: beta - - name: Instal Edge WebDriver + - name: Install Edge WebDriver if: ${{ matrix.BROWSER == 'microsoft-edge-beta' }} run: ./scripts/edge_webdriver.sh - - name: Install xvfb - run: | - sudo apt-get update - sudo apt-get install -y xvfb - which Xvfb + - name: Install Xvfb + run: sudo apt-get install -y xvfb - name: Run Tests run: | @@ -99,7 +94,5 @@ jobs: echo "$BROWSER seems to be missing!" exit 1 } - toplevel=$(git rev-parse --show-toplevel) echo "Found $("$BROWSER" --version)" - testdir=${toplevel}/tests/selenium - xvfb-run --auto-servernum pytest --capture=no --color=yes --verbose --durations=10 "$testdir" + xvfb-run --auto-servernum pytest --capture=no --color=yes --verbose --durations=10 tests/selenium From fa21053d6380c8cd0c6c276ab616b8d53a0ecc40 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 16:56:27 -0400 Subject: [PATCH 40/45] Tweak lint job name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46ec1e4539..13e914ffe8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: 'lts/*' - - name: Run Lint + - name: Run ESLint run: | # "--production" to skip installing devDependencies modules npm ci --production || exit 1 From 9b1b2c1a3fa24c8e08fa4370f8cacc485c6da26d Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 17:00:39 -0400 Subject: [PATCH 41/45] Tweak testing doc --- doc/tests.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/tests.md b/doc/tests.md index aa2647e48b..db0974036d 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -5,13 +5,11 @@ There are two types of tests: * [Unit tests](/doc/tests.md#unit-tests) for exercising isolated units of code * [Functional tests](/doc/tests.md#functional-tests) for verifying high-level extension functionality -[Github Actions](/doc/tests.md#github-actions-ci) runs unit and functional tests on every pull request on Chrome, Firefox and Edge. +[GitHub Actions](/doc/tests.md#github-actions-ci) runs unit and functional tests on every pull request on Chrome, Firefox and Edge. -## Github Actions CI +## GitHub Actions CI -Every pull request runs the full suite of tests on Github Actions. We test on latest stable Chrome and Firefox releases, as well as on Chrome Beta, Edge Beta, Firefox Beta and Firefox ESR. - -See [`test.yml`](/.github/workflows/test.yml) for the Github Actions configuration. +Every pull request runs the full suite of tests on GitHub Actions. See [`test.yml`](/.github/workflows/test.yml) for the GitHub Actions configuration. We use [ESLint](https://eslint.org) to flag potential JavaScript errors and style issues. Please see our [developer guide](/doc/develop.md#lint-your-changes) for setup instructions. From 63d30ed141457ea520ea4f400cd9c183e7697f44 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 17:02:45 -0400 Subject: [PATCH 42/45] chmod +x chromedriver.sh --- scripts/chromedriver.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/chromedriver.sh diff --git a/scripts/chromedriver.sh b/scripts/chromedriver.sh old mode 100644 new mode 100755 From 17121908abfe76139e8603b5967b5b909da73ff0 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 17:05:25 -0400 Subject: [PATCH 43/45] Add a Geckodriver install script for local dev --- scripts/geckodriver.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 scripts/geckodriver.sh diff --git a/scripts/geckodriver.sh b/scripts/geckodriver.sh new file mode 100755 index 0000000000..37354bd915 --- /dev/null +++ b/scripts/geckodriver.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Install the latest version of geckodriver +version=$(curl -sI https://github.com/mozilla/geckodriver/releases/latest | grep -i "^Location: " | sed 's/.*\///' | tr -d '\r') + +# check that we got something +if [ -z "$version" ]; then + echo "Failed to determine the latest geckodriver version!" + exit 1 +fi + +# Geckodriver distribution is MacOS or Linux specific +os="$(uname -s)" +if [[ $os == "Darwin" ]]; then + os_dist="macos.tar.gz" +else + os_dist="linux64.tar.gz" +fi + +echo "Setting up geckodriver version $version ..." +url="https://github.com/mozilla/geckodriver/releases/download/${version}/geckodriver-${version}-${os_dist}" +wget -q -O /tmp/geckodriver.tar.gz "$url" +sudo tar -xvf /tmp/geckodriver.tar.gz -C /usr/local/bin/ +sudo chmod a+x /usr/local/bin/geckodriver + +# check that geckodriver is now present +type geckodriver >/dev/null 2>&1 || { + echo "Failed to install geckodriver!" + exit 1 +} From ebdf2c87e41d8f5c6020385664644c53a6e891f0 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 17:07:45 -0400 Subject: [PATCH 44/45] Remove stray Travis refs --- doc/tests.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc/tests.md b/doc/tests.md index db0974036d..5e5b005f23 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -36,7 +36,7 @@ Do verify that removing or mutating the code being tested produces failed assert Our [functional tests](/tests/selenium/) are written in Python and driven by [Selenium](https://selenium-python.readthedocs.io/) and [pytest](https://docs.pytest.org/en/latest/). - To run them in Chrome, you need to [install `chromedriver`](http://chromedriver.chromium.org/getting-started) -- For Firefox, you need to [install `geckodriver`](https://github.com/EFForg/privacybadger/blob/1550b9efb64c1d5e276361e3940f402c3ec87afc/scripts/setup_travis.sh#L21-L50) +- For Firefox, you need to [install `geckodriver`](/scripts/geckodriver.sh) - For Microsoft Edge, [install Microsoft Edge WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) You also need to [install the Python packages](https://snarky.ca/a-quick-and-dirty-guide-on-how-to-install-packages-for-python/) specified in [`/tests/requirements.txt`](/tests/requirements.txt). @@ -54,9 +54,6 @@ $ BROWSER=/Applications/Firefox.app/Contents/MacOS/firefox-bin pytest -v tests/ $ BROWSER=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome pytest -v tests/ ``` -For more information, see our Travis CI [setup](/scripts/setup_travis.sh) and -[run](/scripts/run_travis.sh) scripts. - ### Invocation examples From 8ce250b3b761931cf1276be88d953079bebec562 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 10 Apr 2025 17:11:55 -0400 Subject: [PATCH 45/45] Mega nits --- scripts/chromedriver.sh | 2 +- scripts/edge_webdriver.sh | 10 +++++----- scripts/geckodriver.sh | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/chromedriver.sh b/scripts/chromedriver.sh index 33afbb3756..b31d0e9171 100755 --- a/scripts/chromedriver.sh +++ b/scripts/chromedriver.sh @@ -49,7 +49,7 @@ wget -q -O "$TEMPDIR/chromedriver.zip" "$chromedriver_url" \ # check that chromedriver is now present type chromedriver >/dev/null 2>&1 || { - echo "Failed to install ChromeDriver!" + echo "Failed to install ChromeDriver" exit 1 } diff --git a/scripts/edge_webdriver.sh b/scripts/edge_webdriver.sh index c56bf496e5..2d5f924906 100755 --- a/scripts/edge_webdriver.sh +++ b/scripts/edge_webdriver.sh @@ -4,8 +4,8 @@ edge_version_major=$(microsoft-edge-beta --product-version | cut -d . -f 1) edgedriver_version_url="https://msedgedriver.azureedge.net/LATEST_RELEASE_${edge_version_major}_LINUX" edgedriver_version=$(curl -s "$edgedriver_version_url" | tr -d "\0\r\n" | cut -c 3-) if [ -z "$edgedriver_version" ]; then - echo "Failed to retrieve Edge WebDriver version!" - exit 1 + echo "Failed to retrieve Edge WebDriver version!" + exit 1 fi echo "Installing Edge WebDriver version $edgedriver_version ..." @@ -16,6 +16,6 @@ sudo chmod a+x /usr/local/bin/msedgedriver # check that Edge WebDriver is now present type msedgedriver >/dev/null 2>&1 || { - echo "Failed to install Edge WebDriver!" - exit 1 -} \ No newline at end of file + echo "Failed to install Edge WebDriver" + exit 1 +} diff --git a/scripts/geckodriver.sh b/scripts/geckodriver.sh index 37354bd915..77dbd4931a 100755 --- a/scripts/geckodriver.sh +++ b/scripts/geckodriver.sh @@ -5,7 +5,7 @@ version=$(curl -sI https://github.com/mozilla/geckodriver/releases/latest | grep # check that we got something if [ -z "$version" ]; then - echo "Failed to determine the latest geckodriver version!" + echo "Failed to determine the latest Geckodriver version!" exit 1 fi @@ -17,7 +17,7 @@ else os_dist="linux64.tar.gz" fi -echo "Setting up geckodriver version $version ..." +echo "Setting up Geckodriver version $version ..." url="https://github.com/mozilla/geckodriver/releases/download/${version}/geckodriver-${version}-${os_dist}" wget -q -O /tmp/geckodriver.tar.gz "$url" sudo tar -xvf /tmp/geckodriver.tar.gz -C /usr/local/bin/ @@ -25,6 +25,6 @@ sudo chmod a+x /usr/local/bin/geckodriver # check that geckodriver is now present type geckodriver >/dev/null 2>&1 || { - echo "Failed to install geckodriver!" + echo "Failed to install Geckodriver" exit 1 }