Skip to content

Commit b037fa5

Browse files
committed
playwright: let the UI tests pass with the Rails app
Currently, the Git home page is implemented as a Rails app. For various reasons, this app behaves a bit different than the upcoming Hugo/Pagefind-based home page. Let's document the differences via the UI tests. Let's also make it easy to test against various sites, via the environment variable `PLAYWRIGHT_TEST_URL`. When set, it is used instead of https://git-scm.com/. This enables swift and painless validation of the Hugo/Pagefind site, as it is now easy to augment the Playwright tests to test something on the original Rails app and then to verify without much hassle that the Hugo/Pagefind site behaves the same. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2a3f95e commit b037fa5

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tests/git-scm.spec.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const { test, expect, selectors } = require('@playwright/test')
22

3-
const url = 'https://git.github.io/git-scm.com/'
3+
const url = process.env.PLAYWRIGHT_TEST_URL
4+
? process.env.PLAYWRIGHT_TEST_URL.replace(/[^/]$/, '$&/')
5+
: 'https://git-scm.com/'
6+
const isRailsApp = url === 'https://git-scm.com/'
47

58
async function pretendPlatform(page, browserName, userAgent, platform) {
69
if (browserName !== 'chromium') {
@@ -97,11 +100,19 @@ test('search', async ({ page }) => {
97100
await page.goto(`${url}docs/git-commit/fr`)
98101
await searchBox.fill('add')
99102
await searchBox.press('Shift')
100-
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
103+
if (isRailsApp) {
104+
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add$/)
105+
} else {
106+
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
107+
}
101108

102109
// pressing the Enter key should navigate to the full search results page
103110
await searchBox.press('Enter')
104-
await expect(page).toHaveURL(/\/search.*language=fr/)
111+
if (isRailsApp) {
112+
await expect(page).toHaveURL(/\/search/)
113+
} else {
114+
await expect(page).toHaveURL(/\/search.*language=fr/)
115+
}
105116
})
106117

107118
test('manual pages', async ({ page }) => {
@@ -115,7 +126,11 @@ test('manual pages', async ({ page }) => {
115126
// Verify that the drop-downs are shown when clicked
116127
const previousVersionDropdown = page.locator('#previous-versions-dropdown')
117128
await expect(previousVersionDropdown).toBeHidden()
118-
await page.getByRole('link', { name: 'Latest version' }).click()
129+
if (isRailsApp) {
130+
await page.getByRole('link', { name: /Version \d+\.\d+\.\d+/ }).click()
131+
} else {
132+
await page.getByRole('link', { name: 'Latest version' }).click()
133+
}
119134
await expect(previousVersionDropdown).toBeVisible()
120135

121136
const topicsDropdown = page.locator('#topics-dropdown')

0 commit comments

Comments
 (0)