Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Playwright capture screenshot of Electron desktop app (Jan) on failures #1934

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion electron/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 1,16 @@
import { PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
testDir: './tests',
testDir: './tests/e2e',
retries: 0,
globalTimeout: 300000,
use: {
screenshot: 'only-on-failure',
video: 'retain-on-failure',
trace: 'retain-on-failure',
},

reporter: [['html', { outputFolder: './playwright-report' }]],
}

export default config
34 changes: 34 additions & 0 deletions electron/tests/e2e/hub.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,34 @@
import {
page,
test,
setupElectron,
teardownElectron,
TIMEOUT,
} from '../pages/basePage'
import { expect } from '@playwright/test'

test.beforeAll(async () => {
const appInfo = await setupElectron()
expect(appInfo.asar).toBe(true)
expect(appInfo.executable).toBeTruthy()
expect(appInfo.main).toBeTruthy()
expect(appInfo.name).toBe('jan')
expect(appInfo.packageJson).toBeTruthy()
expect(appInfo.packageJson.name).toBe('jan')
expect(appInfo.platform).toBeTruthy()
expect(appInfo.platform).toBe(process.platform)
expect(appInfo.resourcesDir).toBeTruthy()
})

test.afterAll(async () => {
await teardownElectron()
})

test('explores hub', async () => {
await page.getByTestId('Hub').first().click({
timeout: TIMEOUT,
})
await page.getByTestId('hub-container-test-id').isVisible({
timeout: TIMEOUT,
})
})
38 changes: 38 additions & 0 deletions electron/tests/e2e/navigation.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,38 @@
import { expect } from '@playwright/test'
import {
page,
setupElectron,
TIMEOUT,
test,
teardownElectron,
} from '../pages/basePage'

test.beforeAll(async () => {
await setupElectron()
})

test.afterAll(async () => {
await teardownElectron()
})

test('renders left navigation panel', async () => {
const systemMonitorBtn = await page
.getByTestId('System Monitor')
.first()
.isEnabled({
timeout: TIMEOUT,
})
const settingsBtn = await page
.getByTestId('Thread')
.first()
.isEnabled({ timeout: TIMEOUT })
expect([systemMonitorBtn, settingsBtn].filter((e) => !e).length).toBe(0)
// Chat section should be there
await page.getByTestId('Local API Server').first().click({
timeout: TIMEOUT,
})
const localServer = page.getByTestId('local-server-testid').first()
await expect(localServer).toBeVisible({
timeout: TIMEOUT,
})
})
23 changes: 23 additions & 0 deletions electron/tests/e2e/settings.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
import { expect } from '@playwright/test'

import {
setupElectron,
teardownElectron,
test,
page,
TIMEOUT,
} from '../pages/basePage'

test.beforeAll(async () => {
await setupElectron()
})

test.afterAll(async () => {
await teardownElectron()
})

test('shows settings', async () => {
await page.getByTestId('Settings').first().click({ timeout: TIMEOUT })
const settingDescription = page.getByTestId('testid-setting-description')
await expect(settingDescription).toBeVisible({ timeout: TIMEOUT })
})
48 changes: 0 additions & 48 deletions electron/tests/hub.e2e.spec.ts

This file was deleted.

61 changes: 0 additions & 61 deletions electron/tests/navigation.e2e.spec.ts

This file was deleted.

67 changes: 67 additions & 0 deletions electron/tests/pages/basePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,67 @@
import {
expect,
test as base,
_electron as electron,
ElectronApplication,
Page,
} from '@playwright/test'
import {
findLatestBuild,
parseElectronApp,
stubDialog,
} from 'electron-playwright-helpers'

export const TIMEOUT: number = parseInt(process.env.TEST_TIMEOUT || '300000')

export let electronApp: ElectronApplication
export let page: Page

export async function setupElectron() {
process.env.CI = 'e2e'

const latestBuild = findLatestBuild('dist')
expect(latestBuild).toBeTruthy()

// parse the packaged Electron app and find paths and other info
const appInfo = parseElectronApp(latestBuild)
expect(appInfo).toBeTruthy()

electronApp = await electron.launch({
args: [appInfo.main], // main file from package.json
executablePath: appInfo.executable, // path to the Electron executable
})
await stubDialog(electronApp, 'showMessageBox', { response: 1 })

page = await electronApp.firstWindow({
timeout: TIMEOUT,
})
// Return appInfo for future use
return appInfo
}

export async function teardownElectron() {
await page.close()
await electronApp.close()
}

export const test = base.extend<{
attachScreenshotsToReport: void
}>({
attachScreenshotsToReport: [
async ({ request }, use, testInfo) => {
await use()

// After the test, we can check whether the test passed or failed.
if (testInfo.status !== testInfo.expectedStatus) {
const screenshot = await page.screenshot()
await testInfo.attach('screenshot', {
body: screenshot,
contentType: 'image/png',
})
}
},
{ auto: true },
],
})

test.setTimeout(TIMEOUT)
45 changes: 0 additions & 45 deletions electron/tests/settings.e2e.spec.ts

This file was deleted.

Loading