|
| 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 | +}); |
0 commit comments