playwright-fluent
Version:
Fluent API around playwright
207 lines (206 loc) • 7.64 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"));
describe('Playwright Fluent - uncheck', () => {
let p;
beforeEach(() => {
p = new SUT.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should wait until selector is enabled - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = '#dynamically-added-input';
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector);
// Then
const isUnchecked = await p.isUnchecked(selector);
expect(isUnchecked).toBe(true);
// And
await p.expectThatSelector(selector).isUnchecked();
});
test('should wait until selector object is enabled - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = p.selector('input#dynamically-added-input');
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector);
// Then
await p.expectThat(selector).isUnchecked();
const isUnchecked = await selector.isUnchecked();
expect(isUnchecked).toBe(true);
});
test('should do nothing when selector is already unchecked - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = '#unchecked-and-disabled';
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector);
// Then
const isUnchecked = await p.isUnchecked(selector);
expect(isUnchecked).toBe(true);
// And
await p.expectThatSelector(selector).isUnchecked();
});
test('should do nothing when selector object is already unchecked - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = p.selector('input').withValue('I am unchecked and disabled');
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector);
// Then
const isUnchecked = await selector.isUnchecked();
expect(isUnchecked).toBe(true);
// And
await p.expectThatSelector(selector).isUnchecked();
});
test('should not uncheck a non existing selector - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = 'foobar';
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Selector 'foobar' was not found in DOM");
});
test('should not uncheck a non existing selector object - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = p.selector('foobar');
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Cannot uncheck 'selector(foobar)' because this selector was not found in DOM");
});
test('should not uncheck a hidden selector - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = '#hidden';
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Cannot hover on '#hidden' because this selector is not visible");
});
test('should not uncheck a disabled selector - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = '#disabled';
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Cannot uncheck '#disabled' because this selector is disabled");
});
test('should not uncheck a disabled selector object - chromium', async () => {
// Given
const url = `file:${path.join(__dirname, 'uncheck.test.html')}`;
const selector = p.selector('input').withValue('I am disabled');
// When
let result = undefined;
try {
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.navigateTo(url)
.uncheck(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
const errorMessage = `Cannot uncheck 'selector(input)
.withValue(I am disabled)' because this selector is disabled`;
expect(result && result.message).toContain(errorMessage);
});
test('should uncheck - chromium', async () => {
// Given
const url = 'https://reactstrap.github.io/?path=/docs/components-forms--input';
const checkMeOut = p.selector('label').withText('Check me out').parent().find('input');
const storyBookIframe = 'iframe#storybook-preview-iframe';
// When
await p
.withBrowser('chromium')
.withOptions({ headless: false })
.withCursor()
.emulateDevice('iPhone 6 landscape')
.navigateTo(url)
.switchToIframe(storyBookIframe)
.check(checkMeOut)
.expectThatSelector(checkMeOut)
.isChecked()
.uncheck(checkMeOut)
.expectThatSelector(checkMeOut)
.isUnchecked();
// Then
expect(await checkMeOut.isUnchecked()).toBe(true);
expect(await checkMeOut.isChecked()).toBe(false);
});
});
;