Skip to content

Commit

Permalink
Run Playwright tests once per day against dev (Fixes #14701)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgibson committed Jun 19, 2024
1 parent 4391652 commit 252a833
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 12 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Workflow that runs Playwright functional tests once per day against dev infra.

name: Playwright Tests
run-name: Playwright Tests for ${{ github.sha }}
env:
SLACK_CHANNEL_ID: CBX0KH5GA # #www-notify in MoCo Slack
SLACK_BOT_TOKEN: ${{secrets.SLACK_BOT_TOKEN_FOR_MEAO_NOTIFICATIONS_APP}}
on:
schedule:
- cron: "0 15 * * *" # 3pm daily
workflow_dispatch:
inputs:
mozorg_service_hostname:
description: The root URL of the Mozorg service to run tests against. eg "https://www.mozilla.org/"
required: true

jobs:
notify-of-test-run-start:
if: github.repository == "mozilla/bedrock"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Notify via Slack that tests are starting
uses: ./.github/actions/slack
with:
env_name: test
label: "Playwright Tests [${{ github.sha }}]"
status: info
channel_id: ${{ env.SLACK_CHANNEL_ID }}
slack_bot_token: ${{ env.SLACK_BOT_TOKEN }}
ref: ${{ github.sha }}
message: "Playwright Tests started"

playwright-tests:
runs-on: ubuntu-latest
needs: notify-of-test-run-start
env:
PLAYWRIGHT_BASE_URL: ${{ github.event.inputs.mozorg_service_hostname || "https://dev.bedrock.nonprod.webservices.mozgcp.net/" }}
CI: true
CI_JOB_ID: ${{ github.run_id }}
DRIVER: ""
LABEL: playwright-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: cd tests/playwright && npm ci && npm run install-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report for ${{ github.sha }}
path: playwright-report/
retention-days: 30

notify-of-test-run-completion:
if: github.repository == "mozilla/bedrock" && always()
runs-on: ubuntu-latest
needs: [notify-of-test-run-start, playwright-tests]
steps:
- uses: actions/checkout@v4
- name: Notify via Slack of test-run outcome
uses: ./.github/actions/slack
with:
env_name: test
label: "Playwright tests [${{ github.sha }}]"
status: ${{ needs.playwright-tests.result }}
channel_id: ${{ env.SLACK_CHANNEL_ID }}
slack_bot_token: ${{ env.SLACK_BOT_TOKEN }}
ref: ${{ github.sha }}
message: "Playwright tests completed. Status: ${{ needs.playwright-tests.result }}"
4 changes: 3 additions & 1 deletion tests/playwright/specs/footer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ test.describe(

// Change page language from /en-US/ to /de/
await languageSelect.selectOption('de');
await page.waitForURL('**/de/?automation=true');
await page.waitForURL('**/de/?automation=true', {
waitUntil: 'commit'
});

// Assert page language is now German
await expect(languageSelect).toHaveValue('de');
Expand Down
8 changes: 6 additions & 2 deletions tests/playwright/specs/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ test.describe(

// Click Firefox desktop link
await firefoxMenuLink.click();
await page.waitForURL('**/firefox/new/');
await page.waitForURL('**/firefox/new/', {
waitUntil: 'commit'
});

// Assert Firefox menu is closed after navigation
await expect(firefoxMenu).not.toBeVisible();
Expand Down Expand Up @@ -163,7 +165,9 @@ test.describe(

// Click Firefox desktop link
await firefoxMenuLink.click();
await page.waitForURL('**/firefox/new/');
await page.waitForURL('**/firefox/new/', {
waitUntil: 'commit'
});

// Assert nav menu is closed again after navigation
await expect(navigationMenuItems).not.toBeVisible();
Expand Down
8 changes: 5 additions & 3 deletions tests/playwright/specs/products/firefox/firefox-home.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ test.describe(
const downloadButton = page.getByTestId('firefox-desktop-download');
await expect(downloadButton).toBeVisible();
await downloadButton.click();
await page.waitForURL('**/firefox/download/thanks/');
await page.waitForURL('**/firefox/download/thanks/', {
waitUntil: 'commit'
});

// Assert /thanks/ page triggers file download.
const download = await page.waitForEvent('download');
const downloadURL = download.url();

expect(downloadURL).toEqual(
expect.stringContaining(
'https://download-installer.cdn.mozilla.net/pub/firefox/releases/'
expect.stringMatching(
/https:\/\/download-installer.cdn.mozilla.net\/|https:\/\/cdn-stage.stubattribution.nonprod.cloudops.mozgcp.net\//
)
);

Expand Down
12 changes: 8 additions & 4 deletions tests/playwright/specs/products/firefox/firefox-new.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ test.describe(

// Click primary download button.
await downloadButton.click();
await page.waitForURL('**/firefox/download/thanks/');
await page.waitForURL('**/firefox/download/thanks/', {
waitUntil: 'commit'
});

// Assert /thanks/ page triggers file download.
const download = await page.waitForEvent('download');
const downloadURL = download.url();

expect(downloadURL).toEqual(
expect.stringContaining(
'https://download-installer.cdn.mozilla.net/pub/firefox/releases/'
expect.stringMatching(
/https:\/\/download-installer.cdn.mozilla.net\/|https:\/\/cdn-stage.stubattribution.nonprod.cloudops.mozgcp.net\//
)
);

Expand Down Expand Up @@ -76,7 +78,9 @@ test.describe(

// Click primary download button.
await downloadButton.click();
await page.waitForURL('**/firefox/download/thanks/');
await page.waitForURL('**/firefox/download/thanks/', {
waitUntil: 'commit'
});

// Assert Linux 32-bit / 64-bit choices are displayed.
const downloadButtonLinux32 = page.getByTestId(
Expand Down
9 changes: 7 additions & 2 deletions tests/playwright/specs/products/vpn/vpn-download.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ test.describe(
await expect(downloadLink).toBeVisible();
await downloadLink.click();
await page.waitForURL(
'**/products/vpn/download/windows/thanks/'
'**/products/vpn/download/windows/thanks/',
{
waitUntil: 'commit'
}
);

// Assert /thanks/ page triggers file download.
Expand Down Expand Up @@ -72,7 +75,9 @@ test.describe(

await expect(downloadLink).toBeVisible();
await downloadLink.click();
await page.waitForURL('**/products/vpn/download/mac/thanks/');
await page.waitForURL('**/products/vpn/download/mac/thanks/', {
waitUntil: 'commit'
});

// Assert /thanks/ page triggers file download.
const download = await page.waitForEvent('download');
Expand Down

0 comments on commit 252a833

Please sign in to comment.