Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
:beetle: - bugfix
:x: - deprecation

## [Unreleased]
- :beetle: added present timeout for value waits

## [0.41.5]
- :beetle: updated validation package

## [0.41.4]
- :beetle: added existence waiter before value waits to avoid promise reject without reason error
- :rocket: added _restartBrowser_ config flag to restart browser between tests (default is false, considering restarting context)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions src/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ Then(
async function (alias: string, validationType: string, value: any) {
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const validation = getPollValidation(validationType);
const elementText = () => element.innerText();
await validation(elementText, expectedValue, {
timeout: config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -55,11 +56,12 @@ Then(
const propertyName = await getValue(property);
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const validation = getPollValidation(validationType);
const actualValue = () => element.evaluate((node: any, propertyName: string) => node[propertyName], propertyName);
await validation(actualValue, expectedValue, {
timeout: config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -79,11 +81,12 @@ Then(
const attributeName = await getValue(attribute);
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const validation = getPollValidation(validationType);
const actualValue = () => element.getAttribute(attributeName);
await validation(actualValue, expectedValue, {
timeout: config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand Down Expand Up @@ -246,14 +249,15 @@ Then(
const propertyName = await getValue(property);
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const validation = getPollValidation(validationType);
const actualValue = () => element.evaluate(
(node: Element, propertyName: string) => getComputedStyle(node).getPropertyValue(propertyName),
propertyName
);
await validation(actualValue, expectedValue, {
timeout: config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -265,7 +269,9 @@ Then(
* @param {string} value - expected text value
* @example I expect text of alert does not contain 'coffee'
*/
Then('I expect text of alert {playwrightValidation} {string}', async function (validationType: string, expectedValue: string) {
Then(
'I expect text of alert {playwrightValidation} {string}',
async function (validationType: string, expectedValue: string) {
const alertText = await new Promise<string>(resolve => page.once('dialog', async (dialog) => {
resolve(dialog.message());
}));
Expand Down
44 changes: 24 additions & 20 deletions src/waits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { getPollValidation } from '@qavajs/validation';
*/
When(
'I wait until {string} {playwrightConditionWait}( ){playwrightTimeout}',
async function (alias: string, waitType: string, timeout: number | null) {
async function (alias: string, waitType: string, timeoutValue: number | null) {
const wait = getConditionWait(waitType);
const element = await getElement(alias);
await wait(element, timeout ? timeout : config.browser.timeout.page);
await wait(element, timeoutValue ?? config.browser.timeout.page);
}
);

Expand All @@ -33,14 +33,15 @@ When(
*/
When(
'I wait until text of {string} {playwrightValidation} {string}( ){playwrightTimeout}',
async function (alias: string, waitType: string, value: string, timeout: number | null) {
async function (alias: string, waitType: string, value: string, timeoutValue: number | null) {
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = timeoutValue ?? config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const expectedValue = await getValue(value);
const getValueFn = () => element.innerText();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -59,13 +60,13 @@ When(
*/
When(
'I wait until number of elements in {string} collection {playwrightValidation} {string}( ){playwrightTimeout}',
async function (alias: string, waitType: string, value: string, timeout: number | null) {
async function (alias: string, waitType: string, value: string, timeoutValue: number | null) {
const wait = getPollValidation(waitType);
const collection = await getElement(alias);
const expectedValue = await getValue(value);
const getValueFn = () => collection.count();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout: timeoutValue ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -83,18 +84,19 @@ When(
*/
When(
'I wait until {string} property of {string} {playwrightValidation} {string}( ){playwrightTimeout}',
async function (property: string, alias: string, waitType: string, value: string, timeout: number | null) {
async function (property: string, alias: string, waitType: string, value: string, timeoutValue: number | null) {
const propertyName = await getValue(property);
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = timeoutValue ?? config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const expectedValue = await getValue(value);
const getValueFn = () => element.evaluate(
(node: any, propertyName: string) => node[propertyName],
propertyName
);
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -112,18 +114,19 @@ When(
*/
When(
'I wait until {string} css property of {string} {playwrightValidation} {string}( ){playwrightTimeout}',
async function (property: string, alias: string, waitType: string, value: string, timeout: number | null) {
async function (property: string, alias: string, waitType: string, value: string, timeoutValue: number | null) {
const propertyName = await getValue(property);
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = timeoutValue ?? config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const expectedValue = await getValue(value);
const getValueFn = () => element.evaluate(
(node: Element, propertyName: string) => getComputedStyle(node).getPropertyValue(propertyName),
propertyName
);
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -141,15 +144,16 @@ When(
*/
When(
'I wait until {string} attribute of {string} {playwrightValidation} {string}( ){playwrightTimeout}',
async function (attribute: string, alias: string, waitType: string, value: string, timeout: number | null) {
async function (attribute: string, alias: string, waitType: string, value: string, timeoutValue: number | null) {
const attributeName = await getValue(attribute);
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const timeout = timeoutValue ?? config.browser.timeout.value;
await element.waitFor({ state: 'attached', timeout });
const expectedValue = await getValue(value);
const getValueFn = () => element.getAttribute(attributeName);
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout,
interval: config.browser.timeout.valueInterval
});
}
Expand Down Expand Up @@ -177,12 +181,12 @@ When('I wait {int} ms', async function (ms) {
*/
When(
'I wait until current url {playwrightValidation} {string}( ){playwrightTimeout}',
async function (waitType: string, value: string, timeout: number | null) {
async function (waitType: string, value: string, timeoutValue: number | null) {
const wait = getPollValidation(waitType);
const expectedValue = await getValue(value);
const getValueFn = () => page.url();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout: timeoutValue ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
});
}
Expand All @@ -199,12 +203,12 @@ When(
*/
When(
'I wait until page title {playwrightValidation} {string}( ){playwrightTimeout}',
async function (waitType: string, value: string, timeout: number | null) {
async function (waitType: string, value: string, timeoutValue: number | null) {
const wait = getPollValidation(waitType);
const expectedValue = await getValue(value);
const getValueFn = () => page.title();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
timeout: timeoutValue ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
});
}
Expand Down