Skip to content

feat(testing): add e2e test for 'Go Home' button #2648

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 23 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f0b5a57
feat: add playwright
jsjoeio Jan 26, 2021
c2f1a2d
feat: add test for login page
jsjoeio Jan 28, 2021
d7e41a3
fix: increase test timeout to 30000
jsjoeio Jan 28, 2021
3033c8f
feat: add test to visit go home in app menu
jsjoeio Jan 28, 2021
34c6ec4
feat: add globalSetup for testing
jsjoeio Feb 1, 2021
9eba2bd
fix(ci): update test job to use bin
jsjoeio Feb 1, 2021
236717e
fix: update modulePathIgnorePatterns for jest
jsjoeio Feb 1, 2021
ffdbf3a
feat: add test/videos & /screenshots to gitignore
jsjoeio Feb 2, 2021
9e3c8bd
feat: add step to upload test videos
jsjoeio Feb 2, 2021
e077f2d
refactor: update test script to check env var
jsjoeio Feb 4, 2021
b02d2fb
feat: add cookie utils for e2e tests
jsjoeio Feb 4, 2021
2dc56ad
refactor: manually add cookie goHome
jsjoeio Feb 4, 2021
d0eece3
refactor: add note to test.sh about --home
jsjoeio Feb 4, 2021
06af8b3
refactor: update goHome location in test
jsjoeio Feb 11, 2021
38d7718
refactor: use promises for goHome test
jsjoeio Feb 11, 2021
3fa460c
refactor: create helpers.ts & add Cookie
jsjoeio Feb 12, 2021
5857b25
chore: add todo regarding storage and cookies e2e
jsjoeio Feb 12, 2021
b0fd554
refactor: add constants.ts with PASSWORD, etc
jsjoeio Feb 12, 2021
d61bbc4
refactor(goHome): check url, remove timeout
jsjoeio Feb 12, 2021
6d4f814
Close context before browser
code-asher Feb 12, 2021
ef7e727
Fix unreadable wtfnode output
code-asher Feb 12, 2021
6685b3a
Move wtfnode setup to global setup
code-asher Feb 12, 2021
47a05c9
Gate wtfnode behind WTF_NODE env var
code-asher Feb 12, 2021
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
Prev Previous commit
Next Next commit
feat: add test to visit go home in app menu
  • Loading branch information
jsjoeio committed Feb 22, 2021
commit 3033c8f9a23383ad701d3252a0d02315cadc2ef1
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
test:
needs: linux-amd64
runs-on: ubuntu-latest
env:
PASSWORD: e45432jklfdsab
CODE_SERVER_ADDRESS: http://localhost:8080
steps:
- uses: actions/checkout@v1
- name: Download release packages
Expand All @@ -37,7 +40,7 @@ jobs:
- uses: microsoft/playwright-github-action@v1
- name: Install dependencies and run tests
run: |
node ./release-packages/code-server*-linux-amd64 &
node ./release-packages/code-server*-linux-amd64 --home $CODE_SERVER_ADDRESS/healthz &
yarn --frozen-lockfile
yarn test

Expand Down
3 changes: 2 additions & 1 deletion ci/dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ main() {
# information. We must also run it from the root otherwise coverage will not
# include our source files.
cd "$OLDPWD"
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@"
# We use the same environment variables set in ci.yml in the test job
CS_DISABLE_PLUGINS=true PASSWORD=e45432jklfdsab CODE_SERVER_ADDRESS=http://localhost:8080 ./test/node_modules/.bin/jest "$@"
}

main "$@"
47 changes: 31 additions & 16 deletions test/goHome.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { chromium, Page, Browser, BrowserContext } from "playwright"

// NOTE: this is hard-coded and passed as an environment variable
// See the test job in ci.yml
const PASSWORD = "e45432jklfdsab"

describe("login", () => {
let browser: Browser
let page: Page
let context: BrowserContext

beforeAll(async () => {
browser = await chromium.launch({ headless: false })
browser = await chromium.launch()
context = await browser.newContext()
})

afterAll(async () => {
await browser.close()
await context.close()
})

beforeEach(async () => {
Expand All @@ -29,22 +26,40 @@ describe("login", () => {
})

it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
await page.goto("http://localhost:8080")
const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz`
let requestedGoHomeUrl = false
page.on("request", (request) => {
// This ensures that we did make a request to the GO_HOME_URL
// Most reliable way to test button
// because we don't care if the request has a response
// only that it was made
if (request.url() === GO_HOME_URL) {
requestedGoHomeUrl = true
}
})
// waitUntil: "networkidle"
// In case the page takes a long time to load
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "networkidle" })
// Type in password
await page.fill(".password", PASSWORD)
await page.fill(".password", process.env.PASSWORD || "password")
// Click the submit button and login
await page.click(".submit")
// Click the Applicaiton menu
// Click the Application menu
await page.click(".menubar-menu-button[title='Application Menu']")
// See the Go Home button
const goHomeButton = ".home-bar[aria-label='Home'] li"
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
expect(await page.isVisible(goHomeButton))
// Hover over element without clicking
await page.hover(goHomeButton)
// Click the top left corner of the element
await page.click(goHomeButton)
// Note: we have to click on <li> in the Go Home button for it to work
// Land on coder.com
// expect(await page.url()).toBe("https://coder.com/")
// Click it and navigate to coder.com
// NOTE: ran into issues of it failing intermittently
// without having button: "middle"
await page.click(goHomeButton, { button: "middle" })

// If there are unsaved changes it will show a dialog
// asking if you're sure you want to leave
page.on("dialog", (dialog) => dialog.accept())

// We make sure to wait on a request to the GO_HOME_URL
await page.waitForRequest(GO_HOME_URL)
expect(requestedGoHomeUrl).toBeTruthy()
})
})
8 changes: 2 additions & 6 deletions test/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { chromium, Page, Browser, BrowserContext } from "playwright"

// NOTE: this is hard-coded and passed as an environment variable
// See the test job in ci.yml
const PASSWORD = "e45432jklfdsab"

describe("login", () => {
let browser: Browser
let page: Page
Expand All @@ -29,9 +25,9 @@ describe("login", () => {
})

it("should be able to login with the password from config.yml", async () => {
await page.goto("http://localhost:8080")
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080")
// Type in password
await page.fill(".password", PASSWORD)
await page.fill(".password", process.env.PASSWORD || "password")
// Click the submit button and login
await page.click(".submit")
// See the editor
Expand Down