Skip to content

Commit 064ac2f

Browse files
committed
WIP: fixes for app e2e
Signed-off-by: Vincent T <[email protected]>
1 parent 41d7722 commit 064ac2f

15 files changed

+969
-35
lines changed

app/app-e2e-tests/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/

app/app-e2e-tests/e2e/example.spec.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
const { _electron: electron } = require('playwright');
4+
5+
// const app = await electron.launch({ args: ['main.js'] });
6+
7+
// app.process().stdout.on('data', (data) => console.log(`stdout: ${data}`));
8+
// app.process().stderr.on('data', (error) => console.log`stderr: ${error}`));
9+
10+
// const electronApp = await electron.launch({ cwd: '/home/vtaylor/headlamp/app/electron', timeout: 0, args: ['main.js'] });
11+
// electronApp.process().stdout.on('data', (data) => console.log(`stdout: ${data}`));
12+
// electronApp.process().stderr.on('data', (error) => console.log(`stderr: ${error}`));
13+
14+
// test('launch app', async () => {
15+
// const electronApp = await _electron.launch({ cwd: '/home/vtaylor/headlamp/app/electron', args: ['main.js'] })
16+
// // close app
17+
// await electronApp.close()
18+
// })
19+
20+
test('launch app', async () => {
21+
// const headlampPage = new HeadlampPage(page);
22+
// Launch Electron app.
23+
const electronApp = await electron.launch({
24+
cwd: '/home/vtaylor/headlamp/app/electron',
25+
timeout: 0,
26+
args: ['main.js'],
27+
});
28+
electronApp.process().stdout.on('data', data => console.log(`stdoutX: ${data}`));
29+
electronApp.process().stderr.on('data', error => console.log(`stderrX: ${error}`));
30+
// Evaluation expression in the Electron context.
31+
// const appPath = await electronApp.evaluate(async (electron) => {
32+
// // This runs in the main Electron process, |electron| parameter
33+
// // here is always the result of the require('electron') in the main
34+
// // app script.
35+
// // return electron.getAppPath();
36+
// });
37+
38+
// Get the first window that the app opens, wait if necessary.
39+
const window = await electronApp.firstWindow();
40+
// await window.goto('https://playwright.dev/');
41+
await window.waitForLoadState('domcontentloaded');
42+
43+
// await window.goto('https://playwright.dev/');
44+
// await window.getByRole('link', { name: 'Get started' }).click();
45+
46+
await window.goto('http://localhost:3000/');
47+
await window.getByRole('button', { name: 'Home' }).click();
48+
49+
// await electronApp.browserWindow(page);
50+
// Print the title.
51+
// console.log(await window.title());
52+
// Capture a screenshot.
53+
// await window.screenshot({ path: 'intro.png' });
54+
55+
// await headlampPage.authenticate();
56+
// await headlampPage.hasNetworkTab();
57+
// Direct Electron console to Node terminal.
58+
window.on('console', console.log);
59+
// Click button.
60+
// await window.click('text=Click me');
61+
});
62+
63+
test('has title', async ({ page }) => {
64+
await page.goto('https://playwright.dev/');
65+
66+
// Expect a title "to contain" a substring.
67+
await expect(page).toHaveTitle(/Playwright/);
68+
});
69+
70+
test('get started link', async ({ page }) => {
71+
await page.goto('https://playwright.dev/');
72+
73+
// Click the get started link.
74+
await page.getByRole('link', { name: 'Get started' }).click();
75+
76+
// Expects page to have a heading with the name of Installation.
77+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
78+
});

app/app-e2e-tests/package-lock.json

+97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app-e2e-tests/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "app-e2e-tests",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"directories": {
6+
"test": "tests"
7+
},
8+
"scripts": {},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"description": "",
13+
"devDependencies": {
14+
"@playwright/test": "^1.45.3",
15+
"@types/node": "^20.14.12"
16+
}
17+
}
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
9+
10+
/**
11+
* See https://playwright.dev/docs/test-configuration.
12+
*/
13+
export default defineConfig({
14+
testDir: './e2e',
15+
timeout: 60000,
16+
expect: {
17+
timeout: 60000,
18+
},
19+
/* Run tests in files in parallel */
20+
fullyParallel: true,
21+
/* Fail the build on CI if you accidentally left test.only in the source code. */
22+
forbidOnly: !!process.env.CI,
23+
/* Retry on CI only */
24+
retries: process.env.CI ? 2 : 0,
25+
/* Opt out of parallel tests on CI. */
26+
workers: process.env.CI ? 1 : undefined,
27+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
28+
reporter: 'html',
29+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
30+
use: {
31+
/* Base URL to use in actions like `await page.goto('/')`. */
32+
// baseURL: 'http://127.0.0.1:3000',
33+
34+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
35+
trace: 'on-first-retry',
36+
headless: false,
37+
launchOptions: { slowMo: 5000 },
38+
},
39+
40+
/* Configure projects for major browsers */
41+
projects: [
42+
{
43+
name: 'chromium',
44+
use: { ...devices['Desktop Chrome'] },
45+
},
46+
47+
// {
48+
// name: 'firefox',
49+
// use: { ...devices['Desktop Firefox'] },
50+
// },
51+
52+
// {
53+
// name: 'webkit',
54+
// use: { ...devices['Desktop Safari'] },
55+
// },
56+
57+
/* Test against mobile viewports. */
58+
// {
59+
// name: 'Mobile Chrome',
60+
// use: { ...devices['Pixel 5'] },
61+
// },
62+
// {
63+
// name: 'Mobile Safari',
64+
// use: { ...devices['iPhone 12'] },
65+
// },
66+
67+
/* Test against branded browsers. */
68+
// {
69+
// name: 'Microsoft Edge',
70+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
71+
// },
72+
// {
73+
// name: 'Google Chrome',
74+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
75+
// },
76+
],
77+
78+
/* Run your local dev server before starting the tests */
79+
// webServer: {
80+
// command: 'npm run start',
81+
// url: 'http://127.0.0.1:3000',
82+
// reuseExistingServer: !process.env.CI,
83+
// },
84+
});

0 commit comments

Comments
 (0)