-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add Playwright end-to-end tests
- Loading branch information
Showing
9 changed files
with
774 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- playwright | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test, expect } from './fixtures'; | ||
|
||
test.beforeEach(async ({ page, extensionId }, _testInfo) => { | ||
await page.goto(`chrome-extension://${extensionId}/treetop.html`); | ||
|
||
await page.evaluate(async () => { | ||
await chrome.bookmarks.create({ | ||
parentId: '1', | ||
url: 'https://github.com', | ||
title: 'GitHub', | ||
}); | ||
await chrome.bookmarks.create({ | ||
parentId: '2', | ||
url: 'https://gitlab.com', | ||
title: 'GitLab', | ||
}); | ||
}); | ||
}); | ||
|
||
test('existing bookmarks', async ({ page }) => { | ||
const rootFolder = page.locator('.folder').first(); | ||
const bookmarksBarContents = rootFolder.locator('.folder > .contents').nth(0); | ||
await expect(bookmarksBarContents).toHaveCount(1); | ||
expect( | ||
bookmarksBarContents.getByRole('link', { name: 'GitHub' }), | ||
).toBeVisible(); | ||
|
||
const otherBookmarksContents = rootFolder | ||
.locator('.folder > .contents') | ||
.nth(1); | ||
await expect(otherBookmarksContents).toHaveCount(1); | ||
expect( | ||
otherBookmarksContents.getByRole('link', { name: 'GitLab' }), | ||
).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test, expect } from './fixtures'; | ||
|
||
test.beforeEach(async ({ page, extensionId }, _testInfo) => { | ||
await page.goto(`chrome-extension://${extensionId}/treetop.html`); | ||
}); | ||
|
||
test('page header', async ({ page }) => { | ||
const banner = page.getByRole('banner'); | ||
await expect(banner.locator('.treetop')).toHaveText('Treetop'); | ||
await expect(banner.getByRole('textbox')).toBeVisible(); | ||
await expect(banner.getByRole('textbox')).toHaveText(''); | ||
await expect(banner.getByRole('button')).toHaveText(/settings/i); | ||
}); | ||
|
||
test('default bookmarks', async ({ page }) => { | ||
// Root folder | ||
const rootFolder = page.locator('.folder').first(); | ||
await expect(rootFolder.locator('.heading').first()).toHaveText('Bookmarks'); | ||
|
||
// Bookmarks bar | ||
const bookmarksBar = rootFolder.locator('.folder > .heading').nth(0); | ||
const bookmarksBarContents = rootFolder.locator('.folder > .contents').nth(0); | ||
|
||
await expect(bookmarksBar).toHaveText('Bookmarks bar'); | ||
await expect(bookmarksBarContents).toHaveText('Empty folder'); | ||
|
||
// Other bookmarks | ||
const otherBookmarks = rootFolder.locator('.folder > .heading').nth(1); | ||
const otherBookmarksContents = rootFolder | ||
.locator('.folder > .contents') | ||
.nth(1); | ||
|
||
await expect(otherBookmarks).toHaveText('Other bookmarks'); | ||
await expect(otherBookmarksContents).toHaveText('Empty folder'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { test as base, chromium, type BrowserContext } from '@playwright/test'; | ||
import path from 'path'; | ||
|
||
export const test = base.extend<{ | ||
context: BrowserContext; | ||
extensionId: string; | ||
}>({ | ||
context: async ({}, use) => { | ||
const pathToExtension = './dist/chrome'; | ||
const context = await chromium.launchPersistentContext('', { | ||
headless: false, | ||
args: [ | ||
// `--headless=new`, | ||
`--disable-extensions-except=${pathToExtension}`, | ||
`--load-extension=${pathToExtension}`, | ||
], | ||
}); | ||
await use(context); | ||
await context.close(); | ||
}, | ||
extensionId: async ({ context }, use) => { | ||
let [background] = context.serviceWorkers(); | ||
if (!background) { | ||
background = await context.waitForEvent('serviceworker'); | ||
} | ||
|
||
const extensionId = background.url().split('/')[2]; | ||
await use(extensionId); | ||
}, | ||
}); | ||
|
||
export const expect = test.expect; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.