@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
171 lines (148 loc) • 6.63 kB
JavaScript
;
const { BASE_URL } = require("../../../../src/reuse/constants.ts");
const { handleCookiesConsent } = require("../../../helper/utils");
describe("webdriver.io page locator test", function () {
it("should access element by elementProperties, descendantProperties and inner descendantProperties", async function () {
await browser.navigateTo(`${BASE_URL}/#/entity/sap.m.Button/sample/sap.m.sample.Button`);
await handleCookiesConsent();
await util.browser.switchToIframe("[id='sampleFrame']");
const backButtonProperties = {
"elementProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.m.Button",
"type": "Back"
},
"descendantProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.ui.core.Icon",
"src": "sap-icon://nav-back"
}
};
const backButton = await browser.uiControl(backButtonProperties);
await expect(backButton).toBeDisplayed();
await expect(backButton).toBeClickable();
// Use nested ancestorProperties
const backButtonWithNestedDescendantProperties = {
"elementProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.m.Button",
"type": "Back",
"descendantProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.ui.core.Icon",
"src": "sap-icon://nav-back"
}
}
};
const sameBackButton = await browser.uiControl(backButtonWithNestedDescendantProperties);
await expect(sameBackButton).toBeDisplayed();
await expect(sameBackButton).toBeClickable();
// Compare IDs to be sure that both elements are the same reject button;
const backButtonId = await backButton.getProperty("id");
const sameBackButtonId = await sameBackButton.getProperty("id");
expect(backButtonId).toEqual(sameBackButtonId);
});
it("should access element(s) by descendantProperties", async function () {
await browser.url("#/categories");
const ui5ControlProperties = {
"descendantProperties": {
"viewName": "sap.ui.demo.cart.view.Home",
"metadata": "sap.m.List",
"id": "*categoryList"
}
};
// Code before fixes:
// const elems = await browser.uiControls(ui5ControlProperties);
// expect(elems).toBeInstanceOf(Array);
// expect(elems).toBeElementsArrayOfSize({ gte: 1 });
// Code after fixes:
await expect(browser.uiControls(ui5ControlProperties, 1, 1000))
.rejects.toThrowError(/No visible elements found/);
});
it("should access element by element properties and descendant properties", async function () {
await browser.navigateTo(`${BASE_URL}/#/entity/sap.m.Button/sample/sap.m.sample.Button`);
await handleCookiesConsent();
await util.browser.switchToIframe("[id='sampleFrame']");
const ui5ControlProperties = {
"elementProperties": {
"metadata": "sap.m.FlexItemData",
"viewName": "sap.m.sample.Button.Page"
},
"descendantProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.m.Button",
"text": "Default"
}
};
const elem = await browser.uiControl(ui5ControlProperties);
await expect(elem).toBeDisplayedInViewport();
expect(elem).toBeInstanceOf(Object);
expect(elem).toHaveAttribute("elementId");
});
it("try access element by wrong descendant properties and catch error", async function () {
await browser.url("#/categories");
const wrongProperties = {
"descendantProperties": {
"viewName": "sapcart.view.App",
"metadata": "sap.ui.core.mvc.XMLView",
"displayBlock": "true"
}
};
await expect(browser.uiControl(wrongProperties, 1, 1000))
.rejects.toThrowError(/No visible elements found/);
});
it("should access element by elementProperties and multiple descendantProperties as array - AND (happy case)", async function () {
await browser.navigateTo(`${BASE_URL}/#/entity/sap.m.Button/sample/sap.m.sample.Button`);
await handleCookiesConsent();
await util.browser.switchToIframe("[id='sampleFrame']");
// The toolbar contains both a "Default" button and a "Reject" button as descendants - both must match
const selector = {
"elementProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.m.Toolbar"
},
"descendantProperties": [
{ "viewName": "sap.m.sample.Button.Page", "metadata": "sap.m.Button", "text": "Default" },
{ "viewName": "sap.m.sample.Button.Page", "metadata": "sap.m.Button", "text": "Reject" }
]
};
const elem = await browser.uiControl(selector);
await expect(elem).toBeDisplayed();
});
it("should fail when one entry of descendantProperties array does not match - AND (unhappy case)", async function () {
await browser.navigateTo(`${BASE_URL}/#/entity/sap.m.Button/sample/sap.m.sample.Button`);
await handleCookiesConsent();
await util.browser.switchToIframe("[id='sampleFrame']");
// Second entry has a non-existent text - AND logic means the whole selector fails
const selector = {
"elementProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.m.Toolbar"
},
"descendantProperties": [
{ "viewName": "sap.m.sample.Button.Page", "metadata": "sap.m.Button", "text": "Default" },
{ "viewName": "sap.m.sample.Button.Page", "metadata": "sap.m.Button", "text": "this-button-does-not-exist" }
]
};
await expect(browser.uiControl(selector, 0, 1000))
.rejects.toThrowError(/No visible elements found/);
});
it("should return multiple elements when multiple parents each satisfy array descendantProperties - AND (multiple results)", async function () {
await browser.navigateTo(`${BASE_URL}/#/entity/sap.m.Button/sample/sap.m.sample.Button`);
await handleCookiesConsent();
await util.browser.switchToIframe("[id='sampleFrame']");
// Multiple FlexItemData elements exist on this page (one per button).
// Using a single-entry array exercises the array code path and should return all FlexItemData with a Button descendant.
const selector = {
"elementProperties": {
"viewName": "sap.m.sample.Button.Page",
"metadata": "sap.m.FlexItemData"
},
"descendantProperties": [
{ "viewName": "sap.m.sample.Button.Page", "metadata": "sap.m.Button" }
]
};
const elems = await browser.uiControls(selector);
expect(elems.length).toBeGreaterThan(1);
});
});