playwright-fluent
Version:
Fluent API around playwright
76 lines (75 loc) • 3.17 kB
JavaScript
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 text', () => {
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 text', 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-text.test.html')}`;
await page.goto(url);
const selector = '#p1';
const handle = await page.$(selector);
// When
const result = await SUT.hasHandleText(handle, 'foo');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test('should return true when selector has uppercased text', 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-text.test.html')}`;
await page.goto(url);
const selector = '#upper-case';
const handle = await page.$(selector);
// When
const result = await SUT.hasHandleText(handle, 'FOO');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test('should return false when selector has not the text', 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-text.test.html')}`;
await page.goto(url);
const selector = '#p1';
const handle = await page.$(selector);
// When
const result = await SUT.hasHandleText(handle, 'yo');
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return true when selector is empty and expected is empty', 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-text.test.html')}`;
await page.goto(url);
const handle = await page.$('#empty');
// When
const result = await SUT.hasHandleText(handle, '');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
});
;