Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

playwright test structure #64451

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ client/web-sveltekit/node_modules
client/wildcard/node_modules
internal/appliance/frontend/maintenance/node_modules

testing/e2e/node_modules
cmd/symbols/internal/squirrel/test_repos/starlark

# Generated by local tools
Expand Down
11 changes: 0 additions & 11 deletions client/web-sveltekit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,6 @@ compile_app(
visibility = ["//client/web/dist:__pkg__"],
)

playwright_test_bin.playwright_test(
name = "playwright_install",
args = [
"install",
],
local = True,
tags = [
"requires-network",
],
)

PLAYWRIGHT_DEPS = [
"//client/web-sveltekit:node_modules/@playwright/test",
"//client/web-sveltekit:node_modules/playwright",
Expand Down
16 changes: 13 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ packages:
- '!client/cody-context-filters-test-dataset'
- 'schema'
- 'internal/appliance/frontend/maintenance'
- 'testing/e2e'
5 changes: 5 additions & 0 deletions testing/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
64 changes: 64 additions & 0 deletions testing/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//testing/e2e:@playwright/test/package_json.bzl", playwright_test_bin = "bin")

npm_link_all_packages(name = "node_modules")

PLAYWRIGHT_DEPS = [
"//testing/e2e:node_modules/@playwright/test",
"//testing/e2e:node_modules/playwright",
]

playwright_test_bin.playwright_test(
name = "e2e_test",
timeout = "long",
args = [
"test",
"--config $(location playwright.config.ts)",
],
data = glob(
[
"tests/**/*.spec.ts",
],
) + [
"playwright.config.ts",
"//dev/tools:chromium",
] + PLAYWRIGHT_DEPS,
env = {
"CHROMIUM_BIN": "$(rootpath //dev/tools:chromium)",
"BAZEL": "1",
},
tags = [
"manual", # We never want normal CI runs to include this.
"no-cache", # Because those tests are meant to target a real live instance, that lives outside the inputs, there's no point in caching.
"requires-network",
],
)

# This should be a run, but I'm getting weird errors when I try.
# To reproduce, ...bin.playwright_test -> ...bin.playwright_binary and bazel run the target.
playwright_test_bin.playwright_test(
name = "e2e_test_ui",
timeout = "eternal",
args = [
"test",
"--config $(location playwright.config.ts)",
"--ui",
],
data = glob(
[
"tests/**/*.spec.ts",
],
) + [
"playwright.config.ts",
"//dev/tools:chromium",
] + PLAYWRIGHT_DEPS,
env = {
"CHROMIUM_BIN": "$(rootpath //dev/tools:chromium)",
"BAZEL": "1",
},
tags = [
"manual", # We never want normal CI runs to include this.
"no-cache", # Because those tests are meant to target a real live instance, that lives outside the inputs, there's no point in caching.
"requires-network",
],
)
18 changes: 18 additions & 0 deletions testing/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"dependencies": {
"playwright": "1.46.0"
},
"devDependencies": {
"@playwright/test": "1.46.0",
"@types/node": "20.11.19"
}
}
83 changes: 83 additions & 0 deletions testing/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: '.',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
launchOptions: {
// When in CI, use bazel packaged linux chromium
executablePath: process.env.CHROMIUM_BIN,
},
},
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
46 changes: 46 additions & 0 deletions testing/e2e/tests/demo/dotcom.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test, expect } from '@playwright/test'

const baseURL = 'https://sourcegraph.com'

test.describe('search smoke tests', () => {
test.describe('react', () => {
test('has title', async ({ page }) => {
await page.goto(`${baseURL}/search`)
await expect(page).toHaveTitle('Sourcegraph')
})
})

test.describe('svelte', () => {
const useSvelte = 'feat=web-next'
test('has title', async ({ page }) => {
await page.goto(`${baseURL}/search?${useSvelte}`)
await expect(page).toHaveTitle('Sourcegraph')
})

test('navigate to repo via search', async ({ page }) => {
await page.goto(
`${baseURL}/search?${useSvelte}&q=context:global+repo:sgtest/weird&patternType=keyword&sm=0`
)
await page.getByRole('link', { name: 'sgtest/weird' }).click()
await page.waitForURL(`${baseURL}/github.com/sgtest/weird`)
})

test('navigate to repo at a specific branch via search', async ({ page }) => {
await page.goto(
`${baseURL}/search?${useSvelte}&q=context:global+repo:sgtest/weird%40main&patternType=keyword&sm=0`
)
await page.getByRole('link', { name: 'sgtest/weird' }).click()
await page.waitForURL(`${baseURL}/github.com/sgtest/weird@main`)
})

test('navigate to a file via search', async ({ page }) => {
await page.goto(
`${baseURL}/search?${useSvelte}&q=context:global+repo:%5Egithub%5C.com/sgtest/weird%24%40af4f7a3be2ba4be3a1804302f0ff97f56ac8130d+file:ALLCAPS&patternType=keyword&sm=0`
)
await page.getByRole('link', { name: 'ALLCAPS' }).click()
await page.waitForURL(
`${baseURL}/github.com/sgtest/weird@af4f7a3be2ba4be3a1804302f0ff97f56ac8130d/-/blob/filenames/ALLCAPS`
)
})
})
})
18 changes: 18 additions & 0 deletions testing/e2e/tests/demo/playwright-demo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();

// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
1 change: 1 addition & 0 deletions testing/e2e/tests/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BASE_URL = 'https://sourcegraph.com'
Loading