From 577ea708f36fcb798397778508332af41e2b3b4c Mon Sep 17 00:00:00 2001 From: Ron <45816308+rjaegers@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:14:36 +0000 Subject: [PATCH] test: use a page object model paradigm --- .devcontainer/cpp/e2e/playwright.config.ts | 3 +- .devcontainer/cpp/e2e/tests/codespace.pom.ts | 30 ++++++++++++++++++++ .devcontainer/cpp/e2e/tests/smoke.spec.ts | 10 +++++-- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .devcontainer/cpp/e2e/tests/codespace.pom.ts diff --git a/.devcontainer/cpp/e2e/playwright.config.ts b/.devcontainer/cpp/e2e/playwright.config.ts index 1ef51015..60b955f6 100644 --- a/.devcontainer/cpp/e2e/playwright.config.ts +++ b/.devcontainer/cpp/e2e/playwright.config.ts @@ -12,12 +12,11 @@ export default defineConfig({ retries: process.env.CI ? 2 : 0, workers: 1, reporter: 'list', - timeout: 2 * 60 * 1000, + timeout: 3 * 60 * 1000, expect: { timeout: 30 * 1000 }, use: { - baseURL: 'https://' + process.env.CODESPACE_NAME + '.github.dev', trace: 'on-first-retry' }, projects: [ diff --git a/.devcontainer/cpp/e2e/tests/codespace.pom.ts b/.devcontainer/cpp/e2e/tests/codespace.pom.ts new file mode 100644 index 00000000..e7568693 --- /dev/null +++ b/.devcontainer/cpp/e2e/tests/codespace.pom.ts @@ -0,0 +1,30 @@ +import { expect, type Locator, type Page } from '@playwright/test'; + +export class CodespacePage { + readonly page: Page; + + constructor(page: Page) { + this.page = page; + } + + async goto() { + await this.page.goto('https://' + process.env.CODESPACE_NAME + '.github.dev'); + } + + async arePluginsActive(plugins: string[]) { + for (const plugin of plugins) { + await expect(this.page.getByRole('tab', { name: plugin })).toBeVisible(); + } + } + + async executeInTerminal(commands: string | string[]) { + let commandsWithExit = Array.isArray(commands) ? [...commands + 'exit'] : [commands, 'exit']; + + await this.page.keyboard.press('Control+Shift+`'); + + for (const command of commandsWithExit) { + await this.page.keyboard.type(command); + await this.page.keyboard.press('Enter'); + } + } +} diff --git a/.devcontainer/cpp/e2e/tests/smoke.spec.ts b/.devcontainer/cpp/e2e/tests/smoke.spec.ts index 48142c0f..da1d6e64 100644 --- a/.devcontainer/cpp/e2e/tests/smoke.spec.ts +++ b/.devcontainer/cpp/e2e/tests/smoke.spec.ts @@ -1,8 +1,14 @@ import { test, expect } from '@playwright/test'; +import { CodespacePage } from './codespace.pom'; + +test.beforeEach(async ({ page }) => { + const codespace = new CodespacePage(page); + await codespace.goto(); + await codespace.arePluginsActive(['Testing', 'SonarLint', 'CMake', 'Live Share', 'GitHub Pull Requests']); + await codespace.executeInTerminal('git clean -fdx'); +}); test('build project', async ({ page }) => { - await page.goto('/'); - await expect(page.getByLabel('host, Build for host')).toBeVisible(); await page.getByRole('button', { name: 'Build the selected target' }).click(); await page.getByLabel('host, Build for host').locator('a').click(); await expect(page.getByText('[build] Build finished with')).toBeVisible();