|
| 1 | +import { chromium, Page, Browser, BrowserContext } from "playwright" |
| 2 | + |
| 3 | +// NOTE: this is hard-coded and passed as an environment variable |
| 4 | +// See the test job in ci.yml |
| 5 | +const PASSWORD = "e45432jklfdsab" |
| 6 | + |
| 7 | +describe("login", () => { |
| 8 | + let browser: Browser |
| 9 | + let page: Page |
| 10 | + let context: BrowserContext |
| 11 | + |
| 12 | + beforeAll(async () => { |
| 13 | + browser = await chromium.launch({ headless: false }) |
| 14 | + context = await browser.newContext() |
| 15 | + }) |
| 16 | + |
| 17 | + afterAll(async () => { |
| 18 | + await browser.close() |
| 19 | + }) |
| 20 | + |
| 21 | + beforeEach(async () => { |
| 22 | + page = await context.newPage() |
| 23 | + }) |
| 24 | + |
| 25 | + afterEach(async () => { |
| 26 | + await page.close() |
| 27 | + // Remove password from local storage |
| 28 | + await context.clearCookies() |
| 29 | + }) |
| 30 | + |
| 31 | + it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => { |
| 32 | + await page.goto("http://localhost:8080") |
| 33 | + // Type in password |
| 34 | + await page.fill(".password", PASSWORD) |
| 35 | + // Click the submit button and login |
| 36 | + await page.click(".submit") |
| 37 | + // Click the Applicaiton menu |
| 38 | + await page.click(".menubar-menu-button[title='Application Menu']") |
| 39 | + // See the Go Home button |
| 40 | + const goHomeButton = ".home-bar[aria-label='Home'] li" |
| 41 | + expect(await page.isVisible(goHomeButton)) |
| 42 | + // Hover over element without clicking |
| 43 | + await page.hover(goHomeButton) |
| 44 | + // Click the top left corner of the element |
| 45 | + await page.click(goHomeButton) |
| 46 | + // Note: we have to click on <li> in the Go Home button for it to work |
| 47 | + // Land on coder.com |
| 48 | + // expect(await page.url()).toBe("https://coder.com/") |
| 49 | + }) |
| 50 | +}) |
0 commit comments