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

Webdriverio v8 #116

Merged
merged 19 commits into from
Apr 5, 2023
Merged
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
4,910 changes: 3,417 additions & 1,493 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@sap_oss/wdio-qmate-service",
"version": "1.5.2",
"version": "2.0.0-beta.1",
"author": "SAP SE",
"types": "./@types/index.d.ts",
"main": "./lib/index.js",
"maintainers": [
{
"name": "Marvin Grüssinger",
"email": "marvin.gruessinger@sap.com"
"name": "Benjamin Warth",
"email": "benjamin.warth@sap.com"
},
{
"name": "Georgios Treska",
Expand All @@ -18,8 +18,8 @@
"email": "tomas.hartmann@sap.com"
},
{
"name": "Benjamin Warth",
"email": "benjamin.warth@sap.com"
"name": "Marvin Grüssinger",
"email": "marvin.gruessinger@sap.com"
}
],
"scripts": {
Expand Down Expand Up @@ -136,14 +136,15 @@
"yargs": "^17.1.1"
},
"devDependencies": {
"@wdio/cli": "^7.16.16",
"@wdio/local-runner": "^7.12.4",
"@wdio/mocha-framework": "^7.12.4",
"@wdio/sauce-service": "^7.16.16",
"@wdio/selenium-standalone-service": "^7.12.5",
"@wdio/shared-store-service": "^7.16.16",
"@wdio/spec-reporter": "^7.20.8",
"@wdio/static-server-service": "^7.10.1",
"@types/fs-extra": "^11.0.1",
"@wdio/cli": "^8.6.9",
"@wdio/local-runner": "^8.6.9",
"@wdio/mocha-framework": "^8.6.8",
"@wdio/sauce-service": "^8.6.9",
"@wdio/selenium-standalone-service": "^8.6.8",
"@wdio/shared-store-service": "^8.6.9",
"@wdio/spec-reporter": "^8.6.8",
"@wdio/static-server-service": "^8.6.8",
"app-root-path": "^3.1.0",
"chai": "^4.3.4",
"chromedriver": "^111.0.0",
Expand All @@ -161,6 +162,6 @@
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.6.3",
"wdio-chromedriver-service": "^7.3.2"
"wdio-chromedriver-service": "^8.1.1"
}
}
26 changes: 11 additions & 15 deletions src/bin/typesGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class TypesGenerator {
maintainers: [
{
name: "Marvin Grüssinger",
email: "marvin.gruessinger@sap.com",
email: "marvin.gruessinger@sap.com"
},
{
name: "Benjamin Warth",
email: "benjamin.warth@sap.com",
},
email: "benjamin.warth@sap.com"
}
],
dependencies: {
"@types/axios": "^0.14.0",
"@types/node": "^18.0.3",
},
"@types/node": "^18.0.3"
}
};

