@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
193 lines • 7.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NavigationBar = void 0;
const verboseLogger_1 = require("../../helper/verboseLogger");
const errorHandler_1 = __importDefault(require("../../helper/errorHandler"));
const constants_1 = require("../constants");
/**
* @class navigationBar
* @memberof ui5
*/
class NavigationBar {
vlf = new verboseLogger_1.VerboseLoggerFactory("ui5", "navigationBar");
ErrorHandler = new errorHandler_1.default();
/**
* @function clickBack
* @memberOf ui5.navigationBar
* @description Navigates one layer back.
* @param {Number} [timeout=30000] - The timeout to wait (ms).
* @example await ui5.navigationBar.clickBack();
*/
async clickBack(timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.clickBack);
const selector = {
elementProperties: {
id: "backBtn"
}
};
try {
await ui5.userInteraction.click(selector, 0, timeout);
}
catch (error) {
this.ErrorHandler.logException(error);
}
}
/**
* @function clickSapLogo
* @memberOf ui5.navigationBar
* @description Clicks at the SAP Logo.
* @param {Number} [timeout=30000] - The timeout to wait (ms).
* @example await ui5.navigationBar.clickSapLogo();
*/
async clickSapLogo(timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.clickSapLogo);
async function clickLogo() {
const selector = "//a[@id='shell-header-logo']";
await nonUi5.userInteraction.click(selector, 500);
}
const logoWebComponentSelector = "//*[contains(local-name(),'ui5-shellbar-branding')]";
async function clickLogoWebComponent() {
await nonUi5.userInteraction.click(logoWebComponentSelector, 500);
}
async function clickLogoS4HanaCloud() {
// same selector as for web component, but make it a deep selector to handle cases where element is within shadow root
await nonUi5.userInteraction.click(`>>>${logoWebComponentSelector}`, 500);
}
try {
await browser.waitUntil(async () => {
try {
await Promise.any([clickLogo(), clickLogoWebComponent(), clickLogoS4HanaCloud()]);
return true;
}
catch (error) {
// Ignore error and continue to next promise
return false;
}
}, {
timeout: timeout,
timeoutMsg: "SAP Logo not clickable",
interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL
});
}
catch (error) {
this.ErrorHandler.logException(error);
}
}
/**
* @function clickUserIcon
* @memberOf ui5.navigationBar
* @description Clicks at the Account Icon.
* @param {Number} [timeout=30000] - The timeout to wait (ms).
* @example await ui5.navigationBar.clickUserIcon();
*/
async clickUserIcon(timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.clickUserIcon);
// There are three different user icon implementations, some are still used in "older" systems, by time we can remove the legacy ones.
async function clickLegacyUserAvatar() {
const selector = {
elementProperties: {
metadata: "sap.m.Avatar",
id: "*HeaderButton"
}
};
await ui5.userInteraction.click(selector, 0, 500);
}
async function clickWebComponentUserProfile() {
// TODO: to remove '>>>' after support for v9 is implemented (v9 supports shadow root without '>>>')
const selector = ">>>[data-ui5-stable='profile']";
await nonUi5.userInteraction.click(selector, 500);
}
async function clickShellBarUserAvatar() {
const selector = {
elementProperties: {
viewName: "sap.ushell.components.shell.ShellBar.view.ShellBar",
metadata: "sap.ushell.gen.ui5.webcomponents.dist.Avatar",
id: "userActionsMenuHeaderButton"
}
};
await ui5.userInteraction.click(selector, 0, 500);
}
async function clickShellBarUserAvatar2() {
const selector = {
elementProperties: {
viewName: "sap.ushell.components.shell.ShellBar.view.ShellBar",
metadata: "sap.f.gen.ui5.webcomponents.dist.Avatar",
id: "userActionsMenuHeaderButton"
}
};
await ui5.userInteraction.click(selector, 0, 500);
}
try {
// attempt clicking both old and new user icons
await browser.waitUntil(async () => {
try {
await Promise.any([clickLegacyUserAvatar(), clickWebComponentUserProfile(), clickShellBarUserAvatar(), clickShellBarUserAvatar2()]);
return true;
}
catch (error) {
// Ignore error and continue to next promise
return false;
}
}, {
timeout: timeout,
timeoutMsg: `Could not click User Icon in ${+timeout / 1000}s`,
interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL
});
}
catch (error) {
this.ErrorHandler.logException(error);
}
}
// =================================== ASSERTION ===================================
/**
* @function expectPageTitle
* @memberOf ui5.navigationBar
* @description Expects the page title of the current page to be the compare value.
* @param {String} compareValue - The compare value.
* @example await ui5.navigationBar.expectPageTitle("Home");
*/
async expectPageTitle(compareValue) {
const vl = this.vlf.initLog(this.expectPageTitle);
const selector = {
elementProperties: {
metadata: "sap.ushell.ui.shell.ShellAppTitle",
mProperties: {
text: compareValue
}
}
};
try {
await ui5.assertion.expectToBeVisibleInViewport(selector);
}
catch (error) {
this.ErrorHandler.logException(error);
}
}
/**
* @function expectShellHeader
* @memberOf ui5.navigationBar
* @description Expects the shell header to be visible
* @param {Number} [timeout=30000] - The timeout to wait (ms).
* @example await ui5.navigationBar.expectShellHeader();
*/
async expectShellHeader(timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT, loadPropertyTimeout = process.env.LOAD_PROPERTY_TIMEOUT || 10000) {
const vl = this.vlf.initLog(this.expectShellHeader);
const selector = {
elementProperties: {
id: "shell-header"
}
};
try {
await ui5.assertion.expectToBeVisible(selector, 0, timeout, loadPropertyTimeout);
}
catch (error) {
this.ErrorHandler.logException(error);
}
}
}
exports.NavigationBar = NavigationBar;
exports.default = new NavigationBar();
//# sourceMappingURL=navigationBar.js.map