UNPKG

playwright-fluent

Version:
62 lines (61 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const playwright_1 = require("playwright"); const SUT = tslib_1.__importStar(require("../index")); describe('handle has attribue with expected value', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should return true when selector has attribute with the expected value', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'has-handle-attribute.test.html')}`; await page.goto(url); const selector = '#with-placeholder'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAttribute(handle, 'data-is-valid', 'false'); // Then expect(handle).toBeDefined(); expect(result).toBe(true); }); test('should return false when selector has not the attribute', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'has-handle-attribute.test.html')}`; await page.goto(url); const selector = '#with-no-placeholder'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAttribute(handle, 'foo', 'bar'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); test('should return false when attribute does not match', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'has-handle-attribute.test.html')}`; await page.goto(url); const selector = '#with-placeholder'; const handle = await page.$(selector); // When const result = await SUT.hasHandleAttribute(handle, 'data-is-valid', 'yo'); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); });