Skip to content

Commit

Permalink
fix: timeout from config during late inject (#552)
Browse files Browse the repository at this point in the history
* fix: timeout from config during late inject

* ci: validate late injection config cache

* fix: failing test cases

* fix: failing test cases v2

* ci: dummy change

* ci: failing test cases for ts app

* fix: timeout from config during late inject(ReviewFix)

* fix: timeout from config during late inject(ReviewFix V2)

* chore(pkg-lock): update

* fix: types

---------

Co-authored-by: I060573 <sumesh.nair@sap.com>
Co-authored-by: Volker Buzek <volker.buzek@js-soft.com>
  • Loading branch information
3 people committed Nov 15, 2023
1 parent fe88546 commit 2dc1e08
Show file tree
Hide file tree
Showing 8 changed files with 8,328 additions and 3,190 deletions.
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
11,481 changes: 8,295 additions & 3,186 deletions package-lock.json

Large diffs are not rendered by default.

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 @@ function checkUI5Version(ui5Version: string) {
* 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) {
//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
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"]) {
//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
2 changes: 1 addition & 1 deletion src/types/wdi5.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface wdi5Config extends WebdriverIO.Config {
/**
* the "wdi5" prefix is to comply with W3C standards
*/
export interface wdi5Capabilities extends WebDriver.DesiredCapabilities {
export interface wdi5Capabilities extends WebdriverIO.Capabilities {
"wdi5:authentication"?: BTPAuthenticator | BasicAuthAuthenticator | CustomAuthenticator | Office365Authenticator
}
export interface wdi5MultiRemoteCapability {
Expand Down

0 comments on commit 2dc1e08

Please sign in to comment.