-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: standardise multiremote and standalone e2es across examples
- Loading branch information
1 parent
f2af201
commit f90d032
Showing
10 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { browser } from 'wdio-electron-service'; | ||
import { multiremotebrowser, expect } from '@wdio/globals'; | ||
|
||
const { name, version } = globalThis.packageJson; | ||
|
||
describe('Electron APIs using Multiremote', () => { | ||
it('should retrieve app metadata through the electron API', async () => { | ||
const appName = await browser.electron.execute((electron) => electron.app.getName()); | ||
expect(appName).toStrictEqual([name, name]); | ||
const appVersion = await browser.electron.execute((electron) => electron.app.getVersion()); | ||
expect(appVersion).toStrictEqual([version, version]); | ||
}); | ||
|
||
it('should retrieve instance-specific values from a single instance', async () => { | ||
const browserA = multiremotebrowser.getInstance('browserA'); | ||
expect(await browserA.electron.execute(() => process.argv.includes('--browser=A'))).toBe(true); | ||
expect(await browserA.electron.execute(() => process.argv.includes('--browser=B'))).toBe(false); | ||
const browserB = multiremotebrowser.getInstance('browserB'); | ||
expect(await browserB.electron.execute(() => process.argv.includes('--browser=A'))).toBe(false); | ||
expect(await browserB.electron.execute(() => process.argv.includes('--browser=B'))).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import process from 'node:process'; | ||
|
||
import { startSession } from 'wdio-electron-service'; | ||
import type { PackageJson } from 'read-package-up'; | ||
|
||
const packageJson = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, '..', 'package.json'), { encoding: 'utf-8' }), | ||
) as PackageJson; | ||
|
||
const getBinaryExtension = () => { | ||
if (process.platform === 'darwin') { | ||
return '.app/Contents/MacOS/wdio-electron-service-example'; | ||
} else if (process.platform === 'win32') { | ||
return '.exe'; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
const getBinaryPath = (packageName: string) => | ||
`./out/${packageName}-${process.platform}-${process.arch}/${packageName}${getBinaryExtension()}`; | ||
|
||
async function init() { | ||
const browser = await startSession({ | ||
appBinaryPath: getBinaryPath('wdio-electron-service-example'), | ||
appArgs: ['foo', 'bar=baz'], | ||
}); | ||
|
||
const appName = await browser.electron.execute((electron) => electron.app.getName()); | ||
if (appName !== packageJson.name) { | ||
throw new Error(`appName test failed: ${appName} !== ${packageJson.name}`); | ||
} | ||
|
||
const appVersion = await browser.electron.execute((electron) => electron.app.getVersion()); | ||
if (appVersion !== packageJson.version) { | ||
throw new Error(`appVersion test failed: ${appVersion} !== ${packageJson.version}`); | ||
} | ||
|
||
process.exit(); | ||
} | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import type { PackageJson } from 'read-package-up'; | ||
import type { Options } from '@wdio/types'; | ||
|
||
const packageJson = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, 'package.json'), { encoding: 'utf-8' }), | ||
) as PackageJson; | ||
|
||
globalThis.packageJson = packageJson; | ||
process.env.TEST = 'true'; | ||
|
||
export const config: Options.Testrunner = { | ||
services: ['electron'], | ||
waitforTimeout: 5000, | ||
connectionRetryCount: 10, | ||
connectionRetryTimeout: 30000, | ||
logLevel: 'debug', | ||
runner: 'local', | ||
autoCompileOpts: { | ||
autoCompile: true, | ||
tsNodeOpts: { | ||
transpileOnly: true, | ||
project: path.join(__dirname, 'tsconfig.json'), | ||
}, | ||
}, | ||
framework: 'mocha', | ||
mochaOpts: { | ||
ui: 'bdd', | ||
timeout: 30000, | ||
}, | ||
outputDir: 'wdio-multiremote-logs', | ||
specs: ['./e2e-multiremote/*.ts'], | ||
capabilities: { | ||
browserA: { | ||
capabilities: { | ||
'browserName': 'electron', | ||
'wdio:electronServiceOptions': { | ||
appArgs: ['browser=A'], | ||
}, | ||
} as WebdriverIO.Capabilities, | ||
}, | ||
browserB: { | ||
capabilities: { | ||
'browserName': 'electron', | ||
'wdio:electronServiceOptions': { | ||
appArgs: ['browser=B'], | ||
}, | ||
} as WebdriverIO.Capabilities, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { browser } from 'wdio-electron-service'; | ||
import { multiremotebrowser, expect } from '@wdio/globals'; | ||
|
||
const { name, version } = globalThis.packageJson; | ||
|
||
describe('Electron APIs using Multiremote', () => { | ||
it('should retrieve app metadata through the electron API', async () => { | ||
const appName = await browser.electron.execute((electron) => electron.app.getName()); | ||
expect(appName).toStrictEqual([name, name]); | ||
const appVersion = await browser.electron.execute((electron) => electron.app.getVersion()); | ||
expect(appVersion).toStrictEqual([version, version]); | ||
}); | ||
|
||
it('should retrieve instance-specific values from a single instance', async () => { | ||
const browserA = multiremotebrowser.getInstance('browserA'); | ||
expect(await browserA.electron.execute(() => process.argv.includes('--browser=A'))).toBe(true); | ||
expect(await browserA.electron.execute(() => process.argv.includes('--browser=B'))).toBe(false); | ||
const browserB = multiremotebrowser.getInstance('browserB'); | ||
expect(await browserB.electron.execute(() => process.argv.includes('--browser=A'))).toBe(false); | ||
expect(await browserB.electron.execute(() => process.argv.includes('--browser=B'))).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import url from 'node:url'; | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import process from 'node:process'; | ||
|
||
import { startSession } from 'wdio-electron-service'; | ||
import type { PackageJson } from 'read-package-up'; | ||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
const packageJson = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, '..', 'package.json'), { encoding: 'utf-8' }), | ||
) as PackageJson; | ||
|
||
const getBinaryExtension = () => { | ||
if (process.platform === 'darwin') { | ||
return '.app/Contents/MacOS/wdio-electron-service-example'; | ||
} else if (process.platform === 'win32') { | ||
return '.exe'; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
const getBinaryPath = (packageName: string) => | ||
`./out/${packageName}-${process.platform}-${process.arch}/${packageName}${getBinaryExtension()}`; | ||
|
||
const browser = await startSession({ | ||
appBinaryPath: getBinaryPath('wdio-electron-service-example'), | ||
appArgs: ['foo', 'bar=baz'], | ||
}); | ||
|
||
const appName = await browser.electron.execute((electron) => electron.app.getName()); | ||
if (appName !== packageJson.name) { | ||
throw new Error(`appName test failed: ${appName} !== ${packageJson.name}`); | ||
} | ||
|
||
const appVersion = await browser.electron.execute((electron) => electron.app.getVersion()); | ||
if (appVersion !== packageJson.version) { | ||
throw new Error(`appVersion test failed: ${appVersion} !== ${packageJson.version}`); | ||
} | ||
|
||
process.exit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Options } from '@wdio/types'; | ||
import { config as baseConfig } from './wdio.conf.js'; | ||
|
||
export const config: Options.Testrunner = { | ||
...baseConfig, | ||
outputDir: 'wdio-multiremote-logs', | ||
specs: ['./e2e-multiremote/*.ts'], | ||
capabilities: { | ||
browserA: { | ||
capabilities: { | ||
'browserName': 'electron', | ||
'wdio:electronServiceOptions': { | ||
appArgs: ['browser=A'], | ||
}, | ||
} as WebdriverIO.Capabilities, | ||
}, | ||
browserB: { | ||
capabilities: { | ||
'browserName': 'electron', | ||
'wdio:electronServiceOptions': { | ||
appArgs: ['browser=B'], | ||
}, | ||
} as WebdriverIO.Capabilities, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters