playwright-fluent
Version:
Fluent API around playwright
73 lines (72 loc) • 3.19 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('get class list of handle', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return empty string when attribute is empty - chromium', 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, 'get-attribute-of-handle.test.html')}`;
await page.goto(url);
// When
const selector = '#with-empty-attribute';
const handle = await page.$(selector);
const result = await SUT.getAttributeOfHandle('foobar', handle);
// Then
expect(result).toBe('');
});
test('should return null when attribute does not exist - chromium', 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, 'get-attribute-of-handle.test.html')}`;
await page.goto(url);
// When
const selector = '#with-no-attribute';
const handle = await page.$(selector);
const result = await SUT.getAttributeOfHandle('foobar', handle);
// Then
expect(result).toBeNull();
});
test('should return attribute value - chromium', 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, 'get-attribute-of-handle.test.html')}`;
await page.goto(url);
// When
const selector = '#with-attribute';
const handle = await page.$(selector);
const result = await SUT.getAttributeOfHandle('foo', handle);
// Then
expect(result).toBe('bar');
});
test('should return placeholder value - chromium', 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, 'get-attribute-of-handle.test.html')}`;
await page.goto(url);
// When
const selector = '#with-placeholder';
const handle = await page.$(selector);
const result = await SUT.getAttributeOfHandle('placeholder', handle);
// Then
expect(result).toBe('type text here');
});
});
;