UNPKG

playwright-pom-materials

Version:

Playwright POM materials

59 lines (58 loc) 2.68 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Selectable = exports.hasSelectedClass = void 0; const playwright_1 = require("../helpers/playwright"); const Clickable_1 = require("./Clickable"); exports.hasSelectedClass = (0, playwright_1.hasClassFunc)('selected'); class Selectable extends Clickable_1.Clickable { constructor(locator, options) { super(locator, options); this.selectedPredicate = (options === null || options === void 0 ? void 0 : options.selectedPredicate) || exports.hasSelectedClass; } isSelected() { return this.selectedPredicate(this.locator); } set(value, options) { return value ? this.select(options) : this.deselect(options); } shouldBeSelected() { return __awaiter(this, void 0, void 0, function* () { yield (0, playwright_1.pwRetryForMaterial)(this.locator, this.selectedPredicate); }); } shouldNotBeSelected() { return __awaiter(this, void 0, void 0, function* () { yield (0, playwright_1.pwRetryForMaterial)(this.locator, (0, playwright_1.reverseLocatorPredicate)(this.selectedPredicate)); }); } select(options) { return __awaiter(this, void 0, void 0, function* () { yield (0, playwright_1.pwRetryUi)(this.locator, () => __awaiter(this, void 0, void 0, function* () { if (yield this.isSelected()) return true; yield this.click(); return false; }), options); }); } deselect(options) { return __awaiter(this, void 0, void 0, function* () { yield (0, playwright_1.pwRetryUi)(this.locator, () => __awaiter(this, void 0, void 0, function* () { if (!(yield this.isSelected())) return true; yield this.click(); return false; }), options); }); } } exports.Selectable = Selectable;