-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3133 from cdr/jsjoeio/migrate-to-playwright-test
refactor(testing): migrate to playwright-test from jest-playwright
- Loading branch information
Showing
13 changed files
with
1,294 additions
and
731 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
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
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,73 @@ | ||
import { | ||
ChromiumEnv, | ||
FirefoxEnv, | ||
WebKitEnv, | ||
test, | ||
setConfig, | ||
PlaywrightOptions, | ||
Config, | ||
globalSetup, | ||
} from "@playwright/test" | ||
import * as crypto from "crypto" | ||
import path from "path" | ||
import { PASSWORD } from "./utils/constants" | ||
import * as wtfnode from "./utils/wtfnode" | ||
|
||
// Playwright doesn't like that ../src/node/util has an enum in it | ||
// so I had to copy hash in separately | ||
const hash = (str: string): string => { | ||
return crypto.createHash("sha256").update(str).digest("hex") | ||
} | ||
|
||
const cookieToStore = { | ||
sameSite: "Lax" as const, | ||
name: "key", | ||
value: hash(PASSWORD), | ||
domain: "localhost", | ||
path: "/", | ||
expires: -1, | ||
httpOnly: false, | ||
secure: false, | ||
} | ||
|
||
globalSetup(async () => { | ||
console.log("\n🚨 Running globalSetup for playwright end-to-end tests") | ||
console.log("👋 Please hang tight...") | ||
|
||
if (process.env.WTF_NODE) { | ||
wtfnode.setup() | ||
} | ||
|
||
const storage = { | ||
cookies: [cookieToStore], | ||
} | ||
|
||
// Save storage state and store as an env variable | ||
// More info: https://playwright.dev/docs/auth?_highlight=authe#reuse-authentication-state | ||
process.env.STORAGE = JSON.stringify(storage) | ||
console.log("✅ globalSetup is now complete.") | ||
}) | ||
|
||
const config: Config = { | ||
testDir: path.join(__dirname, "e2e"), // Search for tests in this directory. | ||
timeout: 30000, // Each test is given 30 seconds. | ||
retries: 3, // Retry failing tests 2 times | ||
} | ||
|
||
if (process.env.CI) { | ||
// In CI, retry failing tests 2 times | ||
// in the event of flakiness | ||
config.retries = 2 | ||
} | ||
|
||
setConfig(config) | ||
|
||
const options: PlaywrightOptions = { | ||
headless: true, // Run tests in headless browsers. | ||
video: "retain-on-failure", | ||
} | ||
|
||
// Run tests in three browsers. | ||
test.runWith(new ChromiumEnv(options), { tag: "chromium" }) | ||
test.runWith(new FirefoxEnv(options), { tag: "firefox" }) | ||
test.runWith(new WebKitEnv(options), { tag: "webkit" }) |
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 |
---|---|---|
@@ -1,35 +1,15 @@ | ||
/// <reference types="jest-playwright-preset" /> | ||
|
||
// This test is for nothing more than to make sure | ||
// tests are running in multiple browsers | ||
describe("Browser gutcheck", () => { | ||
beforeEach(async () => { | ||
await jestPlaywright.resetBrowser({ | ||
logger: { | ||
isEnabled: (name) => name === "browser", | ||
log: (name, severity, message, args) => console.log(`${name} ${message}`), | ||
}, | ||
}) | ||
}) | ||
|
||
test("should display correct browser based on userAgent", async () => { | ||
const displayNames = { | ||
chromium: "Chrome", | ||
firefox: "Firefox", | ||
webkit: "Safari", | ||
} | ||
const userAgent = await page.evaluate("navigator.userAgent") | ||
|
||
if (browserName === "chromium") { | ||
expect(userAgent).toContain(displayNames[browserName]) | ||
} | ||
|
||
if (browserName === "firefox") { | ||
expect(userAgent).toContain(displayNames[browserName]) | ||
} | ||
|
||
if (browserName === "webkit") { | ||
expect(userAgent).toContain(displayNames[browserName]) | ||
} | ||
}) | ||
import { test, expect } from "@playwright/test" | ||
import { CODE_SERVER_ADDRESS } from "../utils/constants" | ||
|
||
// This is a "gut-check" test to make sure playwright is working as expected | ||
test("browser should display correct userAgent", async ({ page, browserName }) => { | ||
const displayNames = { | ||
chromium: "Chrome", | ||
firefox: "Firefox", | ||
webkit: "Safari", | ||
} | ||
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) | ||
const userAgent = await page.evaluate("navigator.userAgent") | ||
|
||
expect(userAgent).toContain(displayNames[browserName]) | ||
}) |
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
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
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 |
---|---|---|
@@ -1,38 +1,46 @@ | ||
/// <reference types="jest-playwright-preset" /> | ||
import { test, expect } from "@playwright/test" | ||
import { CODE_SERVER_ADDRESS, STORAGE } from "../utils/constants" | ||
|
||
describe("Open Help > About", () => { | ||
beforeEach(async () => { | ||
// Create a new context with the saved storage state | ||
// so we don't have to logged in | ||
test.describe("Open Help > About", () => { | ||
// Create a new context with the saved storage state | ||
// so we don't have to logged in | ||
const options: any = {} | ||
// TODO@jsjoeio | ||
// Fix this once https://github.com/microsoft/playwright-test/issues/240 | ||
// is fixed | ||
if (STORAGE) { | ||
const storageState = JSON.parse(STORAGE) || {} | ||
await jestPlaywright.resetContext({ | ||
options.contextOptions = { | ||
storageState, | ||
}) | ||
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) | ||
}) | ||
} | ||
} | ||
|
||
it("should see a 'Help' then 'About' button in the Application Menu that opens a dialog", async () => { | ||
// Make sure the editor actually loaded | ||
expect(await page.isVisible("div.monaco-workbench")) | ||
test( | ||
"should see a 'Help' then 'About' button in the Application Menu that opens a dialog", | ||
options, | ||
async ({ page }) => { | ||
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) | ||
// Make sure the editor actually loaded | ||
expect(await page.isVisible("div.monaco-workbench")) | ||
|
||
// Click the Application menu | ||
await page.click("[aria-label='Application Menu']") | ||
// See the Help button | ||
const helpButton = "a.action-menu-item span[aria-label='Help']" | ||
expect(await page.isVisible(helpButton)) | ||
// Click the Application menu | ||
await page.click("[aria-label='Application Menu']") | ||
// See the Help button | ||
const helpButton = "a.action-menu-item span[aria-label='Help']" | ||
expect(await page.isVisible(helpButton)) | ||
|
||
// Hover the helpButton | ||
await page.hover(helpButton) | ||
// Hover the helpButton | ||
await page.hover(helpButton) | ||
|
||
// see the About button and click it | ||
const aboutButton = "a.action-menu-item span[aria-label='About']" | ||
expect(await page.isVisible(aboutButton)) | ||
// NOTE: it won't work unless you hover it first | ||
await page.hover(aboutButton) | ||
await page.click(aboutButton) | ||
// see the About button and click it | ||
const aboutButton = "a.action-menu-item span[aria-label='About']" | ||
expect(await page.isVisible(aboutButton)) | ||
// NOTE: it won't work unless you hover it first | ||
await page.hover(aboutButton) | ||
await page.click(aboutButton) | ||
|
||
const codeServerText = "text=code-server" | ||
expect(await page.isVisible(codeServerText)) | ||
}) | ||
const codeServerText = "text=code-server" | ||
expect(await page.isVisible(codeServerText)) | ||
}, | ||
) | ||
}) |
Oops, something went wrong.