UNPKG

playwright-fluent

Version:
72 lines (71 loc) 4.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.expectThatSelectorHasAttributeWithValue = exports.hasAttributeWithValue = 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 hasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, options = utils_1.defaultWaitUntilOptions) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...options, }; if (typeof selector === 'string') { const result = await action.hasSelectorAttribute(selector, attributeName, expectedAttributeValue, page, waitOptions); return result; } { const result = await action.hasSelectorObjectAttribute(selector, attributeName, expectedAttributeValue, page, waitOptions); return result; } } exports.hasAttributeWithValue = hasAttributeWithValue; async function expectThatCssSelectorHasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, options) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...fluent_api_1.defaultAssertOptions, ...options, throwOnTimeout: true, }; await (0, utils_1.waitUntil)(() => hasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, utils_1.noWaitNoThrowOptions), async () => { const exists = await action.exists(selector, page); if (!exists) { return `Selector '${selector}' was not found in DOM.`; } const currentAttributeValue = await action.getAttributeOfSelector(selector, attributeName, page, utils_1.noWaitNoThrowOptions); if (currentAttributeValue === null) { return `Selector '${selector}' does not have attribute '${attributeName}' with value '${expectedAttributeValue}', because no attribute with this name has been found on the selector`; } return `Selector '${selector}' does not have attribute '${attributeName}' with value '${expectedAttributeValue}', but instead the attribute value is '${currentAttributeValue}'`; }, waitOptions); } async function expectThatSelectorObjectHasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, options) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...fluent_api_1.defaultAssertOptions, ...options, throwOnTimeout: true, }; await (0, utils_1.waitUntil)(() => hasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, utils_1.noWaitNoThrowOptions), async () => { const exists = await selector.exists(); if (!exists) { return `Selector '${selector.toString()}' was not found in DOM.`; } const currentAttributeValue = await selector.getAttribute(attributeName); if (currentAttributeValue === null) { return `'${selector.toString()}' does not have attribute '${attributeName}' with value '${expectedAttributeValue}', because no attribute with this name has been found on the selector`; } return `'${selector.toString()}' does not have attribute '${attributeName}' with value '${expectedAttributeValue}', but instead the attribute value is '${currentAttributeValue}'`; }, waitOptions); } async function expectThatSelectorHasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, options = fluent_api_1.defaultAssertOptions) { const assertOptions = { ...fluent_api_1.defaultAssertOptions, ...options, }; if (typeof selector === 'string') { return await expectThatCssSelectorHasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, assertOptions); } return await expectThatSelectorObjectHasAttributeWithValue(selector, attributeName, expectedAttributeValue, page, assertOptions); } exports.expectThatSelectorHasAttributeWithValue = expectThatSelectorHasAttributeWithValue;