playwright-fluent
Version:
Fluent API around playwright
151 lines (150 loc) • 6.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("path"));
const SUT = tslib_1.__importStar(require("../../playwright-fluent"));
const utils_1 = require("../../../utils");
describe('Playwright Fluent - expectThat isNotVisibleInViewport()', () => {
let p;
beforeEach(() => {
p = new SUT.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should give back an error when selector is visible in the current viewport', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
const selector = '#visible';
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport({ timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Selector '#visible' is visible in the current viewport.");
});
test('should give back an error when selector object is visible in the current viewport', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
// prettier-ignore
const selector = p
.selector('p')
.withText('I am visible')
.nth(1);
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport({ timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
const errorMessage = `Selector 'selector(p)
.withText(I am visible)
.nth(1)' is visible in the current viewport.`;
expect(result && result.message).toContain(errorMessage);
});
test('should wait until selector is hidden - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
const selector = '#visible-then-hidden';
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport();
// Then
const isNotVisible = await p.isNotVisibleInViewport(selector, utils_1.noWaitNoThrowOptions);
expect(isNotVisible).toBe(true);
});
test('should wait until selector object is hidden - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
const selector = p.selector('p').withText('I am visible then hidden');
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport();
// Then
const isNotVisible = await p.isNotVisibleInViewport(selector, utils_1.noWaitNoThrowOptions);
expect(isNotVisible).toBe(true);
});
test('should wait until selector is removed - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
const selector = '#visible-then-removed';
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport();
// Then
const isNotVisible = await p.isNotVisibleInViewport(selector, utils_1.noWaitNoThrowOptions);
expect(isNotVisible).toBe(true);
});
test('should wait until selector object is removed - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
const selector = p.selector('p').withText('I am visible then removed from DOM');
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport();
// Then
const isNotVisible = await p.isNotVisibleInViewport(selector, utils_1.noWaitNoThrowOptions);
expect(isNotVisible).toBe(true);
});
test('should check that selector is visible but out of viewport - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'expect-is-not-visible-in-viewport.test.html')}`;
const selector = p.selector('p').withText('I am out of viewport');
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.expectThatSelector(selector)
.isNotVisibleInViewport()
.expectThatSelector(selector)
.isVisible();
// Then
const isNotVisibleInViewport = await p.isNotVisibleInViewport(selector, utils_1.noWaitNoThrowOptions);
expect(isNotVisibleInViewport).toBe(true);
const isVisibleInViewport = await p.isVisibleInViewport(selector, utils_1.noWaitNoThrowOptions);
expect(isVisibleInViewport).toBe(false);
const isNotVisible = await p.isNotVisible(selector, utils_1.noWaitNoThrowOptions);
expect(isNotVisible).toBe(false);
});
});
;