Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/5 multiremote support #6

Merged
merged 7 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ jobs:

- name: Run tests
run: npm test

- name: Run multiremote tests
run: npm run test:multiremote
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"release:patch": "npm run release -- patch",
"release:minor": "npm run release -- minor",
"release:major": "npm run release -- major",
"test": "npx wdio run tests/wdio.conf.ts"
"test": "npx wdio run tests/wdio.conf.ts",
"test:multiremote": "npx wdio run tests/wdio.multiremote.conf.ts"
},
"repository": {
"type": "git",
Expand Down
6 changes: 4 additions & 2 deletions src/browser/alertIsPresent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Browser } from 'webdriverio';

/**
* A condition for checking an alert on the page
*
Expand All @@ -9,7 +11,7 @@
*/

export function alertIsPresent(): () => Promise<boolean> {
return async (): Promise<boolean> => {
return await browser.isAlertOpen();
return async function (this: Browser<'async'>): Promise<boolean> {
return await this.isAlertOpen();
};
}
6 changes: 4 additions & 2 deletions src/browser/numberOfWindowsToBe​.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Browser } from 'webdriverio';

/**
* A condition for checking the number of opened windows.
*
Expand All @@ -10,8 +12,8 @@
*/

export function numberOfWindowsToBe(expectedNumber: number): () => Promise<boolean> {
return async (): Promise<boolean> => {
const actualWindows = await browser.getWindowHandles();
return async function (this: Browser<'async'>): Promise<boolean> {
const actualWindows = await this.getWindowHandles();

return actualWindows.length === expectedNumber;
};
Expand Down
6 changes: 4 additions & 2 deletions src/browser/titleContains.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Browser } from 'webdriverio';

/**
* A condition for checking that the title contains a case-sensitive substring
*
Expand All @@ -10,8 +12,8 @@
*/

export function titleContains(expectedTitle: string): () => Promise<boolean> {
return async (): Promise<boolean> => {
const actualTitle = await browser.getTitle();
return async function (this: Browser<'async'>): Promise<boolean> {
const actualTitle = await this.getTitle();

return actualTitle.includes(expectedTitle);
};
Expand Down
6 changes: 4 additions & 2 deletions src/browser/titleIs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Browser } from 'webdriverio';

/**
* A condition for checking the title of a page
*
Expand All @@ -10,8 +12,8 @@
*/

export function titleIs(expectedTitle: string): () => Promise<boolean> {
return async (): Promise<boolean> => {
const actualTitle = await browser.getTitle();
return async function (this: Browser<'async'>): Promise<boolean> {
const actualTitle = await this.getTitle();

return actualTitle === expectedTitle;
};
Expand Down
6 changes: 4 additions & 2 deletions src/browser/urlContains.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Browser } from 'webdriverio';

/**
* A condition for checking the URL of the current page to contain specific text.
*
Expand All @@ -10,8 +12,8 @@
*/

export function urlContains(expectedUrl: string): () => Promise<boolean> {
return async (): Promise<boolean> => {
const actualUrl = await browser.getUrl();
return async function (this: Browser<'async'>): Promise<boolean> {
const actualUrl = await this.getUrl();

return actualUrl.includes(expectedUrl);
};
Expand Down
6 changes: 4 additions & 2 deletions src/browser/urlIs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Browser } from 'webdriverio';

/**
* A condition for checking URL of the current page to be a specific url.
*
Expand All @@ -10,8 +12,8 @@
*/

export function urlIs(expectedUrl: string): () => Promise<boolean> {
return async (): Promise<boolean> => {
const actualUrl = await browser.getUrl();
return async function (this: Browser<'async'>): Promise<boolean> {
const actualUrl = await this.getUrl();

return actualUrl === expectedUrl;
};
Expand Down
6 changes: 4 additions & 2 deletions src/element/elementToBeClickable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking an element is visible and clickable
*
Expand All @@ -11,8 +13,8 @@
*/

export function elementToBeClickable(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
return async function (): Promise<boolean> {
const element = await getElement(selectorOrElement);

return await element.isClickable();
};
Expand Down
6 changes: 4 additions & 2 deletions src/element/elementToBeEnabled.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking an element is visible and enabled such that you can click it
*
Expand All @@ -11,8 +13,8 @@
*/

export function elementToBeEnabled(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
return async function (): Promise<boolean> {
const element = await getElement(selectorOrElement);

return await element.isEnabled();
};
Expand Down
6 changes: 4 additions & 2 deletions src/element/elementToBeSelected.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking an element is visible and selected
*
Expand All @@ -11,8 +13,8 @@
*/

export function elementToBeSelected(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
return async function (): Promise<boolean> {
const element = await getElement(selectorOrElement);

return await element.isSelected();
};
Expand Down
6 changes: 4 additions & 2 deletions src/element/invisibilityOf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking the element to be invisible
*
Expand All @@ -11,9 +13,9 @@
*/

export function invisibilityOf(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
return async function (): Promise<boolean> {
try {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
const element = await getElement(selectorOrElement);
const isVisible = await element.isDisplayed();

return !isVisible;
Expand Down
7 changes: 4 additions & 3 deletions src/element/numberOfElementsToBe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElements } from './../utils';

/**
* A condition for checking number of elements with given selector
*
Expand All @@ -15,9 +17,8 @@ export function numberOfElementsToBe(
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
expectedNumber: number,
): () => Promise<boolean> {
return async (): Promise<boolean> => {
const elements =
typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray;
return async function (): Promise<boolean> {
const elements = await getElements(selectorOrElementArray);

return elements.length === expectedNumber;
};
Expand Down
7 changes: 4 additions & 3 deletions src/element/numberOfElementsToBeLessThan.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElements } from './../utils';

/**
* A condition for checking number of elements with given selector being less than defined number
*
Expand All @@ -15,9 +17,8 @@ export function numberOfElementsToBeLessThan(
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
expectedNumber: number,
): () => Promise<boolean> {
return async (): Promise<boolean> => {
const elements =
typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray;
return async function (): Promise<boolean> {
const elements = await getElements(selectorOrElementArray);

return elements.length < expectedNumber;
};
Expand Down
7 changes: 4 additions & 3 deletions src/element/numberOfElementsToBeMoreThan​.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElements } from './../utils';

/**
* A condition for checking number of elements with given selector being more than defined number
*
Expand All @@ -15,9 +17,8 @@ export function numberOfElementsToBeMoreThan(
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
expectedNumber: number,
): () => Promise<boolean> {
return async (): Promise<boolean> => {
const elements =
typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray;
return async function (): Promise<boolean> {
const elements = await getElements(selectorOrElementArray);

return elements.length > expectedNumber;
};
Expand Down
6 changes: 4 additions & 2 deletions src/element/presenceOf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking that an element is present on the DOM of a page
*
Expand All @@ -11,9 +13,9 @@
*/

export function presenceOf(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
return async function (): Promise<boolean> {
try {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
const element = await getElement(selectorOrElement);
const isVisible = await element.isExisting();

return isVisible;
Expand Down
6 changes: 4 additions & 2 deletions src/element/sizeOfElementToBe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking size of element with given selector
*
Expand All @@ -15,8 +17,8 @@ export function sizeOfElementsToBe(
selectorOrElement: string | Promise<WebdriverIO.Element>,
expectedSize: { width: number; height: number },
): () => Promise<boolean> {
return async (): Promise<boolean> => {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
return async function (): Promise<boolean> {
const element = await getElement(selectorOrElement);
const actualSize = await element.getSize();

return actualSize.width === expectedSize.width && actualSize.height === expectedSize.height;
Expand Down
6 changes: 4 additions & 2 deletions src/element/stalenessOf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking that an element is not present on the DOM of a page
*
Expand All @@ -11,9 +13,9 @@
*/

export function stalenessOf(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
return async function (): Promise<boolean> {
try {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
const element = await getElement(selectorOrElement);
const isVisible = await element.isExisting();

return !isVisible;
Expand Down
6 changes: 4 additions & 2 deletions src/element/textToBePresentInElement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking an element contains a specific text
*
Expand All @@ -15,8 +17,8 @@ export function textToBePresentInElement(
selectorOrElement: string | Promise<WebdriverIO.Element>,
expectedText: string,
): () => Promise<boolean> {
return async (): Promise<boolean> => {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
return async function (): Promise<boolean> {
const element = await getElement(selectorOrElement);
const text = await element.getText();

return text.includes(expectedText);
Expand Down
6 changes: 4 additions & 2 deletions src/element/textToBePresentInElementValue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking an element contains a specific value
*
Expand All @@ -15,8 +17,8 @@ export function textToBePresentInElementValue(
selectorOrElement: string | Promise<WebdriverIO.Element>,
expectedValue: string,
): () => Promise<boolean> {
return async (): Promise<boolean> => {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
return async function (): Promise<boolean> {
const element = await getElement(selectorOrElement);
const value = await element.getValue();

return value.includes(expectedValue);
Expand Down
6 changes: 4 additions & 2 deletions src/element/visibilityOf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getElement } from './../utils';

/**
* A condition for checking the element to be visible
*
Expand All @@ -11,9 +13,9 @@
*/

export function visibilityOf(selectorOrElement: string | Promise<WebdriverIO.Element>): () => Promise<boolean> {
return async (): Promise<boolean> => {
return async function (): Promise<boolean> {
try {
const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
const element = await getElement(selectorOrElement);
const isVisible = await element.isDisplayed();

return isVisible;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/getElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getElement = async (
selectorOrElement: string | Promise<WebdriverIO.Element>,
): Promise<WebdriverIO.Element> => {
return typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement;
};
5 changes: 5 additions & 0 deletions src/utils/getElements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getElements = async (
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
): Promise<WebdriverIO.ElementArray> => {
return typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray;
};
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './getElement';
export * from './getElements';
4 changes: 2 additions & 2 deletions tests/browser/alertIsPresent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ describe('alertIsPresent', () => {
it('should verify that method returns true when element is clickable', async () => {
await browser.execute('alert("Alert");');

expect(await alertIsPresent()()).toBe(true);
expect(await alertIsPresent().call(browser)).toBe(true);
});

it('should verify that method returns false when alert is not present', async () => {
expect(await alertIsPresent()()).toBe(false);
expect(await alertIsPresent().call(browser)).toBe(false);
});
});
4 changes: 2 additions & 2 deletions tests/browser/numberOfWindowsToBe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ describe('numberOfWindowsToBe', () => {
const link = await $('.large-centered a');
await link.click();

expect(await numberOfWindowsToBe(2)()).toBe(true);
expect(await numberOfWindowsToBe(2).call(browser)).toBe(true);
});

it('should verify that method returns false when number of windows not to be', async () => {
await browser.closeWindow();

expect(await numberOfWindowsToBe(2)()).toBe(false);
expect(await numberOfWindowsToBe(2).call(browser)).toBe(false);
});
});
Loading