Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timeout from config during late inject #552

Merged
merged 14 commits into from
Nov 15, 2023
3 changes: 2 additions & 1 deletion examples/ui5-js-app/e2e-test-config/wdio-ui5-late.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const merge = require("deepmerge")

const _config = {
wdi5: {
skipInjectUI5OnStart: true
skipInjectUI5OnStart: true,
waitForUI5Timeout: 654321
},
specs: [join("..", "webapp", "test", "e2e", "ui5-late.test.js")],
baseUrl: "https://github.com/ui5-community/wdi5/"
Expand Down
9 changes: 9 additions & 0 deletions examples/ui5-js-app/webapp/test/e2e/ui5-late.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ describe("ui5 basic", () => {
await ui5Service.injectUI5()
})

it("should verify the caching of the wdi5 config", async () => {
// open local app
await browser.url("http://localhost:8888")
// do the late injection
await ui5Service.injectUI5()
// check if config have been cached
expect(__wdi5Config.wdi5.waitForUI5Timeout).toBe(654321)
})

// after late injection, use wdi5 as usual
it("should get a button text via model binding", async () => {
const buttonText = await browser
Expand Down
9 changes: 9 additions & 0 deletions examples/ui5-ts-app/test/e2e/ui5-late.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ describe("late inject wdi5", () => {
await wdi5.injectUI5()
})

it("should verify the caching of the wdi5 config", async () => {
// open local app
await browser.url("http://localhost:8080/index.html")
// do the late injection
await wdi5.injectUI5()
// check if config have been cached properly
expect(__wdi5Config.wdi5.waitForUI5Timeout).toBe(654321)
})

it("wdi5 should subsequently work with UI5 enablement", async () => {
const webcomponentValue = await (
browser.asControl({
Expand Down
2 changes: 1 addition & 1 deletion examples/ui5-ts-app/wdio-ui5-late.conf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config as baseConfig } from "./wdio-ui5.conf.js"

baseConfig.wdi5 = { skipInjectUI5OnStart: true }
baseConfig.wdi5 = { skipInjectUI5OnStart: true, waitForUI5Timeout: 654321 }
baseConfig.specs = ["./test/e2e/ui5-late.test.ts"]
delete baseConfig.exclude
baseConfig.baseUrl = "https://github.com/ui5-community/wdi5/"
Expand Down
6 changes: 5 additions & 1 deletion src/lib/wdi5-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@
* attach the sap/ui/test/RecordReplay object to the application context window object as 'bridge'
*/
export async function injectUI5(config: wdi5Config, browserInstance) {
const waitForUI5Timeout = config.wdi5?.waitForUI5Timeout || 15000
if (config?.wdi5 === undefined) {
nair-sumesh marked this conversation as resolved.
Show resolved Hide resolved
//Fetching config from global variable
config.wdi5 = global.__wdi5Config.wdi5
}
const waitForUI5Timeout = config.wdi5.waitForUI5Timeout || 15000
let result = true

// unify timeouts across Node.js- and browser-scope
Expand Down Expand Up @@ -464,7 +468,7 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
return new Proxy(function () {}, handler)
}
// @ts-ignore

Check warning on line 471 in src/lib/wdi5-bridge.ts

View workflow job for this annotation

GitHub Actions / Run linters

Do not use "@ts-ignore" because it alters compilation errors
return makeFluent(browserInstance._asControl(ui5ControlSelector))
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default class Service implements Services.ServiceInstance {
) {} // the Service is instantiated by wdio with the capabilities and config passed on to

async before(/*capabilities* , specs*/) {
// cache config to global for later use
global.__wdi5Config = this._config
// if no wdi5 config is available we add it manually
if (!this._config.wdi5) {
this._config["wdi5"] = {}
Expand Down Expand Up @@ -90,6 +92,10 @@ export default class Service implements Services.ServiceInstance {
if (await checkForUI5Page(browserInstance)) {
// depending on the scenario (lateInject, multiRemote) we have to access the config differently
const config = this._config ? this._config : browserInstance.options
if (config["wdi5"] === undefined) {
nair-sumesh marked this conversation as resolved.
Show resolved Hide resolved
//Fetching config from global variable
config["wdi5"] = global.__wdi5Config.wdi5
}
await injectUI5(config as wdi5Config, browserInstance)
} else {
throw new Error("wdi5: no UI5 page/app present to work on :(")
Expand Down
Loading