-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial E2E test framework for v2 (#288)
This brings an initial E2E test (really, an integration test - it's only running the server locally, as opposed to against a deployment - but it'd be easy to point playwright to a deployment). Demo gif: ![test2](https://user-images.githubusercontent.com/88213859/156078517-6cb4ef84-337b-4e16-a8bc-aea7d06dcbcb.gif) This test exercises a minimal flow for login: - Run the `coderd` binary to start a server on 3000 - Create an initial user as part of setup - Go through the login flow and verify we land on the projects page It will be useful to have to ensure that #360 doesn't introduce a regression in the login flow Future E2E tests that would be useful: - Create a project & verify it shows in the UI - Create a workspace and verify it shows in the UI
- Loading branch information
1 parent
2b0f471
commit 86994da
Showing
16 changed files
with
559 additions
and
40 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 |
---|---|---|
|
@@ -7,4 +7,4 @@ out | |
coverage | ||
.next | ||
storybook-static | ||
test_results | ||
test-results |
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 |
---|---|---|
|
@@ -15,4 +15,4 @@ yarn-error.log | |
coverage/ | ||
out/ | ||
storybook-static/ | ||
test_results/ | ||
test-results/ |
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,5 @@ | ||
// Default credentials and user for running tests | ||
export const username = "admin" | ||
export const password = "password" | ||
export const organization = "acme-crop" | ||
export const email = "admin@coder.com" |
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,24 @@ | ||
import { FullConfig, request } from "@playwright/test" | ||
import { email, username, password, organization } from "./constants" | ||
|
||
const globalSetup = async (config: FullConfig): Promise<void> => { | ||
// Grab the 'baseURL' from the webserver (`coderd`) | ||
const { baseURL } = config.projects[0].use | ||
|
||
// Create a context that will issue http requests. | ||
const context = await request.newContext({ | ||
baseURL, | ||
}) | ||
|
||
// Create initial user | ||
await context.post("/api/v2/user", { | ||
data: { | ||
email, | ||
username, | ||
password, | ||
organization, | ||
}, | ||
}) | ||
} | ||
|
||
export default globalSetup |
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,27 @@ | ||
import * as path from "path" | ||
import { PlaywrightTestConfig } from "@playwright/test" | ||
|
||
const config: PlaywrightTestConfig = { | ||
testDir: "tests", | ||
globalSetup: require.resolve("./globalSetup"), | ||
|
||
// Create junit report file for upload to DataDog | ||
reporter: [["junit", { outputFile: "test-results/junit.xml" }]], | ||
|
||
use: { | ||
baseURL: "http://localhost:3000", | ||
video: "retain-on-failure", | ||
}, | ||
|
||
// `webServer` tells Playwright to launch a test server - more details here: | ||
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests | ||
webServer: { | ||
// Run the 'coderd' binary directly | ||
command: path.join(__dirname, "../../bin/coderd"), | ||
port: 3000, | ||
timeout: 120 * 10000, | ||
reuseExistingServer: false, | ||
}, | ||
} | ||
|
||
export default config |
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,17 @@ | ||
import { Page } from "@playwright/test" | ||
|
||
export abstract class BasePom { | ||
protected readonly baseURL: string | undefined | ||
protected readonly path: string | ||
protected readonly page: Page | ||
|
||
constructor(baseURL: string | undefined, path: string, page: Page) { | ||
this.baseURL = baseURL | ||
this.path = path | ||
this.page = page | ||
} | ||
|
||
get url(): string { | ||
return this.baseURL + this.path | ||
} | ||
} |
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,8 @@ | ||
import { Page } from "@playwright/test" | ||
import { BasePom } from "./BasePom" | ||
|
||
export class ProjectsPage extends BasePom { | ||
constructor(baseURL: string | undefined, page: Page) { | ||
super(baseURL, "/projects", page) | ||
} | ||
} |
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,14 @@ | ||
import { Page } from "@playwright/test" | ||
import { BasePom } from "./BasePom" | ||
|
||
export class SignInPage extends BasePom { | ||
constructor(baseURL: string | undefined, page: Page) { | ||
super(baseURL, "/login", page) | ||
} | ||
|
||
async submitBuiltInAuthentication(email: string, password: string): Promise<void> { | ||
await this.page.fill("id=signin-form-inpt-email", email) | ||
await this.page.fill("id=signin-form-inpt-password", password) | ||
await this.page.click("id=signin-form-submit") | ||
} | ||
} |
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,2 @@ | ||
export * from "./ProjectsPage" | ||
export * from "./SignInPage" |
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,16 @@ | ||
import { test } from "@playwright/test" | ||
import { ProjectsPage, SignInPage } from "../pom" | ||
import { email, password } from "../constants" | ||
|
||
test("Login takes user to /projects", async ({ baseURL, page }) => { | ||
await page.goto(baseURL + "/", { waitUntil: "networkidle" }) | ||
|
||
// Log-in with the default credentials we set up in the development server | ||
const signInPage = new SignInPage(baseURL, page) | ||
await signInPage.submitBuiltInAuthentication(email, password) | ||
|
||
const projectsPage = new ProjectsPage(baseURL, page) | ||
await page.waitForNavigation({ url: projectsPage.url, waitUntil: "networkidle" }) | ||
|
||
await page.waitForSelector("text=Projects") | ||
}) |
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
Oops, something went wrong.