2022-01-24 09:26:53 +00:00
|
|
|
// Read more about creating fixtures https://playwright.dev/docs/test-fixtures
|
2022-02-10 13:48:32 +00:00
|
|
|
import { ElectronApplication, test as baseTest, TraceMode } from '@playwright/test';
|
|
|
|
import path from 'path';
|
2022-01-24 09:26:53 +00:00
|
|
|
|
|
|
|
import {
|
2022-02-28 15:28:02 +00:00
|
|
|
bundleType,
|
2022-01-24 09:26:53 +00:00
|
|
|
cwd,
|
|
|
|
executablePath,
|
|
|
|
mainPath,
|
|
|
|
randomDataPath,
|
|
|
|
} from './paths';
|
|
|
|
|
|
|
|
interface EnvOptions {
|
|
|
|
INSOMNIA_DATA_PATH: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const test = baseTest.extend<{
|
|
|
|
app: ElectronApplication;
|
|
|
|
}>({
|
2022-02-10 13:48:32 +00:00
|
|
|
app: async ({ playwright, trace }, use, testInfo) => {
|
2022-01-24 09:26:53 +00:00
|
|
|
const options: EnvOptions = {
|
|
|
|
INSOMNIA_DATA_PATH: randomDataPath(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const electronApp = await playwright._electron.launch({
|
|
|
|
cwd,
|
|
|
|
executablePath,
|
2022-02-28 15:28:02 +00:00
|
|
|
args: bundleType() === 'package' ? [] : [mainPath],
|
2022-01-24 09:26:53 +00:00
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
...options,
|
|
|
|
PLAYWRIGHT: 'true',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-02-10 13:48:32 +00:00
|
|
|
const appContext = electronApp.context();
|
|
|
|
const traceMode: TraceMode = typeof trace === 'string' ? trace as TraceMode : trace.mode;
|
|
|
|
|
|
|
|
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
|
|
|
|
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
|
|
|
|
const captureTrace = (traceMode === 'on' || traceMode === 'retain-on-failure' || (traceMode === 'on-first-retry' && testInfo.retry === 1));
|
|
|
|
|
|
|
|
if (captureTrace) {
|
|
|
|
await appContext.tracing.start(traceOptions);
|
|
|
|
}
|
|
|
|
|
2022-01-24 09:26:53 +00:00
|
|
|
await use(electronApp);
|
|
|
|
|
2022-02-10 13:48:32 +00:00
|
|
|
if (captureTrace) {
|
|
|
|
await appContext.tracing.stop({
|
|
|
|
path: path.join(testInfo.outputDir, 'trace.zip'),
|
|
|
|
});
|
2022-01-24 09:26:53 +00:00
|
|
|
}
|
2022-02-10 13:48:32 +00:00
|
|
|
|
|
|
|
await electronApp.close();
|
2022-01-24 09:26:53 +00:00
|
|
|
},
|
|
|
|
page: async ({ app }, use) => {
|
|
|
|
const page = await app.firstWindow();
|
|
|
|
|
2022-03-03 13:42:04 +00:00
|
|
|
await page.waitForLoadState();
|
2022-01-24 09:26:53 +00:00
|
|
|
|
|
|
|
await page.click("text=Don't share usage analytics");
|
|
|
|
|
|
|
|
await use(page);
|
|
|
|
},
|
|
|
|
});
|