playwright-fluent
Version:
Fluent API around playwright
94 lines (93 loc) • 3.37 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 - isEnabled', () => {
let p;
beforeEach(() => {
p = new SUT.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should return false on wrong selector', async () => {
// Given
const url = `file:${path.join(__dirname, 'is-enabled.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
// When
const selector = p.selector('input').withValue('foo');
const result = await selector.isEnabled();
// Then
expect(result).toBe(false);
});
test('should return true when selector is enabled', async () => {
// Given
const url = `file:${path.join(__dirname, 'is-enabled.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
// When
const selector = p.selector('input').withValue('I am enabled');
const result = await selector.isEnabled();
// Then
expect(result).toBe(true);
});
test('should return true when selector is enabled #2', async () => {
// Given
const url = `file:${path.join(__dirname, 'is-enabled.test.html')}`;
// create selector before browser is launched
const selector = p.selector('input').withValue('I am enabled');
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
// When
const result = await selector.isEnabled();
// Then
expect(result).toBe(true);
});
test('should return false when selector is disabled', async () => {
// Given
const url = `file:${path.join(__dirname, 'is-enabled.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
// When
const selector = p.selector('input').withValue('I am disabled');
const result = await selector.isEnabled();
// Then
expect(result).toBe(false);
});
test('should wait for selector to be enabled', async () => {
// Given
const url = `file:${path.join(__dirname, 'is-enabled.test.html')}`;
// prettier-ignore
await p
.withBrowser('chromium')
.withOptions({ headless: true })
.withCursor()
.navigateTo(url);
const selector = p.selector('input#disabled-then-enabled-input');
const initialEnabledStatus = await selector.isEnabled();
// When
await p.waitUntil(() => selector.isEnabled());
const finalEnabledStatus = await selector.isEnabled();
// Then
expect(initialEnabledStatus).toBe(false);
expect(finalEnabledStatus).toBe(true);
});
});
;