Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client-side-js/injectUI5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ async function clientSide_injectUI5(waitForUI5Timeout: number, browserInstance:

// attach new bridge
window.bridge = RecordReplayUi5LocalRef
window.fe_bridge = {} // empty init for fiori elements test api
// Use conditional assignment to avoid overwriting existing fe_bridge (e.g., if re-injecting)
window.fe_bridge = window.fe_bridge || {}
window.wdi5.Log.info("[browser wdi5] APIs injected!")
window.wdi5.isInitialized = true

Expand Down
2 changes: 2 additions & 0 deletions src/client-side-js/testLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ async function loadFELibraries(browserInstance: WebdriverIO.Browser) {
)
}
)
// Ensure fe_bridge exists (defensive check in case browser context was lost)
window.fe_bridge = window.fe_bridge || {}
window.fe_bridge.ListReport = ListReport
window.fe_bridge.ObjectPage = ObjectPage
window.fe_bridge.Shell = Shell
Expand Down
20 changes: 20 additions & 0 deletions src/lib/wdi5-fe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { initOPA, addToQueue, emptyQueue, loadFELibraries } from "../client-side-js/testLibrary.js"
import { checkForUI5Page, injectUI5 } from "./wdi5-bridge.js"
import { Logger as _Logger } from "./Logger.js"
import type { wdi5Config } from "../types/wdi5.types.js"
const Logger = _Logger.getInstance()

const commonFunctions = ["and", "when", "then"]
Expand Down Expand Up @@ -56,6 +58,24 @@ export class WDI5FE {
}

static async initialize(appConfig, browserInstance = browser) {
// Ensure wdi5 bridge is injected before loading FE libraries
// This handles cases where browser context was lost (e.g., due to redirects)
const isUI5Page = await checkForUI5Page(browserInstance)
if (!isUI5Page) {
throw new Error(
"[wdi5] No UI5 page detected. Cannot initialize FE test library. " +
"Make sure you have navigated to a UI5 application before calling browser.fe.initialize()."
)
}

// Check if wdi5 bridge is present, re-inject if needed
const bridgePresent = await browserInstance.execute(() => !!window.bridge && !!window.fe_bridge)
if (!bridgePresent) {
Logger.warn("[wdi5] Browser context lost (possibly due to a redirect). Re-injecting wdi5 bridge...")
const config: wdi5Config = global.__wdi5Config || (browserInstance.options as wdi5Config)
await injectUI5(config, browserInstance)
}

// first magic wand wave -> app context
await loadFELibraries(browserInstance)
await initOPA(appConfig, browserInstance)
Expand Down
Loading