playwright-fluent
Version:
Fluent API around playwright
174 lines (173 loc) • 6.02 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 - click', () => {
let p;
beforeEach(() => {
p = new SUT.PlaywrightFluent();
});
afterEach(async () => {
await p.close();
});
test('should wait until selector is enabled - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = '#dynamically-added-input';
// When
// prettier-ignore
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(selector);
// Then
await p
.expectThat(selector)
//.isVisibleInViewport()
.isVisible()
.expectThat(selector)
.isEnabled()
.expectThat(selector)
.hasFocus();
const hasFocus = await p.hasFocus(selector);
expect(hasFocus).toBe(true);
});
test('should wait until selector object is enabled - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = p.selector('input#dynamically-added-input');
// When
// prettier-ignore
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(selector);
// Then
await p
.expectThat(selector)
//.isVisibleInViewport()
.isVisible()
.expectThat(selector)
.isEnabled()
.expectThat(selector)
.hasFocus();
const hasFocus = await p.hasFocus(selector);
expect(hasFocus).toBe(true);
});
test('should not click on a non existing selector - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = 'foobar';
// When
let result = undefined;
try {
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Selector 'foobar' was not found in DOM");
});
test('should not click on a non existing selector object - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = p.selector('foobar');
// When
let result = undefined;
try {
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Cannot click on 'selector(foobar)' because this selector was not found in DOM");
});
test('should not click on a hidden selector - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = '#hidden';
// When
let result = undefined;
try {
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(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 click on a disabled selector - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = '#disabled';
// When
let result = undefined;
try {
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
expect(result && result.message).toContain("Cannot click on '#disabled' because this selector is disabled");
});
test('should not click on a disabled selector object - msedge', async () => {
// Given
const url = `file:${path.join(__dirname, 'click.test.html')}`;
const selector = p.selector('input').withValue('I am disabled');
// When
let result = undefined;
try {
await p
.withBrowser('msedge')
.withCursor()
.navigateTo(url)
.click(selector, { timeoutInMilliseconds: 2000 });
}
catch (error) {
result = error;
}
// Then
const errorMessage = `Cannot click on 'selector(input)
.withValue(I am disabled)' because this selector is disabled`;
expect(result && result.message).toContain(errorMessage);
});
test('should click - msedge', 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('msedge')
.withCursor()
.emulateDevice('iPhone 6 landscape')
.navigateTo(url)
.switchToIframe(storyBookIframe)
.click(checkMeOut)
.expectThatSelector(checkMeOut)
.hasFocus();
});
});
;