playwright-fluent
Version:
Fluent API around playwright
66 lines (65 loc) • 3.01 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.expectThatSelectorHasValue = exports.hasValue = 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 hasValue(selector, expectedValue, page, options = utils_1.defaultWaitUntilOptions) {
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
...options,
};
if (typeof selector === 'string') {
const result = await action.hasSelectorValue(selector, expectedValue, page, waitOptions);
return result;
}
{
const result = await action.hasSelectorObjectValue(selector, expectedValue, page, waitOptions);
return result;
}
}
exports.hasValue = hasValue;
async function expectThatCssSelectorHasValue(selector, expectedValue, page, options) {
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
...fluent_api_1.defaultAssertOptions,
...options,
throwOnTimeout: true,
};
await (0, utils_1.waitUntil)(() => hasValue(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}' does not contain '${expectedValue}', but instead it contains '${(0, utils_1.safeToString)(currentValue)}'`;
}, waitOptions);
}
async function expectThatSelectorObjectHasValue(selector, expectedValue, page, options) {
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
...fluent_api_1.defaultAssertOptions,
...options,
throwOnTimeout: true,
};
await (0, utils_1.waitUntil)(() => hasValue(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()}' does not contain '${expectedValue}', but instead it contains '${(0, utils_1.safeToString)(currentValue)}'`;
}, waitOptions);
}
async function expectThatSelectorHasValue(selector, expectedValue, page, options = fluent_api_1.defaultAssertOptions) {
const assertOptions = {
...fluent_api_1.defaultAssertOptions,
...options,
};
if (typeof selector === 'string') {
return await expectThatCssSelectorHasValue(selector, expectedValue, page, assertOptions);
}
return await expectThatSelectorObjectHasValue(selector, expectedValue, page, assertOptions);
}
exports.expectThatSelectorHasValue = expectThatSelectorHasValue;
;