-
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.
Merge pull request #521 from webdriverio-community/sm/standalone-utility
(feat): session utility
- Loading branch information
Showing
32 changed files
with
18,554 additions
and
13,577 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 |
---|---|---|
|
@@ -14,31 +14,35 @@ jobs: | |
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macOS-latest] | ||
node-version: [16.x] | ||
node-version: [18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Cache pnpm modules | ||
uses: actions/cache@v3 | ||
uses: actions/cache@v4 | ||
env: | ||
cache-name: cache-pnpm-modules | ||
with: | ||
path: ~/.pnpm-store | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}- | ||
- uses: pnpm/action-setup@v2 | ||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8.10.0 | ||
version: 9.0.6 | ||
run_install: false | ||
- name: Run headless test | ||
uses: coactions/[email protected] | ||
with: | ||
run: pnpm run ci | ||
- name: Run Tests | ||
run: | | ||
if [ "$RUNNER_OS" == "Linux" ]; then | ||
xvfb-run pnpm run ci | ||
else | ||
pnpm run ci | ||
fi | ||
shell: bash | ||
- name: 🐛 Debug Build | ||
uses: stateful/vscode-server-action@v1 | ||
if: failure() | ||
|
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
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,16 @@ | ||
# Standalone Mode | ||
|
||
You can also use the service without the WDIO testrunner, e.g. in a normal Node.js script. | ||
|
||
The `startElectron` method accepts [`ElectronServiceOptions`](./configuration/service-configuration.md#service-options), creates a new WDIO session using your configuration and returns the WebdriverIO browser object: | ||
|
||
```TS | ||
import { startElectron } from 'wdio-electron-service'; | ||
|
||
const browser = await startElectron({ | ||
appBinaryPath: '/path/to/binary', | ||
appArgs: ['foo', 'bar=baz'], | ||
}); | ||
|
||
const appName = await browser.electron.execute((electron) => electron.app.getName()); | ||
``` |
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,50 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import process from 'node:process'; | ||
|
||
import { startElectron } from 'wdio-electron-service'; | ||
import type { PackageJson } from 'read-package-up'; | ||
|
||
process.env.TEST = 'true'; | ||
|
||
const PACKAGE_NAME = 'wdio-electron-service-example-cjs'; | ||
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/${PACKAGE_NAME}`; | ||
} else if (process.platform === 'win32') { | ||
return '.exe'; | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
const getBinaryPath = () => | ||
`./out/${PACKAGE_NAME}-${process.platform}-${process.arch}/${PACKAGE_NAME}${getBinaryExtension()}`; | ||
|
||
async function init() { | ||
const browser = await startElectron({ | ||
appBinaryPath: getBinaryPath(), | ||
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}`); | ||
} | ||
|
||
// Clean up - quit the app | ||
await browser.deleteSession(); | ||
|
||
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
Oops, something went wrong.