UNPKG

@sap_oss/wdio-qmate-service

Version:

[![REUSE status](https://api.reuse.software/badge/github.com/SAP/wdio-qmate-service)](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[![Node.js CI](https://github.com/SAP/wdio-qmate-service/actions/workflows/node.js.yml/badge.svg)](http

153 lines 8.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Assertion = void 0; const verboseLogger_1 = require("../../helper/verboseLogger"); const elementResolving_1 = require("../../helper/elementResolving"); const errorHandler_1 = __importDefault(require("../../helper/errorHandler")); const constants_1 = require("../constants"); /** * @class assertion * @memberof nonUi5 */ class Assertion { vlf = new verboseLogger_1.VerboseLoggerFactory("nonUi5", "assertion"); ErrorHandler = new errorHandler_1.default(); // =================================== PROPERTIES =================================== /** * @function expectAttributeToBe * @memberOf nonUi5.assertion * @description Expects the attributes value of the passed element to be the compare value. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @param {String} compareValue - The compare value. * @param {String} [attribute] - The attribute to compare. If not passed, it will compare the inner HTML content of the element. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectAttributeToBe(element, "Save"); * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectAttributeToBe(element, "Save", "title"); */ async expectAttributeToBe(elementOrSelector, compareValue, attribute) { const vl = this.vlf.initLog(this.expectAttributeToBe); const element = await (0, elementResolving_1.resolveCssSelectorOrElement)(elementOrSelector); const value = await nonUi5.element.getAttributeValue(element, attribute); return common.assertion.expectEqual(value, compareValue); } /** * @function expectAttributeToContain * @memberOf nonUi5.assertion * @description Expects the attributes value of the passed element to contain the compare value. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @param {String} compareValue - The compare value. * @param {String} [attribute] - The attribute to compare. If not passed, it will compare the inner HTML content of the element. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectAttributeToContain(element, "Save", "title"); */ async expectAttributeToContain(elementOrSelector, compareValue, attribute) { const vl = this.vlf.initLog(this.expectAttributeToContain); const element = await (0, elementResolving_1.resolveCssSelectorOrElement)(elementOrSelector); const value = await nonUi5.element.getAttributeValue(element, attribute); vl.log(`Expecting ${value} to contain ${compareValue}`); return expect(value).toContain(compareValue); } /** * @function expectValueToBe * @memberOf nonUi5.assertion * @description Expects the attributes value of the passed element to be the compare value. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @param {String} compareValue - The compare value. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectValueToBe(element, "Save"); */ async expectValueToBe(elementOrSelector, compareValue) { const vl = this.vlf.initLog(this.expectValueToBe); // Note: it is not required to send 'value' here, because 'expectAttributeToBe' is calling 'getValue' inside const element = await (0, elementResolving_1.resolveCssSelectorOrElement)(elementOrSelector); await this.expectAttributeToBe(element, compareValue); } /** * @function expectCssPropertyValueToBe * @memberOf nonUi5.assertion * @description Expects the CSS property value of the passed element to be the compare value. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @param {String} cssProperty - The CSS property of the element to compare with. * @param {String} compareValue - The compare value. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectCssPropertyValueToBe(element, "color", "rgb(255, 0, 0)"); */ async expectCssPropertyValueToBe(elementOrSelector, cssProperty, compareValue) { const vl = this.vlf.initLog(this.expectCssPropertyValueToBe); const value = await nonUi5.element.getCssPropertyValue(elementOrSelector, cssProperty); return common.assertion.expectEqual(value, compareValue); } /** * @function expectTextToBe * @memberOf nonUi5.assertion * @description Expects the text of the passed element to be the compare value. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @param {String} compareValue - The compare value. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectTextToBe(element, "Save"); **/ async expectTextToBe(elementOrSelector, compareValue) { const vl = this.vlf.initLog(this.expectTextToBe); const element = await (0, elementResolving_1.resolveCssSelectorOrElement)(elementOrSelector); const textValue = await element.getText(); return common.assertion.expectEqual(textValue, compareValue); } // =================================== VISIBILITY =================================== /** * @function expectToBeVisible * @memberOf nonUi5.assertion * @description Expects that the element is visible to the user. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectToBeVisible(elem); */ async expectToBeVisible(elementOrSelector) { const vl = this.vlf.initLog(this.expectToBeVisible); try { const element = await (0, elementResolving_1.resolveCssSelectorOrElement)(elementOrSelector); await browser.waitUntil(async function () { const isPresent = await element.isExisting(); const isDisplayed = await element.isDisplayed(); return isPresent && isDisplayed; }, { interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL, timeout: constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT, timeoutMsg: "Function 'expectToBeVisible' failed. Timeout by waiting for element to be visible." }); } catch (error) { this.ErrorHandler.logException(error); } } /** * @function expectToBeNotVisible * @memberOf nonUi5.assertion * @description Expects that the element is not visible to the user. * @param {Element | string} elementOrSelector - The element or CSS selector describing the element. * @param {Number} [timeout=30000] - The timeout to wait (ms). Recommendation is to lower the timeout since the element is not expected to show up. * @example const element = await nonUi5.element.getById("button01"); * await nonUi5.assertion.expectToBeNotVisible(element, 5000); */ async expectToBeNotVisible(elementOrSelector, timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) { const vl = this.vlf.initLog(this.expectToBeNotVisible); try { const element = await (0, elementResolving_1.resolveCssSelectorOrElement)(elementOrSelector); await element.waitForDisplayed({ timeout: +timeout, reverse: true, timeoutMsg: "Function 'expectToBeNotVisible' failed. Element is visible but was expected to be not.", interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL }); } catch (error) { this.ErrorHandler.logException(error); } } } exports.Assertion = Assertion; exports.default = new Assertion(); //# sourceMappingURL=assertion.js.map