playwright-fluent
Version:
Fluent API around playwright
48 lines (47 loc) • 2.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 dom_actions_1 = require("../../../dom-actions");
const handle_actions_1 = require("../../../handle-actions");
describe('click at position', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should click at position - chromium', async () => {
// Given
browser = await playwright_1.chromium.launch({ headless: true });
const browserContext = await browser.newContext({ viewport: null });
const page = await browserContext.newPage();
await (0, dom_actions_1.showMousePosition)(page);
const url = `file:${path.join(__dirname, 'click-at-position.test.html')}`;
await page.goto(url);
const inputSelector = '#flexSwitchCheckChecked';
const switchContainer = '#switch-container';
const clientRectangle = await (0, dom_actions_1.getClientRectangleOf)(switchContainer, page);
const xCenter = clientRectangle.left + clientRectangle.width / 2;
const yCenter = clientRectangle.top + clientRectangle.height / 2;
const xLeft = clientRectangle.left;
const input = await page.$(inputSelector);
const options = {
...handle_actions_1.defaultClickOptions,
};
// Given switch is off
expect(await (input === null || input === void 0 ? void 0 : input.isChecked())).toBe(false);
// When I click at the center of switch container
await SUT.clickAtPosition({ x: xCenter, y: yCenter }, page, options);
// Then switch is still off (because the click was outside the label)
expect(await (input === null || input === void 0 ? void 0 : input.isChecked())).toBe(false);
// When I click at the left of the switch container
await SUT.clickAtPosition({ x: xLeft + 10, y: yCenter }, page, options);
// Then
expect(await (input === null || input === void 0 ? void 0 : input.isChecked())).toBe(true);
});
});
;