playwright-fluent
Version:
Fluent API around playwright
66 lines (65 loc) • 3.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.expectThatSelectorHasExactValue = exports.hasExactValue = void 0;
const tslib_1 = require("tslib");
const utils_1 = require("../../utils");
const action = (0, tslib_1.__importStar)(require("../../actions"));
const fluent_api_1 = require("../../fluent-api");
async function hasExactValue(selector, expectedValue, page, options = utils_1.defaultWaitUntilOptions) {
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
...options,
};
if (typeof selector === 'string') {
const result = await action.hasSelectorExactValue(selector, expectedValue, page, waitOptions);
return result;
}
{
const result = await action.hasSelectorObjectExactValue(selector, expectedValue, page, waitOptions);
return result;
}
}
exports.hasExactValue = hasExactValue;
async function expectThatCssSelectorHasExactValue(selector, expectedValue, page, options) {
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
...fluent_api_1.defaultAssertOptions,
...options,
throwOnTimeout: true,
};
await (0, utils_1.waitUntil)(() => hasExactValue(selector, expectedValue, page, utils_1.noWaitNoThrowOptions), async () => {
const exists = await action.exists(selector, page);
if (!exists) {
return `Selector '${selector}' was not found in DOM.`;
}
const currentValue = await action.getValueOfSelector(selector, page, utils_1.noWaitNoThrowOptions);
return `Value of selector '${selector}' is not equal to '${expectedValue}', but instead is '${(0, utils_1.safeToString)(currentValue)}'`;
}, waitOptions);
}
async function expectThatSelectorObjectHasExactValue(selector, expectedValue, page, options) {
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
...fluent_api_1.defaultAssertOptions,
...options,
throwOnTimeout: true,
};
await (0, utils_1.waitUntil)(() => hasExactValue(selector, expectedValue, page, utils_1.noWaitNoThrowOptions), async () => {
const exists = await selector.exists();
if (!exists) {
return `Selector '${selector.toString()}' was not found in DOM.`;
}
const currentValue = await selector.value();
return `Value of '${selector.toString()}' is not equal to '${expectedValue}', but instead is '${(0, utils_1.safeToString)(currentValue)}'`;
}, waitOptions);
}
async function expectThatSelectorHasExactValue(selector, expectedValue, page, options = fluent_api_1.defaultAssertOptions) {
const assertOptions = {
...fluent_api_1.defaultAssertOptions,
...options,
};
if (typeof selector === 'string') {
return await expectThatCssSelectorHasExactValue(selector, expectedValue, page, assertOptions);
}
return await expectThatSelectorObjectHasExactValue(selector, expectedValue, page, assertOptions);
}
exports.expectThatSelectorHasExactValue = expectThatSelectorHasExactValue;
;