Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: add e2e tests for basic template and workspace flow #5637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 10, 2023
Merged
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ site/**/*.typegen.ts
site/build-storybook.log
site/coverage/
site/storybook-static/
site/test-results/
site/test-results/*
site/e2e/test-results/*
site/e2e/storageState.json
site/playwright-report/*

# Make target for updating golden files.
cli/testdata/.gen-golden
Expand Down
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ site/**/*.typegen.ts
site/build-storybook.log
site/coverage/
site/storybook-static/
site/test-results/
site/test-results/*
site/e2e/test-results/*
site/e2e/storageState.json
site/playwright-report/*

# Make target for updating golden files.
cli/testdata/.gen-golden
Expand Down
5 changes: 4 additions & 1 deletion site/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ yarn-error.log
build-storybook.log
coverage/
storybook-static/
test-results/
test-results/*
e2e/test-results/*
e2e/storageState.json
playwright-report/*

# Make target for updating golden files.
../cli/testdata/.gen-golden
Expand Down
5 changes: 4 additions & 1 deletion site/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ yarn-error.log
build-storybook.log
coverage/
storybook-static/
test-results/
test-results/*
e2e/test-results/*
e2e/storageState.json
playwright-report/*

# Make target for updating golden files.
../cli/testdata/.gen-golden
Expand Down
3 changes: 2 additions & 1 deletion site/e2e/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import * as constants from "./constants"

const globalSetup = async (): Promise<void> => {
axios.defaults.baseURL = `http://localhost:${constants.basePort}`
// Create a user
await createFirstUser({
email: constants.email,
organization: constants.organization,
username: constants.username,
password: constants.password,
trial: false,
})
}

Expand Down
24 changes: 24 additions & 0 deletions site/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Page } from "@playwright/test"

export const buttons = {
starterTemplates: "Starter templates",
dockerTemplate: "Develop in Docker",
useTemplate: "Use template",
createTemplate: "Create template",
createWorkspace: "Create workspace",
submitCreateWorkspace: "Create workspace",
stopWorkspace: "Stop",
startWorkspace: "Start",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I would decouple this page-specific constant from the test for that page.


export const clickButton = async (page: Page, name: string): Promise<void> => {
await page.getByRole("button", { name, exact: true }).click()
}

export const fillInput = async (
page: Page,
label: string,
value: string,
): Promise<void> => {
await page.fill(`text=${label}`, value)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we made helpers for these? They seem to wrap fairly trivial built-in methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address this comment and the one about the constant: previously, we wrote Playwright tests with POMs, so for each page, you'd have a file with a class and methods. I started doing that here and it felt too heavy since the current plan isn't to write many e2e tests. (Although after seeing how pleasant they were to debug, I'm reconsidering that!) So instead, I just dumped everything I would normally have put in the class into these few helpers. But I agree that it's not that much easier to read and write than just inlining everything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone who isn't familiar with playwright, I appreciate them and makes test-authoring seem a bit easier. No strong opinions though!

40 changes: 40 additions & 0 deletions site/e2e/tests/basicFlow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { test } from "@playwright/test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the file name basicFlow.spec.ts could be more descriptive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we discussed having one long test instead of several short ones since e2e tests tend to build on each other, and so I didn't have something really specific to name it. But again, now that I'm feeling more positive on e2e tests, we should probably talk as a team about whether we want to do more of them.

import { email, password } from "../constants"
import { SignInPage } from "../pom"
import { clickButton, buttons, fillInput } from "../helpers"

test("Basic flow", async ({ baseURL, page }) => {
test.slow()
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)

// create Docker template
await page.waitForSelector("text=Templates")
await page.click("text=Templates")

await clickButton(page, buttons.starterTemplates)

await page.click(`text=${buttons.dockerTemplate}`)

await clickButton(page, buttons.useTemplate)

await clickButton(page, buttons.createTemplate)

// create workspace
await clickButton(page, buttons.createWorkspace)

await fillInput(page, "Workspace Name", "my-workspace")
await clickButton(page, buttons.submitCreateWorkspace)

// stop workspace
await page.waitForSelector("text=Started")
await clickButton(page, buttons.stopWorkspace)

// start workspace
await page.waitForSelector("text=Stopped")
await clickButton(page, buttons.startWorkspace)
await page.waitForSelector("text=Started")
})
13 changes: 0 additions & 13 deletions site/e2e/tests/login.spec.ts

This file was deleted.

3 changes: 2 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"i18next": "21.9.1",
"js-untar": "2.0.0",
"just-debounce-it": "3.1.1",
"playwright": "^1.29.2",
"react": "18.2.0",
"react-chartjs-2": "4.3.1",
"react-color": "2.19.3",
Expand All @@ -81,7 +82,7 @@
"yup": "0.32.11"
},
"devDependencies": {
"@playwright/test": "1.26.1",
"@playwright/test": "1.29.2",
"@storybook/addon-actions": "6.5.9",
"@storybook/addon-essentials": "6.5.12",
"@storybook/addon-links": "6.5.9",
Expand Down
25 changes: 16 additions & 9 deletions site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1921,13 +1921,13 @@
tiny-glob "^0.2.9"
tslib "^2.4.0"

"@playwright/test@1.26.1":
version "1.26.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.26.1.tgz#73ada4e70f618bca69ba7509c4ba65b5a41c4b10"
integrity sha512-bNxyZASVt2adSZ9gbD7NCydzcb5JaI0OR9hc7s+nmPeH604gwp0zp17NNpwXY4c8nvuBGQQ9oGDx72LE+cUWvw==
"@playwright/test@1.29.2":
version "1.29.2"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.29.2.tgz#c48184721d0f0b7627a886e2ec42f1efb2be339d"
integrity sha512-+3/GPwOgcoF0xLz/opTnahel1/y42PdcgZ4hs+BZGIUjtmEFSXGg+nFoaH3NSmuc7a6GSFwXDJ5L7VXpqzigNg==
dependencies:
"@types/node" "*"
playwright-core "1.26.1"
playwright-core "1.29.2"

"@pmmmwh/react-refresh-webpack-plugin@^0.5.3":
version "0.5.9"
Expand Down Expand Up @@ -11326,10 +11326,17 @@ pkg-dir@^5.0.0:
dependencies:
find-up "^5.0.0"

[email protected]:
version "1.26.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.26.1.tgz#a162f476488312dcf12638d97685144de6ada512"
integrity sha512-hzFchhhxnEiPc4qVPs9q2ZR+5eKNifY2hQDHtg1HnTTUuphYCBP8ZRb2si+B1TR7BHirgXaPi48LIye5SgrLAA==
[email protected]:
version "1.29.2"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.29.2.tgz#2e8347e7e8522409f22b244e600e703b64022406"
integrity sha512-94QXm4PMgFoHAhlCuoWyaBYKb92yOcGVHdQLoxQ7Wjlc7Flg4aC/jbFW7xMR52OfXMVkWicue4WXE7QEegbIRA==

playwright@^1.29.2:
version "1.29.2"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.29.2.tgz#d6a0a3e8e44f023f7956ed19ffa8af915a042769"
integrity sha512-hKBYJUtdmYzcjdhYDkP9WGtORwwZBBKAW8+Lz7sr0ZMxtJr04ASXVzH5eBWtDkdb0c3LLFsehfPBTRfvlfKJOA==
dependencies:
playwright-core "1.29.2"

pluralize@^8.0.0:
version "8.0.0"
Expand Down