@qavajs/steps-playwright
Version:
qavajs steps to interact with playwright
217 lines • 11.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@qavajs/core");
/**
* Verify element condition
* @param {string} alias - element to wait condition
* @param {string} condition - wait condition
* @example I expect 'Header' to be visible
* @example I expect 'Loading' not to be present
* @example I expect 'Search Bar > Submit Button' to be clickable
*/
(0, core_1.Then)('I expect {playwrightLocator} {playwrightCondition}', async function (locator, condition) {
await condition(locator, this.config.browser.timeout.page);
});
/**
* Verify that text of element satisfies condition
* @param {string} alias - element to get text
* @param {string} validationType - validation
* @param {string} value - expected result
* @example I expect text of 'Search Results (1)' equals to 'google'
*/
(0, core_1.Then)('I expect text of {playwrightLocator} {validation} {value}', async function (locator, validation, expected) {
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const elementText = () => locator.innerText({ timeout: interval });
await validation.poll(elementText, expectedValue, { timeout, interval });
});
/**
* Verify value of element
* @param {string} alias - element to verify
* @param {string} validationType - validation
* @param {string} value - expected value
* @example I expect value of 'Search Input' to be equal 'text'
*/
(0, core_1.Then)('I expect value of {playwrightLocator} {validation} {value}', async function (locator, validation, expected) {
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualValue = () => locator.inputValue({ timeout: interval });
await validation.poll(actualValue, expectedValue, { timeout, interval });
});
/**
* Verify that property of element satisfies condition
* @param {string} property - element to verify
* @param {string} alias - element to verify
* @param {string} validationType - validation
* @param {string} value - expected value
* @example I expect 'value' property of 'Search Input' to be equal 'text'
* @example I expect 'innerHTML' property of 'Label' to contain '<b>'
*/
(0, core_1.Then)('I expect {value} property of {playwrightLocator} {validation} {value}', async function (property, locator, validation, expected) {
const propertyName = await property.value();
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualValue = () => locator.evaluate((node, propertyName) => node[propertyName], propertyName, { timeout: interval });
await validation.poll(actualValue, expectedValue, { timeout, interval });
});
/**
* Verify that attribute of element satisfies condition
* @param {string} attribute - element to verify
* @param {string} alias - element to verify
* @param {string} validationType - validation
* @param {string} value - expected value
* @example I expect 'href' attribute of 'Home Link' to contain '/home'
*/
(0, core_1.Then)('I expect {value} attribute of {playwrightLocator} {validation} {value}', async function (attribute, locator, validation, expected) {
const attributeName = await attribute.value();
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualValue = () => locator.getAttribute(attributeName, { timeout: interval });
await validation.poll(actualValue, expectedValue, { timeout, interval });
});
/**
* Verify that current url satisfies condition
* @param {string} validationType - validation
* @param {string} expected - expected value
* @example I expect current url contains 'wikipedia'
* @example I expect current url equals 'https://wikipedia.org'
*/
(0, core_1.Then)('I expect current url {validation} {value}', async function (validation, expected) {
const expectedUrl = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualUrl = () => this.playwright.page.url();
await validation.poll(actualUrl, expectedUrl, { timeout, interval });
});
/**
* Verify that number of element in collection satisfies condition
* @param {string} alias - collection to verify
* @param {string} validationType - validation
* @param {string} value - expected value
* @example I expect number of elements in 'Search Results' collection to be equal '50'
* @example I expect number of elements in 'Search Results' collection to be above '49'
* @example I expect number of elements in 'Search Results' collection to be below '51'
*/
(0, core_1.Then)('I expect number of elements in {playwrightLocator} collection {validation} {value}', async function (locator, validation, expected) {
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualCount = () => locator.count();
await validation.poll(actualCount, expectedValue, { timeout, interval });
});
/**
* Verify that page title satisfies condition
* @param {string} validationType - validation
* @param {string} expected - expected value
* @example I expect page title equals 'Wikipedia'
*/
(0, core_1.Then)('I expect page title {validation} {value}', async function (validation, expected) {
const expectedTitle = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualTitle = () => this.playwright.page.title();
await validation.poll(actualTitle, expectedTitle, { timeout, interval });
});
/**
* Verify collection condition
* @param {string} alias - collection to wait condition
* @param {string} condition - wait condition
* @example I expect every element in 'Header > Links' collection to be visible
* @example I expect every element in 'Loading Bars' collection not to be present
*/
(0, core_1.Then)('I expect every element in {playwrightLocator} collection {playwrightCondition}', async function (locator, condition) {
const conditionWait = (element) => condition(element, this.config.browser.timeout.page);
for (let i = 0; i < await locator.count(); i++) {
await conditionWait(locator.nth(i));
}
});
/**
* Verify that all texts in collection satisfy condition
* @param {string} alias - collection to get texts
* @param {string} validationType - validation
* @param {string} value - expected result
* @example I expect text of every element in 'Search Results' collection equals to 'google'
* @example I expect text of every element in 'Search Results' collection does not contain 'google'
*/
(0, core_1.Then)('I expect text of every element in {playwrightLocator} collection {validation} {value}', async function (locator, validation, expected) {
const expectedValue = await expected.value();
const interval = this.config.browser.timeout.valueInterval;
for (let i = 0; i < await locator.count(); i++) {
const elementText = () => locator.nth(i).innerText({ timeout: interval });
await validation.poll(elementText, expectedValue, { interval });
}
});
/**
* Verify that all particular attributes in collection satisfy condition
* @param {string} alias - collection to get attrs
* @param {string} validationType - validation
* @param {string} value - expected result
* @example I expect 'href' attribute of every element in 'Search Results' collection to contain 'google'
*/
(0, core_1.Then)('I expect {value} attribute of every element in {playwrightLocator} collection {validation} {value}', async function (attribute, locator, validation, expected) {
const expectedValue = await expected.value();
const attributeName = await attribute.value();
const interval = this.config.browser.timeout.valueInterval;
for (let i = 0; i < await locator.count(); i++) {
const attributeValue = () => locator.nth(i).getAttribute(attributeName, { timeout: interval });
await validation.poll(attributeValue, expectedValue, { interval });
}
});
/**
* Verify that all particular properties in collection satisfy condition
* @param {string} alias - collection to get props
* @param {string} validationType - validation
* @param {string} value - expected result
* @example I expect 'href' property of every element in 'Search Results' collection to contain 'google'
*/
(0, core_1.Then)('I expect {value} property of every element in {playwrightLocator} collection {validation} {value}', async function (property, locator, validation, expected) {
const expectedValue = await expected.value();
const propertyName = await property.value();
const interval = this.config.browser.timeout.valueInterval;
for (let i = 0; i < await locator.count(); i++) {
const propertyValue = () => locator.nth(i).evaluate((node, property) => node[property], propertyName, { timeout: interval });
await validation.poll(propertyValue, expectedValue, { interval });
}
});
/**
* Verify that css property of element satisfies condition
* @param {string} property - element to verify
* @param {string} alias - element to verify
* @param {string} validationType - validation
* @param {string} value - expected value
* @example I expect 'color' css property of 'Search Input' to be equal 'rgb(42, 42, 42)'
* @example I expect 'font-family' css property of 'Label' to contain 'Fira'
*/
(0, core_1.Then)('I expect {value} css property of {playwrightLocator} {validation} {value}', async function (property, locator, validation, expected) {
const propertyName = await property.value();
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
const actualValue = () => locator.evaluate((node, propertyName) => getComputedStyle(node).getPropertyValue(propertyName), propertyName, { timeout: interval });
await validation.poll(actualValue, expectedValue, { timeout, interval });
});
/**
* Verify that css property of every element in collection satisfies condition
* @param {string} property - property to verify
* @param {string} alias - collection to verify
* @param {string} validationType - validation
* @param {string} value - expected value
* @example I expect 'color' css property of every element in 'Table > Rows' collection to be equal 'rgb(42, 42, 42)'
* @example I expect 'font-family' css property of every element in 'Labels' to contain 'Fira'
*/
(0, core_1.Then)('I expect {value} css property of every element in {playwrightLocator} collection {validation} {value}', async function (property, collection, validation, expected) {
const propertyName = await property.value();
const expectedValue = await expected.value();
const timeout = this.config.browser.timeout.value;
const interval = this.config.browser.timeout.valueInterval;
for (let i = 0; i < await collection.count(); i++) {
const locator = collection.nth(i);
const actualValue = () => locator.evaluate((node, propertyName) => getComputedStyle(node).getPropertyValue(propertyName), propertyName, { timeout: interval });
await validation.poll(actualValue, expectedValue, { timeout, interval });
}
});
//# sourceMappingURL=validations.js.map