Skip to content

Commit

Permalink
Add Playwright tests for options page (#40)
Browse files Browse the repository at this point in the history
- Change GH action to only run no-auth playwright tests
- Write tests for popup page
  • Loading branch information
ekcom authored Oct 30, 2023
1 parent b0c5064 commit c6e974f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/playwright.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
- name: Build Package
run: |
make build
- name: Run Playwright tests
run: npx playwright test
- name: Run Non-Auth Playwright tests
run: npx playwright test --project=no-auth
- uses: actions/upload-artifact@v3
if: always()
with:
Expand Down
4 changes: 4 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default defineConfig({
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
{
name: "no-auth",
testIgnore: "**/tests/auth/**",
},
/*
{
name: "firefox",
Expand Down
9 changes: 9 additions & 0 deletions tests/auth/tdx/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test } from "../../fixtures";
import { BASE_URL } from "../../../src/config";

test("Can access TDX", async ({ page }) => {
//await page.goto(`https://help.uillinois.edu/SBTDNext`);
await page.goto(BASE_URL);
// todo follow sign-in etc
// and test that actually logged in ok
});
6 changes: 0 additions & 6 deletions tests/chrome-extension-test.spec.ts

This file was deleted.

1 change: 1 addition & 0 deletions tests/options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// todo
28 changes: 28 additions & 0 deletions tests/popup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect } from "./fixtures";
import fs from "fs";
import path from "path";

// get popup page URL
// something like "pages/index.html"
const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "src", "static", "manifest.json"), "utf8"));
const defaultPopupRelativePath = manifest.action.default_popup;
test("Popup page has options button and it opens the options page", async ({ page, extensionId, context }) => {
await page.goto(`chrome-extension://${extensionId}/${defaultPopupRelativePath}`);
await expect(page.locator("button:has-text('Options'), a:has-text('Options')")).toBeVisible();

const prevUrl = page.url();
await page.locator("button:has-text('Options'), a:has-text('Options')").click();
const newTab = await context.waitForEvent("page");
await newTab.waitForLoadState();
expect(newTab.url(), "Should have opened a new tab with a different URL").not.toEqual(prevUrl);
});
test("Popup page has help button and it opens the help page", async ({ page, extensionId, context }) => {
await page.goto(`chrome-extension://${extensionId}/${defaultPopupRelativePath}`);
await expect(page.locator("button:has-text('Help'), a:has-text('Help')")).toBeVisible();

const prevUrl = page.url();
await page.locator("button:has-text('Options'), a:has-text('Options')").click();
const newTab = await context.waitForEvent("page");
await newTab.waitForLoadState();
expect(newTab.url(), "Should have opened a new tab with a different URL").not.toEqual(prevUrl);
});

0 comments on commit c6e974f

Please sign in to comment.