|
| 1 | +import { chromium, Page, Browser, BrowserContext } from "playwright" |
| 2 | +import { CODE_SERVER_ADDRESS, PASSWORD, E2E_VIDEO_DIR } from "../utils/constants" |
| 3 | + |
| 4 | +describe("logout", () => { |
| 5 | + let browser: Browser |
| 6 | + let page: Page |
| 7 | + let context: BrowserContext |
| 8 | + |
| 9 | + beforeAll(async () => { |
| 10 | + browser = await chromium.launch({ headless: false }) |
| 11 | + context = await browser.newContext({ |
| 12 | + recordVideo: { dir: E2E_VIDEO_DIR }, |
| 13 | + }) |
| 14 | + }) |
| 15 | + |
| 16 | + afterAll(async () => { |
| 17 | + await browser.close() |
| 18 | + }) |
| 19 | + |
| 20 | + beforeEach(async () => { |
| 21 | + page = await context.newPage() |
| 22 | + }) |
| 23 | + |
| 24 | + afterEach(async () => { |
| 25 | + await page.close() |
| 26 | + // Remove password from local storage |
| 27 | + await context.clearCookies() |
| 28 | + }) |
| 29 | + |
| 30 | + it("should be able login and logout", async () => { |
| 31 | + await page.goto(CODE_SERVER_ADDRESS) |
| 32 | + // Type in password |
| 33 | + await page.fill(".password", PASSWORD) |
| 34 | + // Click the submit button and login |
| 35 | + await page.click(".submit") |
| 36 | + // See the editor |
| 37 | + const codeServerEditor = await page.isVisible(".monaco-workbench") |
| 38 | + expect(codeServerEditor).toBeTruthy() |
| 39 | + |
| 40 | + // Click the Application menu |
| 41 | + await page.click("[aria-label='Application Menu']") |
| 42 | + |
| 43 | + // See the Log out button |
| 44 | + const logoutButton = "a.action-menu-item span[aria-label='Log out']" |
| 45 | + expect(await page.isVisible(logoutButton)) |
| 46 | + |
| 47 | + await page.hover(logoutButton) |
| 48 | + await page.click(logoutButton) |
| 49 | + |
| 50 | + const currentUrl = await page.url() |
| 51 | + expect(currentUrl).toBe(`${CODE_SERVER_ADDRESS}/login`) |
| 52 | + }) |
| 53 | +}) |
0 commit comments