playwright-fluent
Version:
Fluent API around playwright
94 lines (93 loc) • 4.36 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"));
const utils_1 = require("../../../../utils");
const is_handle_visible_1 = require("../../is-handle-visible");
describe('handle is visible in viewport', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return false when selector is hidden - firefox', async () => {
// Given
browser = await playwright_1.firefox.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible-in-viewport.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#hidden');
// When
const result = await SUT.isHandleVisibleInViewport(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return true when selector is visible in viewport', async () => {
// Given
browser = await playwright_1.firefox.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible-in-viewport.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#visible');
// When
const result = await SUT.isHandleVisibleInViewport(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test('should return false when selector is transparent', async () => {
// Given
browser = await playwright_1.firefox.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible-in-viewport.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#transparent');
// When
const result = await SUT.isHandleVisibleInViewport(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return false when selector is out of screen', async () => {
// Given
browser = await playwright_1.firefox.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible-in-viewport.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#out-of-screen');
// When
const result = await SUT.isHandleVisibleInViewport(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return false when selector is out of viewport', async () => {
// Given
browser = await playwright_1.firefox.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible-in-viewport.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#out-of-viewport');
// When
const result = await SUT.isHandleVisibleInViewport(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
});
;