Skip to content

Commit

Permalink
fix: make lib compatible to WebdriverIO v8 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored Oct 3, 2022
1 parent 9963f3e commit 50035bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ const SIMMERJS = fs
let _config: Partial<Config>

async function injectDOMTestingLibrary(container: ElementBase) {
const shouldInject = await container.execute(function () {
const shouldInject = await container.parent.execute(function () {
return {
domTestingLibrary: !window.TestingLibraryDom,
simmer: !window.Simmer,
}
})

if (shouldInject.domTestingLibrary) {
await container.execute(function (library: string) {
await container.parent.execute(function (library: string) {
// add DOM Testing Library to page as a script tag to support Firefox
if (navigator.userAgent.includes('Firefox')) {
const script = document.createElement('script')
Expand All @@ -68,10 +68,10 @@ async function injectDOMTestingLibrary(container: ElementBase) {
}

if (shouldInject.simmer) {
await container.execute(SIMMERJS)
await container.parent.execute(SIMMERJS)
}

await container.execute(function (config: Config) {
await container.parent.execute(function (config: Config) {
window.TestingLibraryDom.configure(config)
}, _config)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ function createQuery(container: ElementBase, queryName: QueryName) {
await injectDOMTestingLibrary(container)

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const result: SerializedQueryResult = await container.executeAsync(
const result: SerializedQueryResult = await container.parent.executeAsync(
executeQuery,
queryName,
container,
Expand Down
19 changes: 10 additions & 9 deletions src/wdio-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ export type ChainablePromiseElementBase<T> = Promise<T> & {$: $}

export type ElementBase = {
$: $

execute<T>(
script: string | ((...args: any[]) => T),
...args: any[]
): Promise<T>

execute<T>(script: string | ((...args: any[]) => T), ...args: any[]): T

executeAsync(script: string | ((...args: any[]) => void), ...args: any[]): any
parent: {
execute<T>(
script: string | ((...args: any[]) => T),
...args: any[]
): Promise<T>

execute<T>(script: string | ((...args: any[]) => T), ...args: any[]): T

executeAsync(script: string | ((...args: any[]) => void), ...args: any[]): any
}
}

export type BrowserBase = {
Expand Down

0 comments on commit 50035bb

Please sign in to comment.