playwright-fluent
Version:
Fluent API around playwright
136 lines (135 loc) • 6.5 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 page_actions_1 = require("../../../page-actions");
const is_handle_visible_1 = require("../is-handle-visible");
const get_intersection_ratio_of_handle_1 = require("../../get-intersection-ratio-of-handle");
const utils_1 = require("../../../../utils");
describe.skip('handle is visible', () => {
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 - webkit', async () => {
// Given
browser = await playwright_1.webkit.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#hidden');
// When
const result = await SUT.isHandleVisible(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return true when selector is visible', async () => {
// Given
browser = await playwright_1.webkit.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#visible');
// When
const result = await SUT.isHandleVisible(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.webkit.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#transparent');
// When
const result = await SUT.isHandleVisible(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.webkit.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#out-of-screen');
// When
const result = await SUT.isHandleVisible(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return true when selector is visible but out of viewport', async () => {
// Given
browser = await playwright_1.webkit.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#out-of-viewport');
// When
const result = await SUT.isHandleVisible(handle, is_handle_visible_1.defaultVerboseOptions);
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test.skip('should return 1 when selector is in viewport - issue playwright headless', async () => {
// Given
browser = await playwright_1.webkit.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#visible');
// When
const visibleRatio = await (0, get_intersection_ratio_of_handle_1.getIntersectionRatioOfHandle)(handle);
// eslint-disable-next-line no-console
console.log(`visible ratio is ${visibleRatio}`);
const windowState = await (0, page_actions_1.getWindowState)(page);
// eslint-disable-next-line no-console
console.log(`windowState:\n ${JSON.stringify(windowState, null, 2)}`);
// Then
expect(handle).toBeDefined();
expect(visibleRatio).toBe(1);
});
test.skip('should return 1 when selector is in viewport - issue playwright headfull', async () => {
// Given
browser = await playwright_1.webkit.launch({ headless: false });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
const url = `file:${path.join(__dirname, 'is-handle-visible.test.html')}`;
await page.goto(url);
await (0, utils_1.sleep)(1000);
const handle = await page.$('#visible');
// When
const visibleRatio = await (0, get_intersection_ratio_of_handle_1.getIntersectionRatioOfHandle)(handle);
// eslint-disable-next-line no-console
console.log(`visible ratio is ${visibleRatio}`);
const windowState = await (0, page_actions_1.getWindowState)(page);
// eslint-disable-next-line no-console
console.log(`windowState:\n ${JSON.stringify(windowState, null, 2)}`);
// Then
expect(handle).toBeDefined();
expect(visibleRatio).toBe(1);
});
});
;