playwright-fluent
Version:
Fluent API around playwright
70 lines (69 loc) • 2.72 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const playwright_1 = require("playwright");
const SUT = tslib_1.__importStar(require(".."));
const utils_1 = require("../../../../utils");
describe('get-handle-of', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return null when page has not been initalized', async () => {
// Given
const page = undefined;
// When
const handle = await SUT.getHandleOf('foobar', page, utils_1.defaultWaitUntilOptions);
// Then
expect(handle).toBeNull();
});
test('should return handle when selector exists on the page - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();
// When
const result = await SUT.getHandleOf('body', page, utils_1.defaultWaitUntilOptions);
// Then
expect(result).toBeDefined();
});
test('should throw an error when selector does not exist on the page - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();
const options = {
...utils_1.defaultWaitUntilOptions,
timeoutInMilliseconds: 2000,
};
// When
let result = undefined;
try {
await SUT.getHandleOf('foobar', page, options);
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Selector 'foobar' was not found in DOM");
});
test('should return an error when page has been closed - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();
const waitOptions = {
...utils_1.defaultWaitUntilOptions,
timeoutInMilliseconds: 5000,
};
// When
await browser.close();
// Then
const expectedError = new Error("Selector 'body' was not found in DOM");
await SUT.getHandleOf('body', page, waitOptions).catch((error) => expect(error).toMatchObject(expectedError));
});
});
;