public async generateTypes() {
Expand Down Expand Up @@ -71,15 +71,13 @@ class TypesGenerator {
const replacements = [
{
src: 'from "../src/reuse/modules',
replace: 'from "./modules',
},
replace: 'from "./modules'
}
];
for (const file of files) {
const src = `${srcPath}/${file}`;
const dist = `${distPath}/${file}`;
await fse.copy(src, dist, {
recursive: true,
});
await fse.copy(src, dist);
await this.replaceStringsInFile(dist, replacements);
}
}
Expand Down Expand Up @@ -121,15 +119,13 @@ class TypesGenerator {
const replacements = [
{
src: 'import { Element } from "../../../../@types/wdio"',
replace: 'import { Element } from "../../../@types/wdio"',
},
replace: 'import { Element } from "../../../@types/wdio"'
}
];
for (const file of files) {
const src = `${srcPath}/${moduleName}/${file}`;
const dist = `${distPath}/modules/${moduleName}/${file}`;
await fse.copy(src, dist, {
recursive: true,
});
await fse.copy(src, dist);
await this.replaceStringsInFile(dist, replacements);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import afterHook from "./scripts/hooks/after";
const pj = require("../package.json");

module.exports = class CustomWorkerService {
config: any;
/**
* `serviceOptions` contains all options specific to the service
* e.g. if defined as follows:
Expand All @@ -20,7 +21,9 @@ module.exports = class CustomWorkerService {
* the `serviceOptions` parameter will be: `{ foo: 'bar' }`
*/
// @ts-ignore
constructor(serviceOptions, capabilities, config, browser) { }
constructor(serviceOptions, capabilities, config) {
this.config = config;
}

/**
* Gets executed once before all workers get launched.
Expand Down Expand Up @@ -54,7 +57,9 @@ module.exports = class CustomWorkerService {
// @ts-ignore
async beforeSession(config, capabilities, specs) {
try {
browser.config = config;
await qmateLoaderSession(config, capabilities, specs);
this.config = browser.config;
} catch (e) {
if (specs && specs[0]) {
// `specs` variable is an array, but includes only one current spec
Expand All @@ -76,6 +81,8 @@ module.exports = class CustomWorkerService {
async before(capabilities, specs, browser) {
// Errors in WDIO hooks are suppressed by default => we call process.exit(1). It will mark all specs as failed
try {
browser.config = this.config;
browser.params = browser.config.params;
heraldantony marked this conversation as resolved.
Show resolved Hide resolved
await qmateLoader(capabilities, specs, browser);
} catch (e) {
if (specs && specs[0]) {
Expand Down Expand Up @@ -120,7 +127,7 @@ module.exports = class CustomWorkerService {
*/
async after(result: number, capabilities: any, specs: any) {
try {
afterHook(result, capabilities, specs);
await afterHook(result, capabilities, specs);
} catch (e) {
util.console.error(`after hook failed: ${e}`);
}
Expand Down
19 changes: 9 additions & 10 deletions src/reuse/modules/common/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ export class UserInteraction {
*/
async fillActive(value: string) {
const vlf = this.vlf.initLog(this.fillActive);
try {
if (value !== null) {
if (!(typeof value === "number" || typeof value === "string")) {
throw new Error("Function 'fillActive' failed: Please provide a value(datatype - number/string) as argument.");
} else {
try {
const elem = await $(await browser.getActiveElement());
await elem.addValue(value); //TODO: open issue on wdio github for different behavior in terms of the active element of addValue() and setValue()
} else {
throw new Error("Function 'fillActive' failed: Please provide a value as argument.");
await elem.addValue(value);
} catch (error) {
throw new Error(`Function 'fillActive' failed: ${error}`);
}
} catch (error) {
// @ts-ignore
throw new Error("Function 'fillActive' failed: ", error);
}
}

Expand All @@ -56,11 +55,11 @@ export class UserInteraction {
*/
async clearAndFillActive(value: string) {
const vlf = this.vlf.initLog(this.clearAndFillActive);
if (value !== null) {
if (typeof value === "number" || typeof value === "string") {
const elem = await $(await browser.getActiveElement());
await elem.setValue(value);
} else {
throw new Error("Function 'clearAndFillActive' failed. Please provide a value as argument.");
throw new Error("Function 'clearAndFillActive' failed. Please provide a value(datatype - number/string) as argument.");
}
}

Expand Down
52 changes: 25 additions & 27 deletions src/reuse/modules/nonUi5/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,23 @@ export class UserInteraction {
*/
async fill(element: Element, value: string) {
const vl = this.vlf.initLog(this.fill);
try {
vl.log(`Setting the value of element to ${value}`);
await element.setValue(value);
} catch (error) {
// @ts-ignore
if (error.message && error.message.match(new RegExp(/(invalid element state|element not interactable)/))) {
const errorMessage = await util.function.mapWdioErrorToQmateErrorMessage(error as Error, "fill");
throw new Error(errorMessage);
} else {
if (!value) {
throw new Error("Function 'fill' failed: Please provide a value as second argument: " + error);
if (!(typeof value === "number" || typeof value === "string")) {
throw new Error("Function 'fill' failed: Please provide an element and value(datatype - number/string) as arguments");
} else {
try {
vl.log(`Setting the value of element to ${value}`);
await element.setValue(value);
} catch (error) {
// @ts-ignore
if (error.message && error.message.match(new RegExp(/(invalid element state|element not interactable)/))) {
const errorMessage = await util.function.mapWdioErrorToQmateErrorMessage(error as Error, "fill");
throw new Error(errorMessage);
} else {
throw error;
if (!value) {
throw new Error("Function 'fill' failed: Please provide a value as second argument: " + error);
} else {
throw error;
}
}
}
}
Expand Down Expand Up @@ -233,8 +237,8 @@ export class UserInteraction {
async clearAndFill(element: Element, value: string) {
const vl = this.vlf.initLog(this.clearAndFill);
//arg. 'value' needs to be checked in case of numeric values. E.g.: 0 or 1 will be handled as boolean value in if.
if (!element || value === null || value === undefined || value === "") {
throw new Error("Function 'clearAndFill' failed: Please provide an element and value as arguments.");
if (!element || !(typeof value === "number" || typeof value === "string")) {
throw new Error("Function 'clearAndFill' failed: Please provide an element and value(datatype - number/string) as arguments.");
} else {
try {
vl.log("Clearing the element");
Expand Down Expand Up @@ -346,19 +350,13 @@ export class UserInteraction {
y: +Number(targetSize.height / 2).toFixed(0) + +Number(targetLocation.y).toFixed(0) + 1
};

await browser.performActions([
{
type: "pointer",
id: "finger1",
parameters: { pointerType: "mouse" },
actions: [
{ type: "pointerMove", duration: 0, x: sourceCenterLocation.x, y: sourceCenterLocation.y },
{ type: "pointerDown", button: 0 },
{ type: "pointerMove", duration: 0, x: targetCenterLocation.x, y: targetCenterLocation.y },
{ type: "pointerUp", button: 0 }
]
}
]);
await browser
.action("pointer")
.move({ duration: 0, x: sourceCenterLocation.x, y: sourceCenterLocation.y })
.down({ button: 0 }) //left button
.move({ duration: 0, x: targetCenterLocation.x, y: targetCenterLocation.y })
.down({ button: 0 }) //left button
.perform();
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/reuse/modules/ui5/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class UserInteraction {
async fill(selector: any, value: string, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
const vl = this.vlf.initLog(this.fill);
vl.log(`Filling with ${value}`);
if (value !== null) {
if (typeof value === "number" || typeof value === "string") {
const id = await ui5.element.getId(selector, index, timeout);
let elem = null;
if (selector.elementProperties.metadata === "sap.m.TextArea") {
Expand All @@ -249,6 +249,8 @@ export class UserInteraction {
elem = await nonUi5.element.getByCss("[id='" + id + "'] input", index, timeout);
}
await elem.setValue(value);
} else {
throw new Error("Function 'fill' failed: Please provide an element and value(datatype - number/string) as arguments.");
}
}

Expand Down Expand Up @@ -314,11 +316,11 @@ export class UserInteraction {
*/
async clearAndFill(selector: any, value: string, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
const vl = this.vlf.initLog(this.clearAndFill);
if (value !== null) {
if (typeof value === "number" || typeof value === "string") {
await this.clear(selector, index, timeout);
await common.userInteraction.fillActive(value);
} else {
throw new Error("Function 'clearAndFill' failed. Please provide a value as second parameter.");
throw new Error("Function 'clearAndFill' failed. Please provide a value(datatype - number/string) as second parameter.");
}
}

Expand Down
20 changes: 6 additions & 14 deletions test/reuse/common/userInteraction/fillActive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ describe("userInteraction - fillActive - element with number", function () {
describe("userInteraction - fillActive - element with empty value", function () {

let value;
let actualValue;

it("Preparation", async function () {
await browser.navigateTo("https://sapui5.hana.ondemand.com/1.99.0/test-resources/sap/m/demokit/cart/webapp/index.html");
await handleCookiesConsent();
});

it("Execution", async function () {
it("Execution & Verification", async function () {
const selector = {
"elementProperties": {
"viewName": "sap.ui.demo.cart.view.Home",
Expand All @@ -103,12 +102,8 @@ describe("userInteraction - fillActive - element with empty value", function ()
const index = 0;
const timeout = 30000;
await ui5.userInteraction.click(selector);
await common.userInteraction.fillActive(value);
actualValue = await ui5.element.getValue(selector, index, timeout);
});

it("Verification", function () {
common.assertion.expectEqual(actualValue, "");
await expect(common.userInteraction.fillActive(value))
.rejects.toThrow("Function 'fillActive' failed: Please provide a value(datatype - number/string) as argument.");
});
});

Expand Down Expand Up @@ -205,15 +200,12 @@ describe("userInteraction - fillActive - empty value", function () {
await nonUi5.assertion.expectValueToBe(element, "", "value");
});

it("Execution", async function () {
it("Execution & Verification", async function () {
// Make the form field active
await nonUi5.userInteraction.click(element);
await common.userInteraction.fillActive();
});
await expect(common.userInteraction.fillActive())
.rejects.toThrow("Function 'fillActive' failed: Please provide a value(datatype - number/string) as argument.");

it("Verification", async function () {
// Check the form field itself
await nonUi5.assertion.expectValueToBe(element, "", "value");
});
});

Expand Down
Loading