Skip to content

Commit

Permalink
test: add e2e scenario related to the window management
Browse files Browse the repository at this point in the history
  • Loading branch information
mato533 committed Dec 30, 2024
1 parent 44bc12d commit dd74e4d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
4 changes: 3 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"test:e2e:no-binary-cjs": "cross-env DEBUG=wdio-electron-service EXAMPLE_DIR=no-binary-cjs pnpm run exec-no-binary",
"test:e2e:no-binary-esm": "cross-env DEBUG=wdio-electron-service EXAMPLE_DIR=no-binary-esm pnpm run exec-no-binary",
"exec": "pnpm run exec:js && pnpm run exec:main && pnpm run exec:multiremote && pnpm run exec:standalone",
"exec-no-binary": "pnpm run exec-no-binary:js && pnpm run exec-no-binary:main && pnpm run exec-no-binary:multiremote && pnpm run exec-no-binary:standalone",
"exec-no-binary": "pnpm run exec-no-binary:js && pnpm run exec-no-binary:main && pnpm run exec-no-binary:multiremote && pnpm run exec-no-binary:standalone && pnpm run exec-no-binary:window && pnpm run exec-no-binary:window:multiremote",
"exec-no-binary:js": "xvfb-maybe wdio run ./wdio.no-binary.conf.js",
"exec-no-binary:main": "xvfb-maybe wdio run ./wdio.no-binary.conf.ts",
"exec-no-binary:window": "cross-env ENABLE_SPLASH_WINDOW=true xvfb-maybe wdio run ./wdio.no-binary.window.conf.ts",
"exec-no-binary:window:multiremote": "cross-env ENABLE_SPLASH_WINDOW=true xvfb-maybe wdio run ./wdio.no-binary.multiremote.conf.ts",
"exec-no-binary:multiremote": "xvfb-maybe wdio run ./wdio.no-binary.multiremote.conf.ts",
"exec-no-binary:standalone": "xvfb-maybe tsx ./test/standalone/api.no-binary.spec.ts",
"exec:js": "xvfb-maybe wdio run ./wdio.conf.js",
Expand Down
18 changes: 18 additions & 0 deletions e2e/test/window/window-multiremote.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { multiremotebrowser, expect } from '@wdio/globals';
describe('application with changing window', () => {
it('should launch the application first screen', async () => {
const browserA = multiremotebrowser.getInstance('browserA');
const browserB = multiremotebrowser.getInstance('browserB');
await expect(browserA).toHaveTitle('Splash window');
await expect(browserB).toHaveTitle('Splash window');
});

it('should launch the application second screen', async () => {
const browserA = multiremotebrowser.getInstance('browserA');
const browserB = multiremotebrowser.getInstance('browserB');
browserA.$('.switch-main-window').click();
browserB.$('.switch-main-window').click();
await expect(browserA).toHaveTitle('Test');
await expect(browserB).toHaveTitle('Test');
});
});
19 changes: 19 additions & 0 deletions e2e/test/window/window.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from '@wdio/globals';
import { browser } from 'wdio-electron-service';

describe('application with changing window', () => {
it('should launch the application first screen', async () => {
const appName = await browser.electron.execute((electron) => electron.app.getName());
console.log(`appName: ${appName}`);
await expect(browser).toHaveTitle('Splash window');
});

it('should launch the application second screen', async () => {
const elem = browser.$('.switch-main-window');
await elem.click();

const appName = await browser.electron.execute((electron) => electron.app.getName());
console.log(`appName: ${appName}`);
await expect(browser).toHaveTitle('Test');
});
});
6 changes: 5 additions & 1 deletion e2e/wdio.no-binary.multiremote.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { config as baseConfig } from './wdio.no-binary.conf.js';
const exampleDir = process.env.EXAMPLE_DIR || 'forge-esm';
const baseServiceOptions = baseConfig.capabilities[0]['wdio:electronServiceOptions'];

const isEnableSplashWindow = !!process.env.ENABLE_SPLASH_WINDOW;

const specs = isEnableSplashWindow ? ['./test/window/window-multiremote.spec.ts'] : ['./test/multiremote/*.spec.ts'];

export const config: WdioElectronConfig = {
...baseConfig,
outputDir: `wdio-logs-multiremote-${exampleDir}`,
specs: ['./test/multiremote/*.spec.ts'],
specs,
capabilities: {
browserA: {
capabilities: {
Expand Down
47 changes: 47 additions & 0 deletions e2e/wdio.no-binary.window.conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import url from 'node:url';
import path from 'node:path';
import fs from 'node:fs';

import type { NormalizedPackageJson } from 'read-package-up';

import { getElectronVersion } from '@wdio/electron-utils';
import type { WdioElectronConfig } from '@wdio/electron-types';

const exampleDir = process.env.EXAMPLE_DIR || 'forge-esm';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const packageJsonPath = path.join(__dirname, '..', 'apps', exampleDir, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf-8' })) as NormalizedPackageJson;
const appEntryPoint = path.join(__dirname, '..', 'apps', exampleDir, 'dist', 'main.bundle.js');

globalThis.packageJson = {
name: 'Electron',
version: getElectronVersion({ packageJson, path: packageJsonPath }) as string,
};
process.env.TEST = 'true';
process.env.ENABLE_SPLASH_WINDOW = 'true';

export const config: WdioElectronConfig = {
services: [['electron', { restoreMocks: true }]],
capabilities: [
{
'browserName': 'electron',
'wdio:electronServiceOptions': {
appEntryPoint,
appArgs: ['foo', 'bar=baz'],
},
},
],
waitforTimeout: 5000,
connectionRetryCount: 10,
connectionRetryTimeout: 30000,
logLevel: 'debug',
runner: 'local',
outputDir: `wdio-logs-${exampleDir}`,
specs: ['./test/window/*.spec.ts'],
tsConfigPath: path.join(__dirname, 'tsconfig.json'),
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
timeout: 30000,
},
};

0 comments on commit dd74e4d

Please sign in to comment.