UNPKG

playwright-fluent

Version:
72 lines (71 loc) 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.expectThatSelectorHasPlaceholder = exports.hasPlaceholder = 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 hasPlaceholder(selector, expectedPlaceholder, page, options = utils_1.defaultWaitUntilOptions) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...options, }; if (typeof selector === 'string') { const result = await action.hasSelectorPlaceholder(selector, expectedPlaceholder, page, waitOptions); return result; } { const result = await action.hasSelectorObjectPlaceholder(selector, expectedPlaceholder, page, waitOptions); return result; } } exports.hasPlaceholder = hasPlaceholder; async function expectThatCssSelectorHasPlaceholder(selector, expectedPlaceholder, page, options) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...fluent_api_1.defaultAssertOptions, ...options, throwOnTimeout: true, }; await (0, utils_1.waitUntil)(() => hasPlaceholder(selector, expectedPlaceholder, page, utils_1.noWaitNoThrowOptions), async () => { const exists = await action.exists(selector, page); if (!exists) { return `Selector '${selector}' was not found in DOM.`; } const currentPlaceholder = await action.getAttributeOfSelector(selector, 'placeholder', page, utils_1.noWaitNoThrowOptions); if (currentPlaceholder === null) { return `Selector '${selector}' does not have placeholder '${expectedPlaceholder}', because no placeholder has been found on the selector`; } return `Selector '${selector}' does not have placeholder '${expectedPlaceholder}', but instead has placeholder '${currentPlaceholder}'`; }, waitOptions); } async function expectThatSelectorObjectHasPlaceholder(selector, expectedPlaceholder, page, options) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...fluent_api_1.defaultAssertOptions, ...options, throwOnTimeout: true, }; await (0, utils_1.waitUntil)(() => hasPlaceholder(selector, expectedPlaceholder, page, utils_1.noWaitNoThrowOptions), async () => { const exists = await selector.exists(); if (!exists) { return `Selector '${selector.toString()}' was not found in DOM.`; } const currentPlaceholder = await selector.placeholder(); if (currentPlaceholder === null) { return `'${selector.toString()}' does not have placeholder '${expectedPlaceholder}', because no placeholder has been found on the selector`; } return `'${selector.toString()}' does not have placeholder '${expectedPlaceholder}', but instead has placeholder '${currentPlaceholder}'`; }, waitOptions); } async function expectThatSelectorHasPlaceholder(selector, expectedPlaceholder, page, options = fluent_api_1.defaultAssertOptions) { const assertOptions = { ...fluent_api_1.defaultAssertOptions, ...options, }; if (typeof selector === 'string') { return await expectThatCssSelectorHasPlaceholder(selector, expectedPlaceholder, page, assertOptions); } return await expectThatSelectorObjectHasPlaceholder(selector, expectedPlaceholder, page, assertOptions); } exports.expectThatSelectorHasPlaceholder = expectThatSelectorHasPlaceholder;