Skip to content

Commit

Permalink
test: use a page object model paradigm
Browse files Browse the repository at this point in the history
  • Loading branch information
rjaegers committed Jul 31, 2024
1 parent ba0f5c7 commit 577ea70
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/cpp/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
30 changes: 30 additions & 0 deletions .devcontainer/cpp/e2e/tests/codespace.pom.ts
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
10 changes: 8 additions & 2 deletions .devcontainer/cpp/e2e/tests/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 577ea70

Please sign in to comment.