diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7b559199..0dd8cdeb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,3 +33,6 @@ jobs: - name: Run tests run: npm test + + - name: Run multiremote tests + run: npm run test:multiremote \ No newline at end of file diff --git a/package.json b/package.json index 041002ba..cf80c30e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/browser/alertIsPresent.ts b/src/browser/alertIsPresent.ts index 908a3be1..79640323 100644 --- a/src/browser/alertIsPresent.ts +++ b/src/browser/alertIsPresent.ts @@ -1,3 +1,5 @@ +import type { Browser } from 'webdriverio'; + /** * A condition for checking an alert on the page * @@ -9,7 +11,7 @@ */ export function alertIsPresent(): () => Promise { - return async (): Promise => { - return await browser.isAlertOpen(); + return async function (this: Browser<'async'>): Promise { + return await this.isAlertOpen(); }; } diff --git "a/src/browser/numberOfWindowsToBe\342\200\213.ts" "b/src/browser/numberOfWindowsToBe\342\200\213.ts" index 5827a9b9..08460f28 100644 --- "a/src/browser/numberOfWindowsToBe\342\200\213.ts" +++ "b/src/browser/numberOfWindowsToBe\342\200\213.ts" @@ -1,3 +1,5 @@ +import type { Browser } from 'webdriverio'; + /** * A condition for checking the number of opened windows. * @@ -10,8 +12,8 @@ */ export function numberOfWindowsToBe(expectedNumber: number): () => Promise { - return async (): Promise => { - const actualWindows = await browser.getWindowHandles(); + return async function (this: Browser<'async'>): Promise { + const actualWindows = await this.getWindowHandles(); return actualWindows.length === expectedNumber; }; diff --git a/src/browser/titleContains.ts b/src/browser/titleContains.ts index 2c30141b..3802968c 100644 --- a/src/browser/titleContains.ts +++ b/src/browser/titleContains.ts @@ -1,3 +1,5 @@ +import type { Browser } from 'webdriverio'; + /** * A condition for checking that the title contains a case-sensitive substring * @@ -10,8 +12,8 @@ */ export function titleContains(expectedTitle: string): () => Promise { - return async (): Promise => { - const actualTitle = await browser.getTitle(); + return async function (this: Browser<'async'>): Promise { + const actualTitle = await this.getTitle(); return actualTitle.includes(expectedTitle); }; diff --git a/src/browser/titleIs.ts b/src/browser/titleIs.ts index 40e54286..f224c04d 100644 --- a/src/browser/titleIs.ts +++ b/src/browser/titleIs.ts @@ -1,3 +1,5 @@ +import type { Browser } from 'webdriverio'; + /** * A condition for checking the title of a page * @@ -10,8 +12,8 @@ */ export function titleIs(expectedTitle: string): () => Promise { - return async (): Promise => { - const actualTitle = await browser.getTitle(); + return async function (this: Browser<'async'>): Promise { + const actualTitle = await this.getTitle(); return actualTitle === expectedTitle; }; diff --git a/src/browser/urlContains.ts b/src/browser/urlContains.ts index 29a5db27..5f008275 100644 --- a/src/browser/urlContains.ts +++ b/src/browser/urlContains.ts @@ -1,3 +1,5 @@ +import type { Browser } from 'webdriverio'; + /** * A condition for checking the URL of the current page to contain specific text. * @@ -10,8 +12,8 @@ */ export function urlContains(expectedUrl: string): () => Promise { - return async (): Promise => { - const actualUrl = await browser.getUrl(); + return async function (this: Browser<'async'>): Promise { + const actualUrl = await this.getUrl(); return actualUrl.includes(expectedUrl); }; diff --git a/src/browser/urlIs.ts b/src/browser/urlIs.ts index 1b04ebe0..2035591c 100644 --- a/src/browser/urlIs.ts +++ b/src/browser/urlIs.ts @@ -1,3 +1,5 @@ +import type { Browser } from 'webdriverio'; + /** * A condition for checking URL of the current page to be a specific url. * @@ -10,8 +12,8 @@ */ export function urlIs(expectedUrl: string): () => Promise { - return async (): Promise => { - const actualUrl = await browser.getUrl(); + return async function (this: Browser<'async'>): Promise { + const actualUrl = await this.getUrl(); return actualUrl === expectedUrl; }; diff --git a/src/element/elementToBeClickable.ts b/src/element/elementToBeClickable.ts index a2cead46..795c7fd4 100644 --- a/src/element/elementToBeClickable.ts +++ b/src/element/elementToBeClickable.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking an element is visible and clickable * @@ -11,8 +13,8 @@ */ export function elementToBeClickable(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + return async function (): Promise { + const element = await getElement(selectorOrElement); return await element.isClickable(); }; diff --git a/src/element/elementToBeEnabled.ts b/src/element/elementToBeEnabled.ts index 4dfb36d1..eddce8e2 100644 --- a/src/element/elementToBeEnabled.ts +++ b/src/element/elementToBeEnabled.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking an element is visible and enabled such that you can click it * @@ -11,8 +13,8 @@ */ export function elementToBeEnabled(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + return async function (): Promise { + const element = await getElement(selectorOrElement); return await element.isEnabled(); }; diff --git a/src/element/elementToBeSelected.ts b/src/element/elementToBeSelected.ts index 3583989d..21ea88ab 100644 --- a/src/element/elementToBeSelected.ts +++ b/src/element/elementToBeSelected.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking an element is visible and selected * @@ -11,8 +13,8 @@ */ export function elementToBeSelected(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + return async function (): Promise { + const element = await getElement(selectorOrElement); return await element.isSelected(); }; diff --git a/src/element/invisibilityOf.ts b/src/element/invisibilityOf.ts index a8f8f1ff..b16232a3 100644 --- a/src/element/invisibilityOf.ts +++ b/src/element/invisibilityOf.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking the element to be invisible * @@ -11,9 +13,9 @@ */ export function invisibilityOf(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { + return async function (): Promise { try { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + const element = await getElement(selectorOrElement); const isVisible = await element.isDisplayed(); return !isVisible; diff --git a/src/element/numberOfElementsToBe.ts b/src/element/numberOfElementsToBe.ts index a16f3845..7454460f 100644 --- a/src/element/numberOfElementsToBe.ts +++ b/src/element/numberOfElementsToBe.ts @@ -1,3 +1,5 @@ +import { getElements } from './../utils'; + /** * A condition for checking number of elements with given selector * @@ -15,9 +17,8 @@ export function numberOfElementsToBe( selectorOrElementArray: string | Promise, expectedNumber: number, ): () => Promise { - return async (): Promise => { - const elements = - typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray; + return async function (): Promise { + const elements = await getElements(selectorOrElementArray); return elements.length === expectedNumber; }; diff --git a/src/element/numberOfElementsToBeLessThan.ts b/src/element/numberOfElementsToBeLessThan.ts index 5f3378fd..5cecbb10 100644 --- a/src/element/numberOfElementsToBeLessThan.ts +++ b/src/element/numberOfElementsToBeLessThan.ts @@ -1,3 +1,5 @@ +import { getElements } from './../utils'; + /** * A condition for checking number of elements with given selector being less than defined number * @@ -15,9 +17,8 @@ export function numberOfElementsToBeLessThan( selectorOrElementArray: string | Promise, expectedNumber: number, ): () => Promise { - return async (): Promise => { - const elements = - typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray; + return async function (): Promise { + const elements = await getElements(selectorOrElementArray); return elements.length < expectedNumber; }; diff --git "a/src/element/numberOfElementsToBeMoreThan\342\200\213.ts" "b/src/element/numberOfElementsToBeMoreThan\342\200\213.ts" index d41f1a94..94d400b7 100644 --- "a/src/element/numberOfElementsToBeMoreThan\342\200\213.ts" +++ "b/src/element/numberOfElementsToBeMoreThan\342\200\213.ts" @@ -1,3 +1,5 @@ +import { getElements } from './../utils'; + /** * A condition for checking number of elements with given selector being more than defined number * @@ -15,9 +17,8 @@ export function numberOfElementsToBeMoreThan( selectorOrElementArray: string | Promise, expectedNumber: number, ): () => Promise { - return async (): Promise => { - const elements = - typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray; + return async function (): Promise { + const elements = await getElements(selectorOrElementArray); return elements.length > expectedNumber; }; diff --git a/src/element/presenceOf.ts b/src/element/presenceOf.ts index 7583fb20..0249e1ac 100644 --- a/src/element/presenceOf.ts +++ b/src/element/presenceOf.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking that an element is present on the DOM of a page * @@ -11,9 +13,9 @@ */ export function presenceOf(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { + return async function (): Promise { try { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + const element = await getElement(selectorOrElement); const isVisible = await element.isExisting(); return isVisible; diff --git a/src/element/sizeOfElementToBe.ts b/src/element/sizeOfElementToBe.ts index 2f12f6ac..d0b944ef 100644 --- a/src/element/sizeOfElementToBe.ts +++ b/src/element/sizeOfElementToBe.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking size of element with given selector * @@ -15,8 +17,8 @@ export function sizeOfElementsToBe( selectorOrElement: string | Promise, expectedSize: { width: number; height: number }, ): () => Promise { - return async (): Promise => { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + return async function (): Promise { + const element = await getElement(selectorOrElement); const actualSize = await element.getSize(); return actualSize.width === expectedSize.width && actualSize.height === expectedSize.height; diff --git a/src/element/stalenessOf.ts b/src/element/stalenessOf.ts index 245cb1de..6e472f76 100644 --- a/src/element/stalenessOf.ts +++ b/src/element/stalenessOf.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking that an element is not present on the DOM of a page * @@ -11,9 +13,9 @@ */ export function stalenessOf(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { + return async function (): Promise { try { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + const element = await getElement(selectorOrElement); const isVisible = await element.isExisting(); return !isVisible; diff --git a/src/element/textToBePresentInElement.ts b/src/element/textToBePresentInElement.ts index 342cc086..54979ac8 100644 --- a/src/element/textToBePresentInElement.ts +++ b/src/element/textToBePresentInElement.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking an element contains a specific text * @@ -15,8 +17,8 @@ export function textToBePresentInElement( selectorOrElement: string | Promise, expectedText: string, ): () => Promise { - return async (): Promise => { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + return async function (): Promise { + const element = await getElement(selectorOrElement); const text = await element.getText(); return text.includes(expectedText); diff --git a/src/element/textToBePresentInElementValue.ts b/src/element/textToBePresentInElementValue.ts index 4e283722..c85ecf7c 100644 --- a/src/element/textToBePresentInElementValue.ts +++ b/src/element/textToBePresentInElementValue.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking an element contains a specific value * @@ -15,8 +17,8 @@ export function textToBePresentInElementValue( selectorOrElement: string | Promise, expectedValue: string, ): () => Promise { - return async (): Promise => { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + return async function (): Promise { + const element = await getElement(selectorOrElement); const value = await element.getValue(); return value.includes(expectedValue); diff --git a/src/element/visibilityOf.ts b/src/element/visibilityOf.ts index f81f7736..2d27f423 100644 --- a/src/element/visibilityOf.ts +++ b/src/element/visibilityOf.ts @@ -1,3 +1,5 @@ +import { getElement } from './../utils'; + /** * A condition for checking the element to be visible * @@ -11,9 +13,9 @@ */ export function visibilityOf(selectorOrElement: string | Promise): () => Promise { - return async (): Promise => { + return async function (): Promise { try { - const element = typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; + const element = await getElement(selectorOrElement); const isVisible = await element.isDisplayed(); return isVisible; diff --git a/src/utils/getElement.ts b/src/utils/getElement.ts new file mode 100644 index 00000000..09310402 --- /dev/null +++ b/src/utils/getElement.ts @@ -0,0 +1,5 @@ +export const getElement = async ( + selectorOrElement: string | Promise, +): Promise => { + return typeof selectorOrElement === 'string' ? await $(selectorOrElement) : await selectorOrElement; +}; diff --git a/src/utils/getElements.ts b/src/utils/getElements.ts new file mode 100644 index 00000000..e38807c9 --- /dev/null +++ b/src/utils/getElements.ts @@ -0,0 +1,5 @@ +export const getElements = async ( + selectorOrElementArray: string | Promise, +): Promise => { + return typeof selectorOrElementArray === 'string' ? await $$(selectorOrElementArray) : await selectorOrElementArray; +}; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 00000000..8a99c47f --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,2 @@ +export * from './getElement'; +export * from './getElements'; diff --git a/tests/browser/alertIsPresent.test.ts b/tests/browser/alertIsPresent.test.ts index c460f0dc..6bb24c5d 100644 --- a/tests/browser/alertIsPresent.test.ts +++ b/tests/browser/alertIsPresent.test.ts @@ -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); }); }); diff --git a/tests/browser/numberOfWindowsToBe.test.ts b/tests/browser/numberOfWindowsToBe.test.ts index a89c9a0e..d9ffd6d5 100644 --- a/tests/browser/numberOfWindowsToBe.test.ts +++ b/tests/browser/numberOfWindowsToBe.test.ts @@ -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); }); }); diff --git a/tests/browser/titleContains.test.ts b/tests/browser/titleContains.test.ts index 16faddb6..520d2c5d 100644 --- a/tests/browser/titleContains.test.ts +++ b/tests/browser/titleContains.test.ts @@ -4,10 +4,10 @@ describe('titleContains', () => { beforeEach(async () => await browser.url('/')); it('should verify that method returns true when title contains', async () => { - expect(await titleContains('Internet')()).toBe(true); + expect(await titleContains('Internet').call(browser)).toBe(true); }); it('should verify that method returns false when title does not contain', async () => { - expect(await titleContains('Home')()).toBe(false); + expect(await titleContains('Home').call(browser)).toBe(false); }); }); diff --git a/tests/browser/titleIs.test.ts b/tests/browser/titleIs.test.ts index d6fe5cb6..d01eff3c 100644 --- a/tests/browser/titleIs.test.ts +++ b/tests/browser/titleIs.test.ts @@ -4,10 +4,10 @@ describe('titleIs', () => { beforeEach(async () => await browser.url('/')); it('should verify that method returns true when title is', async () => { - expect(await titleIs('The Internet')()).toBe(true); + expect(await titleIs('The Internet').call(browser)).toBe(true); }); it('should verify that method returns false when title is not', async () => { - expect(await titleIs('The - Internet')()).toBe(false); + expect(await titleIs('The - Internet').call(browser)).toBe(false); }); }); diff --git a/tests/browser/urlContains.test.ts b/tests/browser/urlContains.test.ts index e2587d5f..30271b45 100644 --- a/tests/browser/urlContains.test.ts +++ b/tests/browser/urlContains.test.ts @@ -4,10 +4,10 @@ describe('urlContains', () => { beforeEach(async () => await browser.url('/')); it('should verify that method returns true when url contains', async () => { - expect(await urlContains('internet')()).toBe(true); + expect(await urlContains('internet').call(browser)).toBe(true); }); it('should verify that method returns false when url does not contain', async () => { - expect(await urlContains('home')()).toBe(false); + expect(await urlContains('home').call(browser)).toBe(false); }); }); diff --git a/tests/browser/urlIs.test.ts b/tests/browser/urlIs.test.ts index 9d2b231a..440e7c9f 100644 --- a/tests/browser/urlIs.test.ts +++ b/tests/browser/urlIs.test.ts @@ -4,10 +4,10 @@ describe('urlIs', () => { beforeEach(async () => await browser.url('/')); it('should verify that method returns true when url is', async () => { - expect(await urlIs('https://the-internet.herokuapp.com/')()).toBe(true); + expect(await urlIs('https://the-internet.herokuapp.com/').call(browser)).toBe(true); }); it('should verify that method returns false when url is not', async () => { - expect(await urlIs('http://the-internet.herokuapp.com/')()).toBe(false); + expect(await urlIs('http://the-internet.herokuapp.com/').call(browser)).toBe(false); }); }); diff --git a/tests/logical/logical.test.ts b/tests/logical/logical.test.ts index 9a656d73..99d1fa22 100644 --- a/tests/logical/logical.test.ts +++ b/tests/logical/logical.test.ts @@ -10,21 +10,21 @@ describe('Logical', () => { const shouldReturnTrue = EC.invisibilityOf(selector); const shouldReturnTrueToo = EC.textToBePresentInElement('button', 'Add'); - expect(await EC.and(shouldReturnTrue, shouldReturnTrueToo)()).toBe(true); + expect(await EC.and(shouldReturnTrue, shouldReturnTrueToo).call(browser)).toBe(true); }); it('should verify method returns false when 1 function returns false and 2 function returns true', async () => { const shouldReturnFalse = EC.visibilityOf(selector); const shouldReturnTrue = EC.textToBePresentInElement('button', 'Add'); - expect(await EC.and(shouldReturnFalse, shouldReturnTrue)()).toBe(false); + expect(await EC.and(shouldReturnFalse, shouldReturnTrue).call(browser)).toBe(false); }); it('should verify method returns false when 1 function returns false and 2 function returns false', async () => { const shouldReturnFalse = EC.visibilityOf(selector); const shouldReturnFalseToo = EC.textToBePresentInElement('button', 'Delete'); - expect(await EC.and(shouldReturnFalse, shouldReturnFalseToo)()).toBe(false); + expect(await EC.and(shouldReturnFalse, shouldReturnFalseToo).call(browser)).toBe(false); }); }); @@ -33,14 +33,14 @@ describe('Logical', () => { const shouldReturnFalse = EC.visibilityOf(selector); const shouldReturnTrue = EC.textToBePresentInElement('button', 'Add'); - expect(await EC.or(shouldReturnFalse, shouldReturnTrue)()).toBe(true); + expect(await EC.or(shouldReturnFalse, shouldReturnTrue).call(browser)).toBe(true); }); it('should verify method returns false when 1 function returns false and 2 function returns false', async () => { const shouldReturnFalse = EC.visibilityOf(selector); const shouldReturnFalseToo = EC.textToBePresentInElement('button', 'Delete'); - expect(await EC.or(shouldReturnFalse, shouldReturnFalseToo)()).toBe(false); + expect(await EC.or(shouldReturnFalse, shouldReturnFalseToo).call(browser)).toBe(false); }); }); @@ -48,13 +48,13 @@ describe('Logical', () => { it('should verify method returns true when function returns false', async () => { const shouldReturnFalse = EC.visibilityOf(selector); - expect(await EC.not(shouldReturnFalse)()).toBe(true); + expect(await EC.not(shouldReturnFalse).call(browser)).toBe(true); }); it('should verify method returns false when function returns false', async () => { const shouldReturnTrue = EC.invisibilityOf(selector); - expect(await EC.not(shouldReturnTrue)()).toBe(false); + expect(await EC.not(shouldReturnTrue).call(browser)).toBe(false); }); }); @@ -63,14 +63,14 @@ describe('Logical', () => { const shouldReturnTrue = EC.invisibilityOf(selector); const shouldReturnFalse = EC.visibilityOf(selector); - expect(await EC.and(EC.not(shouldReturnFalse), shouldReturnTrue)()).toBe(true); + expect(await EC.and(EC.not(shouldReturnFalse), shouldReturnTrue).call(browser)).toBe(true); }); it('should verify method returns false', async () => { const shouldReturnTrue = EC.invisibilityOf(selector); const shouldReturnFalse = EC.visibilityOf(selector); - expect(await EC.and(EC.not(shouldReturnTrue), shouldReturnFalse)()).toBe(false); + expect(await EC.and(EC.not(shouldReturnTrue), shouldReturnFalse).call(browser)).toBe(false); }); }); @@ -78,13 +78,13 @@ describe('Logical', () => { it('should verify method returns true', async () => { const shouldReturnTrue = EC.invisibilityOf(selector); - expect(await EC.or(EC.not(shouldReturnTrue), shouldReturnTrue)()).toBe(true); + expect(await EC.or(EC.not(shouldReturnTrue), shouldReturnTrue).call(browser)).toBe(true); }); it('should verify method returns false', async () => { const shouldReturnTrue = EC.invisibilityOf(selector); - expect(await EC.or(EC.not(shouldReturnTrue), EC.not(shouldReturnTrue))()).toBe(false); + expect(await EC.or(EC.not(shouldReturnTrue), EC.not(shouldReturnTrue)).call(browser)).toBe(false); }); }); }); diff --git a/tests/multiremote/multiremote.test.ts b/tests/multiremote/multiremote.test.ts new file mode 100644 index 00000000..cb5c50fb --- /dev/null +++ b/tests/multiremote/multiremote.test.ts @@ -0,0 +1,107 @@ +import type { Browser } from 'webdriverio'; +import { + urlContains, + alertIsPresent, + numberOfWindowsToBe, + titleIs, + urlIs, + titleContains, + elementToBeClickable, + elementToBeEnabled, + elementToBeSelected, + numberOfElementsToBeLessThan +} from '../../src'; + +declare const browserA: Browser<'async'>; +declare const browserB: Browser<'async'>; + +describe('Multiremote', () => { + beforeEach(async () => await browser.url('/')); + + describe('Browser', () => { + it('should verify urlContains method', async () => { + await browserB.url('https://webdriver.io'); + + expect(await urlContains('io').call(browserB)).toBe(true); + expect(await urlContains('io').call(browserA)).toBe(false); + }); + + it('should verify urlIs method', async () => { + await browserB.url('https://webdriver.io'); + + expect(await urlIs('https://the-internet.herokuapp.com/').call(browserA)).toBe(true); + expect(await urlIs('https://webdriver.io/').call(browserB)).toBe(true); + }); + + it('should verify alertIsPresent method', async () => { + await browserB.execute('alert("Alert");'); + + expect(await alertIsPresent().call(browserB)).toBe(true); + expect(await alertIsPresent().call(browserA)).toBe(false); + }); + + it('should verify titleIs method', async () => { + await browserA.url('https://webdriver.io'); + + expect(await titleIs('The Internet').call(browserA)).toBe(false); + expect(await titleIs('The Internet').call(browserB)).toBe(true); + }); + + it('should verify titleContains method', async () => { + await browserA.url('https://webdriver.io'); + + expect(await titleContains('Internet').call(browserB)).toBe(true); + expect(await titleContains('WebdriverIO').call(browserA)).toBe(true); + }); + + it('should verify numberOfWindowsToBe method', async () => { + const link = await browserA.$('.large-centered a'); + await link.click(); + + expect(await numberOfWindowsToBe(2).call(browserA)).toBe(true); + expect(await numberOfWindowsToBe(2).call(browserB)).toBe(false); + }); + }); + + describe('Element', () => { + it('should verify elementToBeClickable method', async () => { + await browser.url('/add_remove_elements/'); + + await browserB.execute('document.querySelector("button").setAttribute("disabled", "");'); + + expect(await elementToBeClickable(browserB.$('button'))()).toBe(false); + expect(await elementToBeClickable(browserA.$('button'))()).toBe(true); + }); + + it('should verify elementToBeEnabled method', async () => { + await browser.url('/add_remove_elements/'); + + await browserB.execute('document.querySelector("button").setAttribute("disabled", "");'); + + expect(await elementToBeEnabled(browserB.$('button'))()).toBe(false); + expect(await elementToBeEnabled(browserA.$('button'))()).toBe(true); + }); + + it('should verify elementToBeSelected method', async () => { + await browser.url('/checkboxes'); + + const selector = '#checkboxes input'; + const checkbox = await browserA.$(selector); + await checkbox.click(); + + expect(await elementToBeSelected(browserA.$(selector))()).toBe(true); + expect(await elementToBeSelected(browserB.$(selector))()).toBe(false); + }); + + it('should verify numberOfElementsToBeLessThan method', async () => { + await browser.url('/add_remove_elements/'); + + const selector = '#elements button'; + const addElementButton = await browserA.$('button'); + await Promise.all([addElementButton.click(), addElementButton.click()]); + + expect(await numberOfElementsToBeLessThan(browserA.$$(selector), 3)()).toBe(true); + expect(await numberOfElementsToBeLessThan(browserB.$$(selector), 1)()).toBe(true); + }); + }); +}); diff --git a/tests/wdio.conf.ts b/tests/wdio.conf.ts index acd77fb1..cb731c80 100644 --- a/tests/wdio.conf.ts +++ b/tests/wdio.conf.ts @@ -2,6 +2,7 @@ export const config: WebdriverIO.Config = { runner: 'local', specs: ['./tests/**/*.test.ts'], + exclude: ['./tests/multiremote/multiremote.test.ts'], maxInstances: 10, diff --git a/tests/wdio.multiremote.conf.ts b/tests/wdio.multiremote.conf.ts new file mode 100644 index 00000000..1367e8d9 --- /dev/null +++ b/tests/wdio.multiremote.conf.ts @@ -0,0 +1,60 @@ +export const config: WebdriverIO.Config = { + runner: 'local', + + specs: ['./tests/multiremote/multiremote.test.ts'], + + maxInstances: 10, + + capabilities: { + browserA: { + capabilities: { + browserName: 'chrome', + 'goog:chromeOptions': { + args: [ + '--headless', + '--no-sandbox', + '--disable-dev-shm-usage', + '--enable-precise-memory-info', + '--window-size=1280,900', + ], + }, + }, + }, + browserB: { + capabilities: { + browserName: 'chrome', + 'goog:chromeOptions': { + args: [ + '--headless', + '--no-sandbox', + '--disable-dev-shm-usage', + '--enable-precise-memory-info', + '--window-size=1280,900', + ], + }, + }, + }, + }, + + logLevel: 'info', + + bail: 0, + + baseUrl: 'https://the-internet.herokuapp.com', + + waitforTimeout: 10000, + + connectionRetryTimeout: 120000, + + connectionRetryCount: 3, + + services: ['chromedriver'], + + framework: 'jasmine', + + reporters: ['spec'], + + jasmineOpts: { + defaultTimeoutInterval: 60000, + }, +};