Skip to content

Commit

Permalink
fixed pages not working in electron
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent T <[email protected]>
  • Loading branch information
vyncent-t committed Aug 7, 2024
1 parent 5152204 commit 48d298f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 29 deletions.
30 changes: 1 addition & 29 deletions app/app-e2e-tests/e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Page, test } from '@playwright/test';
import { expect, test } from '@playwright/test';
import { _electron } from '@playwright/test';
import { spawn } from 'child_process';

Expand Down Expand Up @@ -88,34 +88,6 @@ test('launch app', async () => {
// await window.click('text=Click me');
});

class HeadlampPage {
constructor(private page: Page) {}

async homepage() {
await this.page.goto('http://localhost:3000/');
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForSelector('button');
await this.page.click('button');
}
}

test('launch app w/page', async () => {
// Launch Electron app.
const electronApp = await electron.launch({
cwd: '/home/vtaylor/headlamp/app/electron',
timeout: 0,
args: ['main.js'],
});

// const context = await electronApp.context();
const page = await electronApp.firstWindow();
const headlampPage = new HeadlampPage(page);

electronApp.on('window', async () => {
await headlampPage.homepage();
});
});

test('launch app with integrated shell commands', async () => {
// Start the frontend server
await runCommand('npm', ['start'], { cwd: '/home/vtaylor/headlamp/frontend' });
Expand Down
52 changes: 52 additions & 0 deletions app/app-e2e-tests/e2e/tests/demo-test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { test } from '@playwright/test';
import { _electron } from '@playwright/test';
import { headlampAppPage } from './demo-test';

const electron = _electron;
let electronApp;

test.beforeAll(async () => {
// Launch Electron app.
electronApp = await electron.launch({
cwd: '/home/vtaylor/headlamp/app/electron',
timeout: 0,
args: ['main.js'],
});
});

test('launch app / check homepage', async () => {
// Launch Electron app.

// note: may use .context() instead of .firstWindow()?
// const context = await electronApp.context();

// note: firstWindow returns a page object so we can replace the window object
const page = await electronApp.firstWindow();
const headlampPage = new headlampAppPage(page);

await headlampPage.navHomepage();

electronApp.close();
// electronApp.on('window', async () => {
// await headlampPage.homepage();
// });
});

test('launch app / check notifications', async () => {
// Launch Electron app.
// const electronApp = await electron.launch({
// cwd: '/home/vtaylor/headlamp/app/electron',
// timeout: 0,
// args: ['main.js'],
// });

const page = await electronApp.firstWindow();
const headlampPage = new headlampAppPage(page);

await headlampPage.navNotifactions();

electronApp.close();
// electronApp.on('window', async () => {
// await headlampPage.notifications();
// });
});
23 changes: 23 additions & 0 deletions app/app-e2e-tests/e2e/tests/demo-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, Page } from '@playwright/test';

export class headlampAppPage {
constructor(private page: Page) {}

async navHomepage() {
await this.page.waitForLoadState('domcontentloaded');
await this.page.goto('http://localhost:3000/');

await expect(this.page.getByRole('button', { name: 'Home' })).toBeVisible();
await this.page.getByRole('button', { name: 'Home' }).click();
}

async navNotifactions() {
await this.page.waitForLoadState('domcontentloaded');
await this.page.goto('http://localhost:3000/');

await expect(this.page.getByRole('button', { name: 'Notifications' })).toBeVisible();
await this.page.getByRole('button', { name: 'Notifications' }).click();

await expect(this.page.getByRole('heading', { name: 'Notifications' })).toBeVisible();
}
}
Empty file.
Empty file.

0 comments on commit 48d298f

Please sign in to comment.