UNPKG

playwright-fluent

Version:
180 lines (179 loc) 6.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const SUT = tslib_1.__importStar(require("../../../fluent-api")); describe('Selector API - isNotVisible', () => { let p; beforeEach(() => { p = new SUT.PlaywrightFluent(); }); afterEach(async () => { await p.close(); }); test('should return true on wrong selector', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor().navigateTo(url); // When const selector = p.selector('foo').withText('bar'); const result = await selector.isNotVisible(); // Then expect(result).toBe(true); }); test('should return false when selector is visible', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('p') .withText('I am visible'); const result = await selector.isNotVisible(); // Then expect(result).toBe(false); }); test('should return false when selector is visible but out of viewport', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When const selector = p.selector('p').withText('I am out of viewport'); const result = await selector.isNotVisible(); // Then expect(result).toBe(false); }); test('should return true when selector is hidden', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('p') .withText('I am hidden'); const result = await selector.isNotVisible(); // Then expect(result).toBe(true); }); test('should return true when selector is transparent', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('p') .withText('I am transparent'); const result = await selector.isNotVisible(); // Then expect(result).toBe(true); }); test('should return true when selector is out of screen', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When // prettier-ignore const selector = p .selector('[role="row"]') .find('p') .withText('I am out of screen'); const result = await selector.isNotVisible(); // Then expect(result).toBe(true); }); test('should return true when selector is first hidden', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When const selector = p .selector('[role="row"]') .find('td') .withText('hidden, then visible') .find('p'); //only the <p> ... </p> element is hidden first const initialVisibleStatus = await selector.isNotVisible(); await p.wait(5000); const finalVisibleStatus = await selector.isNotVisible(); // Then expect(initialVisibleStatus).toBe(true); expect(finalVisibleStatus).toBe(false); }); test('should use some waiting mechanism to wait for selector to be visible', async () => { // Given const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When const selector = p.selector('p').withText('I am dynamically added'); const initialVisibleStatus = await selector.isNotVisible(); // await p.waitUntil(() => selector.isNotVisible(), { verbose: true }); await p.wait(6000); const finalVisibleStatus = await selector.isNotVisible(); // Then expect(initialVisibleStatus).toBe(true); expect(finalVisibleStatus).toBe(false); }); test('should return false when selector is visible but the selector-fluent is created before page is instanciated', async () => { // Given // prettier-ignore const selector = p .selector('[role="row"]') .find('p') .withText('I am visible'); const url = `file:${path.join(__dirname, 'is-not-visible.test.html')}`; // prettier-ignore await p .withBrowser('chromium') .withOptions({ headless: true }) .withCursor() .navigateTo(url); // When const result = await selector.isNotVisible(); // Then expect(result).toBe(false); }); });