-
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.
- Loading branch information
1 parent
c86ef82
commit f2af201
Showing
3 changed files
with
82 additions
and
44 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,45 @@ | ||
import { Capabilities, Options, Services } from '@wdio/types'; | ||
|
||
export class CJSElectronLauncher { | ||
private instance?: Promise<Services.ServiceInstance>; | ||
|
||
constructor(options: unknown, caps: unknown, config: Options.Testrunner) { | ||
this.instance = (async () => { | ||
const importPath = '../service.js'; | ||
const { default: ElectronService } = await import(importPath); | ||
return new ElectronService(options, caps, config); | ||
})(); | ||
} | ||
|
||
async onPrepare(config: Options.Testrunner, capabilities: Capabilities.RemoteCapabilities) { | ||
const instance = await this.instance; | ||
return instance?.onPrepare?.(config, capabilities); | ||
} | ||
} | ||
|
||
export class CJSElectronService { | ||
private instance?: Promise<Services.ServiceInstance>; | ||
|
||
constructor(globalOptions: unknown) { | ||
this.instance = (async () => { | ||
const importPath = '../service.js'; | ||
const { default: ElectronService } = await import(importPath); | ||
return new ElectronService(globalOptions); | ||
})(); | ||
} | ||
|
||
async beforeSession( | ||
config: Options.Testrunner, | ||
capabilities: WebdriverIO.Capabilities, | ||
specs: string[], | ||
cid: string, | ||
) { | ||
const instance = await this.instance; | ||
return instance?.beforeSession?.(config, capabilities, specs, cid); | ||
} | ||
|
||
async before(capabilities: WebdriverIO.Capabilities, specs: string[], browser: WebdriverIO.Browser) { | ||
const instance = await this.instance; | ||
return instance?.before?.(capabilities, specs, browser); | ||
} | ||
} |
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,32 @@ | ||
import { remote } from 'webdriverio'; | ||
|
||
import { CJSElectronLauncher, CJSElectronService } from './classes.js'; | ||
import { CUSTOM_CAPABILITY_NAME } from './constants.js'; | ||
import { ElectronServiceOptions } from './types.js'; | ||
import { Options } from '@wdio/types'; | ||
|
||
export async function init(opts: ElectronServiceOptions) { | ||
const testRunnerOpts = { ...opts } as Options.Testrunner; | ||
let capabilities = { | ||
browserName: 'electron', | ||
[CUSTOM_CAPABILITY_NAME]: { | ||
...opts, | ||
}, | ||
}; | ||
|
||
const launcher = new CJSElectronLauncher(opts, capabilities, testRunnerOpts); | ||
const service = new CJSElectronService(opts); | ||
|
||
await launcher.onPrepare(testRunnerOpts, [capabilities]); | ||
|
||
console.log('setting caps', capabilities); | ||
|
||
// initialise session | ||
const browser = await remote({ | ||
capabilities, | ||
}); | ||
|
||
await service.before(capabilities, [], browser); | ||
|
||
return browser; | ||
} |