playwright-fluent
Version:
Fluent API around playwright
123 lines (122 loc) • 4.25 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("../../../fluent-api"));
describe('Selector API - doesNotExist', () => {
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, 'doesNotExist.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.doesNotExist();
// Then
expect(result).toBe(true);
});
test('should return false when selector is visible', async () => {
// Given
const url = `file:${path.join(__dirname, 'doesNotExist.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.doesNotExist();
// Then
expect(result).toBe(false);
});
test('should return false when selector is hidden', async () => {
// Given
const url = `file:${path.join(__dirname, 'doesNotExist.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.doesNotExist();
// Then
expect(result).toBe(false);
});
test('should return false when selector is transparent', async () => {
// Given
const url = `file:${path.join(__dirname, 'doesNotExist.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.doesNotExist();
// Then
expect(result).toBe(false);
});
test('should return false when selector is out of screen', async () => {
// Given
const url = `file:${path.join(__dirname, 'doesNotExist.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.doesNotExist();
// Then
expect(result).toBe(false);
});
test('should wait for selector to be removed from DOM', async () => {
// Given
const url = `file:${path.join(__dirname, 'doesNotExist.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor().navigateTo(url);
// When
const selector = p.selector('p').withText('I am visible and will be removed');
const initialRemovedStatus = await selector.doesNotExist();
await p.waitUntil(() => selector.doesNotExist());
const finalRemovedStatus = await selector.doesNotExist();
// Then
expect(initialRemovedStatus).toBe(false);
expect(finalRemovedStatus).toBe(true);
});
});
;