Skip to content

Commit

Permalink
Better ui-tests timing
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Nov 13, 2024
1 parent 9db60f0 commit c752f37
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions demo/ui-tests/demo.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import { test, expect } from '@playwright/test';

async function inputLine(page, text: string, appendEnter: boolean = true) {
for (const char of text) {
if (char === '\t') {
await page.keyboard.press('Tab');
} else {
await page.keyboard.type(char);
}
await page.waitForTimeout(10);
}
if (appendEnter) {
await page.keyboard.press('Enter');
}
}

test('visual test', async ({ page }) => {
await page.goto('/');

const wait = 100; // milliseconds

await page.locator('div.xterm-screen').click(); // sets focus for keyboard input

await page.keyboard.type('ls'); // avoid timestamps
await page.keyboard.press('Enter');
await inputLine(page, 'ls'); // avoid timestamps
await page.waitForTimeout(wait);

await page.keyboard.type('cp file.txt file2.txt');
await page.keyboard.press('Enter');
await inputLine(page, 'cp file.txt file2.txt');
await page.waitForTimeout(wait);

await page.keyboard.type('ls'); // avoid timestamps
await page.keyboard.press('Enter');
await inputLine(page, 'ls'); // avoid timestamps
await page.waitForTimeout(wait);

await page.keyboard.type('una');
await page.keyboard.press('Tab'); // tab complete command name
await page.keyboard.press('Enter');
await inputLine(page, 'una\t'); // tab complete command name
await page.waitForTimeout(wait);

await page.keyboard.type('grep ember mon');
await page.keyboard.press('Tab'); // tab complete filename
await page.keyboard.press('Enter');
await inputLine(page, 'grep ember mon\t'); // tab complete filename
await page.waitForTimeout(wait);

await page.keyboard.press('Tab'); // list all commands
await inputLine(page, '\t', false); // list all commands
await page.waitForTimeout(wait);

await page.keyboard.type('abc');
await page.keyboard.press('Enter'); // no such command
await inputLine(page, 'abc'); // no such command
await page.waitForTimeout(wait);

await expect(page).toHaveScreenshot();
Expand Down

0 comments on commit c752f37

Please sign in to comment.