Skip to content

Commit

Permalink
fix: wait for the injection of wdi5 till the redirection finished (#379)
Browse files Browse the repository at this point in the history
- wait for the injection of wdi5 till the redirection finished
- access the config differently depending on the scenario (latInject, multiRemote)
  • Loading branch information
Siolto authored Nov 24, 2022
1 parent 5f9c375 commit 2cc492e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/lib/wdi5-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ export async function injectUI5(config: wdi5Config, browserInstance) {
return result
}

export async function checkForUI5Page() {
export async function checkForUI5Page(browserInstance) {
// wait till the loading finished and the state is "completed"
await browser.waitUntil(async () => {
const state = await browser.executeAsync((done) => {
await browserInstance.waitUntil(async () => {
const state = await browserInstance.executeAsync((done) => {
done(document.readyState)
})
return state === "complete"
})
// sap in global window namespace denotes (most likely :) ) that ui5 is present
return await browser.executeAsync((done) => {
return await browserInstance.executeAsync((done) => {
done(!!window.sap)
})
}
Expand Down
10 changes: 6 additions & 4 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Service implements Services.ServiceInstance {
await authenticate(this._capabilities[name].capabilities["wdi5:authentication"], name)
}
if (!this._config.wdi5.skipInjectUI5OnStart) {
await injectUI5(this._config as wdi5Config, browser[name])
await this.injectUI5(browser[name])
} else {
Logger.warn("skipped wdi5 injection!")
}
Expand All @@ -40,7 +40,7 @@ export default class Service implements Services.ServiceInstance {
await authenticate(this._capabilities["wdi5:authentication"])
}
if (!this._config.wdi5.skipInjectUI5OnStart) {
await injectUI5(this._config as wdi5Config, browser)
await this.injectUI5(browser)
} else {
Logger.warn("skipped wdi5 injection!")
}
Expand All @@ -53,8 +53,10 @@ export default class Service implements Services.ServiceInstance {
* to the injectUI5 function of the actual wdi5-bridge
*/
async injectUI5(browserInstance = browser) {
if (await checkForUI5Page()) {
await injectUI5(browserInstance.config as wdi5Config, browserInstance)
if (await checkForUI5Page(browserInstance)) {
// depending on the scenario (lateInject, multiRemote) we have to access the config differently
const config = this._config ? this._config : browserInstance.config
await injectUI5(config as wdi5Config, browserInstance)
} else {
throw new Error("wdi5: no UI5 page/app present to work on :(")
}
Expand Down

0 comments on commit 2cc492e

Please sign in to comment.