Skip to content

Commit

Permalink
Add ChainablePromiseArray to signatures (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Yevhen Laichenkov <elaichenkov@gmail.com>
  • Loading branch information
rohantalkad747 and elaichenkov authored Oct 14, 2021
1 parent 46d479c commit bdf912b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/element/numberOfElementsToBe.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { getElements } from './../utils';
import type { ChainablePromiseArray } from 'webdriverio';

/**
* A condition for checking number of elements with given selector
*
* @example
* browser.waitUntil(numberOfElementsToBe('a', 4));
*
* @param {!string | WebdriverIO.ElementArray} selectorOrElementArray The selector or elements array to check
* @param {!string | ChainablePromiseArray<WebdriverIO.ElementArray>} selectorOrElementArray The selector or elements array to check
* @param {!number} expectedNumber The selector to check
*
* @returns {!function} An expected condition that returns a promise
* representing whether the element length.
*/

export function numberOfElementsToBe(
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
selectorOrElementArray: string | ChainablePromiseArray<WebdriverIO.ElementArray>,
expectedNumber: number,
): () => Promise<boolean> {
return async function (): Promise<boolean> {
Expand Down
5 changes: 3 additions & 2 deletions src/element/numberOfElementsToBeLessThan.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { getElements } from './../utils';
import type { ChainablePromiseArray } from 'webdriverio';

/**
* A condition for checking number of elements with given selector being less than defined number
*
* @example
* browser.waitUntil(numberOfElementsToBeLessThan('a', 2));
*
* @param {!string | WebdriverIO.ElementArray} selectorOrElementArray The selector or elements array to check
* @param {!string | ChainablePromiseArray<WebdriverIO.ElementArray>} selectorOrElementArray The selector or elements array to check
* @param {!number} expectedNumber The selector to check
*
* @returns {!function} An expected condition that returns a promise
* representing whether the element length is less than defined number.
*/

export function numberOfElementsToBeLessThan(
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
selectorOrElementArray: string | ChainablePromiseArray<WebdriverIO.ElementArray>,
expectedNumber: number,
): () => Promise<boolean> {
return async function (): Promise<boolean> {
Expand Down
5 changes: 3 additions & 2 deletions src/element/numberOfElementsToBeMoreThan​.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { getElements } from './../utils';
import type { ChainablePromiseArray } from 'webdriverio';

/**
* A condition for checking number of elements with given selector being more than defined number
*
* @example
* browser.waitUntil(numberOfElementsToBeMoreThan​('a', 4));
*
* @param {!string | WebdriverIO.ElementArray} selectorOrElementArray The selector or elements array to check
* @param {!string | ChainablePromiseArray<WebdriverIO.ElementArray>} selectorOrElementArray The selector or elements array to check
* @param {!number} expectedNumber The selector to check
*
* @returns {!function} An expected condition that returns a promise
* representing whether the element length is greater than defined number.
*/

export function numberOfElementsToBeMoreThan(
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
selectorOrElementArray: string | ChainablePromiseArray<WebdriverIO.ElementArray>,
expectedNumber: number,
): () => Promise<boolean> {
return async function (): Promise<boolean> {
Expand Down
10 changes: 6 additions & 4 deletions src/utils/getElements.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const getElements = async (
selectorOrElementArray: string | Promise<WebdriverIO.ElementArray>,
): Promise<WebdriverIO.ElementArray> => {
return typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray;
import type { ChainablePromiseArray } from 'webdriverio';

export const getElements = (
selectorOrElementArray: string | ChainablePromiseArray<WebdriverIO.ElementArray>,
): ChainablePromiseArray<WebdriverIO.ElementArray> => {
return typeof selectorOrElementArray === 'string' ? $$(selectorOrElementArray) : selectorOrElementArray;
};

0 comments on commit bdf912b

Please sign in to comment.