From 3a0445df83f78575e2b54b9b9ae65b1f7829ba60 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Wed, 10 Jan 2024 12:57:47 +0100 Subject: [PATCH 1/9] feat: add option to ignore urls for auto waiting --- client-side-js/injectXHRPatch.cjs | 53 ++ .../e2e-test-config/wdio-ui5tooling.conf.js | 5 +- examples/ui5-js-app/package.json | 3 +- .../ui5-js-app/scripts/delayedMockServer.js | 13 + examples/ui5-js-app/ui5.yaml | 16 + examples/ui5-js-app/webapp/Component.js | 14 + .../webapp/localService/metadata.xml | 720 ++++++++++++++++++ examples/ui5-js-app/webapp/proxyrc.json | 10 +- package-lock.json | 95 ++- src/lib/wdi5-bridge.ts | 2 + 10 files changed, 909 insertions(+), 22 deletions(-) create mode 100644 client-side-js/injectXHRPatch.cjs create mode 100644 examples/ui5-js-app/scripts/delayedMockServer.js create mode 100644 examples/ui5-js-app/webapp/localService/metadata.xml diff --git a/client-side-js/injectXHRPatch.cjs b/client-side-js/injectXHRPatch.cjs new file mode 100644 index 00000000..aaeb5520 --- /dev/null +++ b/client-side-js/injectXHRPatch.cjs @@ -0,0 +1,53 @@ +async function clientSide_injectXHRPatch(config, browserInstance) { + return await browserInstance.executeAsync((config, done) => { + const originalFetch = window.fetch + + const autoWaitUrlIgnoreRegex = config.wdi5.autoWaitUrlIgnoreRegex + function checkURL(url) { + return autoWaitUrlIgnoreRegex?.map((regex) => new RegExp(regex))?.some((regex) => url.match(regex)) || false + } + + //Load the XHRWaiter before our overwrite so we are called first + sap.ui.require( + ["sap/ui/thirdparty/sinon", "sap/ui/test/autowaiter/_XHRWaiter", "sap/ui/test/autowaiter/_fetchWaiter"], + function (sinon, _XHRWaiter, _fetchWaiter) { + // Hook into XHR open for sinon XHRs + const fnOriginalFakeOpen = sinon.FakeXMLHttpRequest.prototype.open + sinon.FakeXMLHttpRequest.prototype.open = function () { + return fnOriginalFakeOpen.apply(this, hooketoXHROpen.apply(this, arguments)) + } + + // Hook into XHR open for regular XHRs + const fnOriginalOpen = XMLHttpRequest.prototype.open + XMLHttpRequest.prototype.open = function () { + return fnOriginalOpen.apply(this, hooketoXHROpen.apply(this, arguments)) + } + + function hooketoXHROpen(method, url, async) { + //The ignore property will force the OPA5 _XHRWaiter to ignore certain calls for auto waiting + //https://github.com/SAP/openui5/blob/45e49887f632d0a8a8ef195bd3edf10eb0be9015/src/sap.ui.core/src/sap/ui/test/autowaiter/_XHRWaiter.js + //This ist the XHR request instance so setting it here will only affect the specific request + this.ignored = checkURL(url) + + return arguments + } + + const sapFetch = window.fetch + + window.fetch = function (resource) { + const url = typeof resource === "object" ? resource.url : resource + if (checkURL(url)) { + return originalFetch.apply(this, arguments) + } else { + return sapFetch.apply(this, arguments) + } + } + done(true) + } + ) + }, config) +} + +module.exports = { + clientSide_injectXHRPatch +} diff --git a/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js b/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js index ecb31aa6..4eedeb20 100644 --- a/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js +++ b/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js @@ -4,7 +4,10 @@ const merge = require("deepmerge") const _config = { specs: [join("..", "webapp", "test", "e2e", "basic.test.js"), join("webapp", "test", "e2e", "hash-nav.test.js")], - baseUrl: "http://localhost:8080/index.html" + baseUrl: "http://localhost:8080/index.html?isui5toolingTest=true", + wdi5: { + autoWaitUrlIgnoreRegex: [".*/Categories.*"] + } } exports.config = merge(baseConfig, _config) diff --git a/examples/ui5-js-app/package.json b/examples/ui5-js-app/package.json index 5cce1415..9f735ef4 100644 --- a/examples/ui5-js-app/package.json +++ b/examples/ui5-js-app/package.json @@ -26,7 +26,8 @@ "@wdio/mocha-framework": "^8", "@wdio/spec-reporter": "^8", "ui5-middleware-simpleproxy": "latest", - "wdio-ui5-service": "*" + "wdio-ui5-service": "*", + "@sap-ux/ui5-middleware-fe-mockserver": "latest" }, "dependencies": { "@wdio/sauce-service": "^8" diff --git a/examples/ui5-js-app/scripts/delayedMockServer.js b/examples/ui5-js-app/scripts/delayedMockServer.js new file mode 100644 index 00000000..10f77987 --- /dev/null +++ b/examples/ui5-js-app/scripts/delayedMockServer.js @@ -0,0 +1,13 @@ +const femiddleware = require("@sap-ux/ui5-middleware-fe-mockserver") + +module.exports = async function middleware(middlewareConfig) { + const feMiddleware = await femiddleware(middlewareConfig) + return async (req, res, next) => { + if (req.originalUrl.startsWith("/V2") && req.originalUrl.includes("/Categories")) { + await new Promise((resolve) => setTimeout(resolve, 1000)) + feMiddleware(req, res, next) + return + } + next() + } +} diff --git a/examples/ui5-js-app/ui5.yaml b/examples/ui5-js-app/ui5.yaml index c9620c53..2499935c 100644 --- a/examples/ui5-js-app/ui5.yaml +++ b/examples/ui5-js-app/ui5.yaml @@ -10,3 +10,19 @@ server: configuration: baseUri: "https://services.odata.org/V2" strictSSL: false + - name: delayed-mockserver + beforeMiddleware: ui5-middleware-simpleproxy + configuration: + service: + urlBasePath: "/V2/Northwind/Northwind.svc" + name: "" + metadataXmlPath: "./webapp/localService/metadata.xml" + generateMockData: true +--- +specVersion: "1.0" +metadata: + name: delayed-mockserver +kind: extension +type: server-middleware +middleware: + path: scripts/delayedMockServer.js diff --git a/examples/ui5-js-app/webapp/Component.js b/examples/ui5-js-app/webapp/Component.js index 49e33a46..9af9c5b7 100644 --- a/examples/ui5-js-app/webapp/Component.js +++ b/examples/ui5-js-app/webapp/Component.js @@ -27,6 +27,20 @@ sap.ui.define( // set the device model this.setModel(models.createDeviceModel(), "device") + + const url = new URL(location.href) + if (url.searchParams.get("isui5toolingTest")?.toLocaleLowerCase() === "true") { + const startXHR = () => { + this.getModel().read("/Categories", { + success: startXHR + }) + } + startXHR() + const startFetch = () => { + fetch("/V2/Northwind/Northwind.svc/Categories").then(startFetch) + } + startFetch() + } } }) } diff --git a/examples/ui5-js-app/webapp/localService/metadata.xml b/examples/ui5-js-app/webapp/localService/metadata.xml new file mode 100644 index 00000000..a4aa7339 --- /dev/null +++ b/examples/ui5-js-app/webapp/localService/metadata.xml @@ -0,0 +1,720 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/ui5-js-app/webapp/proxyrc.json b/examples/ui5-js-app/webapp/proxyrc.json index be36b27a..82ef5867 100644 --- a/examples/ui5-js-app/webapp/proxyrc.json +++ b/examples/ui5-js-app/webapp/proxyrc.json @@ -1,7 +1,7 @@ { - "/V2/": { - "target": "https://services.odata.org/V2/", - "secure": false, - "changeOrigin": true - } + "/V2/": { + "target": "https://services.odata.org/V2/", + "secure": false, + "changeOrigin": true } +} diff --git a/package-lock.json b/package-lock.json index 619c0123..ac293780 100644 --- a/package-lock.json +++ b/package-lock.json @@ -226,6 +226,7 @@ "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -2996,6 +2997,7 @@ "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", + "dev": true, "dependencies": { "eslint-visitor-keys": "^3.3.0" }, @@ -3010,6 +3012,7 @@ "version": "4.10.0", "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", + "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } @@ -3018,6 +3021,7 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.3.tgz", "integrity": "sha512-yZzuIG+jnVu6hNSzFEN07e8BxF3uAzYtQb6uDkaYZLo6oYZDCq454c5kB8zxnzfCYyP4MIuyBn10L0DqwujTmA==", + "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", @@ -3040,6 +3044,7 @@ "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -3054,12 +3059,14 @@ "node_modules/@eslint/eslintrc/node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "node_modules/@eslint/js": { "version": "8.53.0", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.53.0.tgz", "integrity": "sha512-Kn7K8dx/5U6+cT1yEhpX1w4PCSg0M+XyRILPgvwcEBjerFWCwQj5sbr3/VmxqV0JGHCBCzyd6LxypEuehypY1w==", + "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } @@ -3089,6 +3096,7 @@ "version": "0.11.13", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", "integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==", + "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^2.0.1", "debug": "^4.1.1", @@ -3102,6 +3110,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, "engines": { "node": ">=12.22" }, @@ -3113,7 +3122,8 @@ "node_modules/@humanwhocodes/object-schema": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz", - "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==" + "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", + "dev": true }, "node_modules/@hutson/parse-repository-url": { "version": "3.0.2", @@ -3865,6 +3875,7 @@ "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" @@ -3877,6 +3888,7 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, "engines": { "node": ">= 8" } @@ -3885,6 +3897,7 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -15619,7 +15632,8 @@ "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==" + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true }, "node_modules/@wdio/browserstack-service": { "version": "8.22.1", @@ -16163,6 +16177,7 @@ "version": "8.11.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==", + "dev": true, "bin": { "acorn": "bin/acorn" }, @@ -16174,6 +16189,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } @@ -16648,6 +16664,7 @@ "version": "0.27.2", "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "dev": true, "dependencies": { "follow-redirects": "^1.14.9", "form-data": "^4.0.0" @@ -17392,6 +17409,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, "engines": { "node": ">=6" } @@ -19129,7 +19147,8 @@ "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", - "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==" + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true }, "node_modules/deepmerge": { "version": "4.3.1", @@ -19900,6 +19919,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, "dependencies": { "esutils": "^2.0.2" }, @@ -20416,6 +20436,7 @@ "version": "8.53.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.53.0.tgz", "integrity": "sha512-N4VuiPjXDUa4xVeV/GC/RV3hQW9Nw+Y463lkWaKKXKYMvmRiRDAtfpuPFLN+E1/6ZhyR8J2ig+eVREnYgUsiag==", + "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -20511,6 +20532,7 @@ "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", + "dev": true, "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" @@ -20526,6 +20548,7 @@ "version": "3.4.3", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -20537,6 +20560,7 @@ "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -20552,6 +20576,7 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, "dependencies": { "is-glob": "^4.0.3" }, @@ -20562,12 +20587,14 @@ "node_modules/eslint/node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "node_modules/eslint/node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -20579,6 +20606,7 @@ "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "dev": true, "dependencies": { "acorn": "^8.9.0", "acorn-jsx": "^5.3.2", @@ -20607,6 +20635,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "dev": true, "dependencies": { "estraverse": "^5.1.0" }, @@ -20618,6 +20647,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, "dependencies": { "estraverse": "^5.2.0" }, @@ -21046,7 +21076,8 @@ "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true }, "node_modules/fast-diff": { "version": "1.3.0", @@ -21078,12 +21109,14 @@ "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==" + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true }, "node_modules/fast-url-parser": { "version": "1.1.3", @@ -21098,6 +21131,7 @@ "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "dev": true, "dependencies": { "reusify": "^1.0.4" } @@ -21196,6 +21230,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "dev": true, "dependencies": { "flat-cache": "^3.0.4" }, @@ -21351,6 +21386,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", + "dev": true, "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.3", @@ -21364,6 +21400,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -21383,6 +21420,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, "dependencies": { "glob": "^7.1.3" }, @@ -21396,7 +21434,8 @@ "node_modules/flatted": { "version": "3.2.9", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz", - "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==" + "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==", + "dev": true }, "node_modules/flushwritable": { "version": "1.0.0", @@ -22313,6 +22352,7 @@ "version": "13.23.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", + "dev": true, "dependencies": { "type-fest": "^0.20.2" }, @@ -22455,7 +22495,8 @@ "node_modules/graphemer": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", - "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==" + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true }, "node_modules/handlebars": { "version": "4.7.8", @@ -22853,6 +22894,7 @@ "version": "5.2.4", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", + "dev": true, "engines": { "node": ">= 4" } @@ -22882,6 +22924,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -22897,6 +22940,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, "engines": { "node": ">=4" } @@ -22923,6 +22967,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "devOptional": true, "engines": { "node": ">=0.8.19" } @@ -23381,6 +23426,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", + "dev": true, "engines": { "node": ">=8" } @@ -23789,7 +23835,8 @@ "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==" + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true }, "node_modules/json-stringify-safe": { "version": "5.0.1", @@ -23962,6 +24009,7 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" @@ -24306,7 +24354,8 @@ "node_modules/livereload-js": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/livereload-js/-/livereload-js-3.4.1.tgz", - "integrity": "sha512-5MP0uUeVCec89ZbNOT/i97Mc+q3SxXmiUGhRFOTmhrGPn//uWVQdCvcLJDy64MSBR5MidFdOR7B9viumoavy6g==" + "integrity": "sha512-5MP0uUeVCec89ZbNOT/i97Mc+q3SxXmiUGhRFOTmhrGPn//uWVQdCvcLJDy64MSBR5MidFdOR7B9viumoavy6g==", + "dev": true }, "node_modules/load-bmfont": { "version": "1.4.1", @@ -24494,7 +24543,8 @@ "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true }, "node_modules/lodash.mergewith": { "version": "4.6.2", @@ -25844,6 +25894,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/mustache/-/mustache-2.2.1.tgz", "integrity": "sha512-azYRexmi9y6h2lk2JqfBLh1htlDMjKYyEYOkxoGKa0FRdr5aY4f5q8bH4JIecM181DtUEYLSz8PcRO46mgzMNQ==", + "dev": true, "bin": { "mustache": "bin/mustache" }, @@ -25889,7 +25940,8 @@ "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", - "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==" + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true }, "node_modules/negotiator": { "version": "0.6.3", @@ -26576,6 +26628,7 @@ "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", + "dev": true, "dependencies": { "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", @@ -27053,6 +27106,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, "dependencies": { "callsites": "^3.0.0" }, @@ -27379,6 +27433,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, "engines": { "node": ">= 0.8.0" } @@ -27938,6 +27993,7 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, "funding": [ { "type": "github", @@ -28806,6 +28862,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true, "engines": { "iojs": ">=1.0.0", "node": ">=0.10.0" @@ -28906,6 +28963,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, "funding": [ { "type": "github", @@ -30704,7 +30762,8 @@ "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==" + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true }, "node_modules/textextensions": { "version": "5.16.0", @@ -31034,6 +31093,7 @@ "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, "dependencies": { "prelude-ls": "^1.2.1" }, @@ -31054,6 +31114,7 @@ "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, "engines": { "node": ">=10" }, @@ -31609,6 +31670,7 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, "dependencies": { "punycode": "^2.1.0" } @@ -31617,6 +31679,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, "engines": { "node": ">=6" } @@ -32533,6 +32596,7 @@ "version": "7.4.6", "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "dev": true, "engines": { "node": ">=8.3.0" }, @@ -32586,6 +32650,7 @@ "version": "1.6.11", "resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz", "integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==", + "dev": true, "dependencies": { "sax": "^1.2.4" }, diff --git a/src/lib/wdi5-bridge.ts b/src/lib/wdi5-bridge.ts index a332db03..d6e2ef27 100644 --- a/src/lib/wdi5-bridge.ts +++ b/src/lib/wdi5-bridge.ts @@ -10,6 +10,7 @@ import { WDI5Control } from "./wdi5-control.js" import { WDI5FE } from "./wdi5-fe.js" import { clientSide_injectTools } from "../../client-side-js/injectTools.cjs" import { clientSide_injectUI5 } from "../../client-side-js/injectUI5.cjs" +import { clientSide_injectXHRPatch } from "../../client-side-js/injectXHRPatch.cjs" import { clientSide_getSelectorForElement } from "../../client-side-js/getSelectorForElement.cjs" import { clientSide__checkForUI5Ready } from "../../client-side-js/_checkForUI5Ready.cjs" import { clientSide_getObject } from "../../client-side-js/getObject.cjs" @@ -135,6 +136,7 @@ export async function injectUI5(config: wdi5Config, browserInstance) { const version = await (browserInstance as WebdriverIO.Browser).getUI5Version() await checkUI5Version(version) await clientSide_injectTools(browserInstance) // helpers for wdi5 browser scope + await clientSide_injectXHRPatch(config, browserInstance) result = result && (await clientSide_injectUI5(config, waitForUI5Timeout, browserInstance)) // we are not using _controls as an array, we are using it as an object. That's why the length property From 0d409938bef8d59f77f033952af11b4d8cbc72a2 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Wed, 10 Jan 2024 14:14:10 +0100 Subject: [PATCH 2/9] fix: fetch waiter is only avaiable after 1.114.0 --- client-side-js/injectXHRPatch.cjs | 48 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/client-side-js/injectXHRPatch.cjs b/client-side-js/injectXHRPatch.cjs index aaeb5520..4cd2eb6c 100644 --- a/client-side-js/injectXHRPatch.cjs +++ b/client-side-js/injectXHRPatch.cjs @@ -6,32 +6,34 @@ async function clientSide_injectXHRPatch(config, browserInstance) { function checkURL(url) { return autoWaitUrlIgnoreRegex?.map((regex) => new RegExp(regex))?.some((regex) => url.match(regex)) || false } + const imports = ["sap/ui/thirdparty/sinon", "sap/ui/test/autowaiter/_XHRWaiter"] + if (window.compareVersions.compare(sap.ui.version, "1.114.0", ">")) { + imports.push("sap/ui/test/autowaiter/_fetchWaiter") + } //Load the XHRWaiter before our overwrite so we are called first - sap.ui.require( - ["sap/ui/thirdparty/sinon", "sap/ui/test/autowaiter/_XHRWaiter", "sap/ui/test/autowaiter/_fetchWaiter"], - function (sinon, _XHRWaiter, _fetchWaiter) { - // Hook into XHR open for sinon XHRs - const fnOriginalFakeOpen = sinon.FakeXMLHttpRequest.prototype.open - sinon.FakeXMLHttpRequest.prototype.open = function () { - return fnOriginalFakeOpen.apply(this, hooketoXHROpen.apply(this, arguments)) - } - - // Hook into XHR open for regular XHRs - const fnOriginalOpen = XMLHttpRequest.prototype.open - XMLHttpRequest.prototype.open = function () { - return fnOriginalOpen.apply(this, hooketoXHROpen.apply(this, arguments)) - } + sap.ui.require(imports, function (sinon, _XHRWaiter, _fetchWaiter) { + // Hook into XHR open for sinon XHRs + const fnOriginalFakeOpen = sinon.FakeXMLHttpRequest.prototype.open + sinon.FakeXMLHttpRequest.prototype.open = function () { + return fnOriginalFakeOpen.apply(this, hooketoXHROpen.apply(this, arguments)) + } - function hooketoXHROpen(method, url, async) { - //The ignore property will force the OPA5 _XHRWaiter to ignore certain calls for auto waiting - //https://github.com/SAP/openui5/blob/45e49887f632d0a8a8ef195bd3edf10eb0be9015/src/sap.ui.core/src/sap/ui/test/autowaiter/_XHRWaiter.js - //This ist the XHR request instance so setting it here will only affect the specific request - this.ignored = checkURL(url) + // Hook into XHR open for regular XHRs + const fnOriginalOpen = XMLHttpRequest.prototype.open + XMLHttpRequest.prototype.open = function () { + return fnOriginalOpen.apply(this, hooketoXHROpen.apply(this, arguments)) + } - return arguments - } + function hooketoXHROpen(method, url, async) { + //The ignore property will force the OPA5 _XHRWaiter to ignore certain calls for auto waiting + //https://github.com/SAP/openui5/blob/45e49887f632d0a8a8ef195bd3edf10eb0be9015/src/sap.ui.core/src/sap/ui/test/autowaiter/_XHRWaiter.js + //This ist the XHR request instance so setting it here will only affect the specific request + this.ignored = checkURL(url) + return arguments + } + if (_fetchWaiter !== undefined) { const sapFetch = window.fetch window.fetch = function (resource) { @@ -42,9 +44,9 @@ async function clientSide_injectXHRPatch(config, browserInstance) { return sapFetch.apply(this, arguments) } } - done(true) } - ) + done(true) + }) }, config) } From ed1c8f16380d5b62dc885977c21e7ff25c445e9f Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Thu, 11 Jan 2024 10:32:09 +0100 Subject: [PATCH 3/9] chore: typo --- client-side-js/injectXHRPatch.cjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client-side-js/injectXHRPatch.cjs b/client-side-js/injectXHRPatch.cjs index 4cd2eb6c..2dd94291 100644 --- a/client-side-js/injectXHRPatch.cjs +++ b/client-side-js/injectXHRPatch.cjs @@ -16,16 +16,16 @@ async function clientSide_injectXHRPatch(config, browserInstance) { // Hook into XHR open for sinon XHRs const fnOriginalFakeOpen = sinon.FakeXMLHttpRequest.prototype.open sinon.FakeXMLHttpRequest.prototype.open = function () { - return fnOriginalFakeOpen.apply(this, hooketoXHROpen.apply(this, arguments)) + return fnOriginalFakeOpen.apply(this, hooktoXHROpen.apply(this, arguments)) } // Hook into XHR open for regular XHRs const fnOriginalOpen = XMLHttpRequest.prototype.open XMLHttpRequest.prototype.open = function () { - return fnOriginalOpen.apply(this, hooketoXHROpen.apply(this, arguments)) + return fnOriginalOpen.apply(this, hooktoXHROpen.apply(this, arguments)) } - function hooketoXHROpen(method, url, async) { + function hooktoXHROpen(method, url, async) { //The ignore property will force the OPA5 _XHRWaiter to ignore certain calls for auto waiting //https://github.com/SAP/openui5/blob/45e49887f632d0a8a8ef195bd3edf10eb0be9015/src/sap.ui.core/src/sap/ui/test/autowaiter/_XHRWaiter.js //This ist the XHR request instance so setting it here will only affect the specific request From ee4132e798af4601d76e96d2a2e68c242718f016 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Thu, 11 Jan 2024 10:44:00 +0100 Subject: [PATCH 4/9] chore: added type for new config with documentation --- src/types/wdi5.types.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/types/wdi5.types.ts b/src/types/wdi5.types.ts index 0bc48352..4382c456 100644 --- a/src/types/wdi5.types.ts +++ b/src/types/wdi5.types.ts @@ -53,6 +53,11 @@ export interface wdi5Config extends WebdriverIO.Config { * in a SAP Build Workzone Standard Edition (fka Launchpad) environment */ btpWorkZoneEnablement?: boolean + /** + * Regex for XHR/Fetch requests to be ignored by the auto waiter + * Ideal for long polling as this would result in the waiter waiting forever + */ + autoWaitUrlIgnoreRegex?: RegExp[] } capabilities: wdi5Capabilities[] | wdi5MultiRemoteCapability } From f2783613cff9f2c9d259fc87bd43b808c56188ef Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Thu, 11 Jan 2024 13:34:26 +0100 Subject: [PATCH 5/9] docs: add documentation for autoWaitUrlIgnoreRegex --- docs/configuration.md | 9 ++++++++- src/types/wdi5.types.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index f70a45bd..0d6caa16 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -26,7 +26,8 @@ exports.config = { logLevel: "verbose", // [optional] error | verbose | silent, default: "error" skipInjectUI5OnStart: false, // [optional] {boolean}, default: false; true when UI5 is not on the start page, you need to later call .injectUI5() manually waitForUI5Timeout: 15000, // [optional] {number}, default: 15000; maximum waiting time in milliseconds while checking for UI5 availability - btpWorkZoneEnablement: false // [optional] {boolean}, default: false; whether to instruct wdi5 to inject itself in both the SAP Build Workzone, standard edition, shell and app + btpWorkZoneEnablement: false, // [optional] {boolean}, default: false; whether to instruct wdi5 to inject itself in both the SAP Build Workzone, standard edition, shell and app + autoWaitUrlIgnoreRegex: [] // [optional] {string[]}, default: []; Array of regex to ignore certain XHR/Fetch calls wile autowaiting } // ... } @@ -133,6 +134,12 @@ Number in milliseconds (default: `15000`) to wait for UI5-related operations wit Boolean setting to trigger injecting `wdi5` into both the shell and the app when used with the SAP Build Workzone, standard edition. Recommended complement is to also [configure IAS Authentication](authentication?id=sap-cloud-identity-services-identity-authentication): as SAP Build requires its own Identity Provider (most likely provided by using an IAS tenant), you'll have to configure authentication against that as well in `wdi5`. +### `autoWaitUrlIgnoreRegex` + +Ignore list in form of regex. Those will be used to ignore certain XHR/Fetch call from beeing waited for by the OPA5 Waiters. This can be used in combination with longpolling requests to continusly update your app. + +!> Be carefull adding to many requests or to general regex here as this might make the tests more instable by advancing in the test before you expect it. + ## `package.json` Not required, but as a convention, put a `test` or `wdi5` script into your UI5.app's `package.json` to start `wdi5/wdio`. diff --git a/src/types/wdi5.types.ts b/src/types/wdi5.types.ts index 4382c456..e4d952b1 100644 --- a/src/types/wdi5.types.ts +++ b/src/types/wdi5.types.ts @@ -57,7 +57,7 @@ export interface wdi5Config extends WebdriverIO.Config { * Regex for XHR/Fetch requests to be ignored by the auto waiter * Ideal for long polling as this would result in the waiter waiting forever */ - autoWaitUrlIgnoreRegex?: RegExp[] + autoWaitUrlIgnoreRegex?: string[] } capabilities: wdi5Capabilities[] | wdi5MultiRemoteCapability } From 39584ed1628df7888c2dc4272c5fd77b9024886d Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Mon, 15 Jan 2024 08:10:24 +0100 Subject: [PATCH 6/9] Update docs/configuration.md Co-authored-by: Volker Buzek --- docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 0d6caa16..0fbf3ef0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -138,7 +138,7 @@ Recommended complement is to also [configure IAS Authentication](authentication? Ignore list in form of regex. Those will be used to ignore certain XHR/Fetch call from beeing waited for by the OPA5 Waiters. This can be used in combination with longpolling requests to continusly update your app. -!> Be carefull adding to many requests or to general regex here as this might make the tests more instable by advancing in the test before you expect it. +!> Be careful not to add too many URLs here as this might make the tests unreliable ## `package.json` From 3308eb2090f5bb81b33f02ff1bfedf6d7e0ba511 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Mon, 15 Jan 2024 08:15:43 +0100 Subject: [PATCH 7/9] chore: change option naming --- client-side-js/injectXHRPatch.cjs | 4 ++-- docs/configuration.md | 4 ++-- examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js | 2 +- src/types/wdi5.types.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client-side-js/injectXHRPatch.cjs b/client-side-js/injectXHRPatch.cjs index 2dd94291..44258343 100644 --- a/client-side-js/injectXHRPatch.cjs +++ b/client-side-js/injectXHRPatch.cjs @@ -2,9 +2,9 @@ async function clientSide_injectXHRPatch(config, browserInstance) { return await browserInstance.executeAsync((config, done) => { const originalFetch = window.fetch - const autoWaitUrlIgnoreRegex = config.wdi5.autoWaitUrlIgnoreRegex + const ignoreAutoWaitUrls = config.wdi5.ignoreAutoWaitUrls function checkURL(url) { - return autoWaitUrlIgnoreRegex?.map((regex) => new RegExp(regex))?.some((regex) => url.match(regex)) || false + return ignoreAutoWaitUrls?.map((regex) => new RegExp(regex))?.some((regex) => url.match(regex)) || false } const imports = ["sap/ui/thirdparty/sinon", "sap/ui/test/autowaiter/_XHRWaiter"] if (window.compareVersions.compare(sap.ui.version, "1.114.0", ">")) { diff --git a/docs/configuration.md b/docs/configuration.md index 0fbf3ef0..f07fea11 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -27,7 +27,7 @@ exports.config = { skipInjectUI5OnStart: false, // [optional] {boolean}, default: false; true when UI5 is not on the start page, you need to later call .injectUI5() manually waitForUI5Timeout: 15000, // [optional] {number}, default: 15000; maximum waiting time in milliseconds while checking for UI5 availability btpWorkZoneEnablement: false, // [optional] {boolean}, default: false; whether to instruct wdi5 to inject itself in both the SAP Build Workzone, standard edition, shell and app - autoWaitUrlIgnoreRegex: [] // [optional] {string[]}, default: []; Array of regex to ignore certain XHR/Fetch calls wile autowaiting + ignoreAutoWaitUrls: [] // [optional] {string[]}, default: []; Array of regex to ignore certain XHR/Fetch calls wile autowaiting } // ... } @@ -134,7 +134,7 @@ Number in milliseconds (default: `15000`) to wait for UI5-related operations wit Boolean setting to trigger injecting `wdi5` into both the shell and the app when used with the SAP Build Workzone, standard edition. Recommended complement is to also [configure IAS Authentication](authentication?id=sap-cloud-identity-services-identity-authentication): as SAP Build requires its own Identity Provider (most likely provided by using an IAS tenant), you'll have to configure authentication against that as well in `wdi5`. -### `autoWaitUrlIgnoreRegex` +### `ignoreAutoWaitUrls` Ignore list in form of regex. Those will be used to ignore certain XHR/Fetch call from beeing waited for by the OPA5 Waiters. This can be used in combination with longpolling requests to continusly update your app. diff --git a/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js b/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js index 4eedeb20..9b7b43c9 100644 --- a/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js +++ b/examples/ui5-js-app/e2e-test-config/wdio-ui5tooling.conf.js @@ -6,7 +6,7 @@ const _config = { specs: [join("..", "webapp", "test", "e2e", "basic.test.js"), join("webapp", "test", "e2e", "hash-nav.test.js")], baseUrl: "http://localhost:8080/index.html?isui5toolingTest=true", wdi5: { - autoWaitUrlIgnoreRegex: [".*/Categories.*"] + ignoreAutoWaitUrls: [".*/Categories.*"] } } diff --git a/src/types/wdi5.types.ts b/src/types/wdi5.types.ts index e4d952b1..e95b1c59 100644 --- a/src/types/wdi5.types.ts +++ b/src/types/wdi5.types.ts @@ -57,7 +57,7 @@ export interface wdi5Config extends WebdriverIO.Config { * Regex for XHR/Fetch requests to be ignored by the auto waiter * Ideal for long polling as this would result in the waiter waiting forever */ - autoWaitUrlIgnoreRegex?: string[] + ignoreAutoWaitUrls?: string[] } capabilities: wdi5Capabilities[] | wdi5MultiRemoteCapability } From e3dca087f567f4a18c88135171bccbc07f589125 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Mon, 15 Jan 2024 08:18:47 +0100 Subject: [PATCH 8/9] Update docs/configuration.md Co-authored-by: Volker Buzek --- docs/configuration.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index f07fea11..622f2bbe 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -136,7 +136,9 @@ Recommended complement is to also [configure IAS Authentication](authentication? ### `ignoreAutoWaitUrls` -Ignore list in form of regex. Those will be used to ignore certain XHR/Fetch call from beeing waited for by the OPA5 Waiters. This can be used in combination with longpolling requests to continusly update your app. +Array of URLs (as strings), either relative or absolute. `RegEx` are supported. +Querying the URLs will be excluded from the UI5 lifecycle sync. Meaning: no Test code will wait until querying the URLs resolve. +Typical use case is "longpolling" requests that continuously update your app. !> Be careful not to add too many URLs here as this might make the tests unreliable From b33fa1bd75f2b566b48806e79c8598046cfbd182 Mon Sep 17 00:00:00 2001 From: Sebastian Mahr Date: Mon, 15 Jan 2024 08:19:24 +0100 Subject: [PATCH 9/9] chore: remove unused await --- src/lib/wdi5-bridge.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/wdi5-bridge.ts b/src/lib/wdi5-bridge.ts index d6e2ef27..3eda9371 100644 --- a/src/lib/wdi5-bridge.ts +++ b/src/lib/wdi5-bridge.ts @@ -134,7 +134,7 @@ export async function injectUI5(config: wdi5Config, browserInstance) { } const version = await (browserInstance as WebdriverIO.Browser).getUI5Version() - await checkUI5Version(version) + checkUI5Version(version) await clientSide_injectTools(browserInstance) // helpers for wdi5 browser scope await clientSide_injectXHRPatch(config, browserInstance) result = result && (await clientSide_injectUI5(config, waitForUI5Timeout, browserInstance))