-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As of WebdriverIO v7.19.0 it is possible to chain custom queries as long as they end in `$`. See the release notes for v7.19.0 here: https://github.com/webdriverio/webdriverio/blob/v7.19.0/CHANGELOG.md Add chainable queries to the `Browser` and `Element` as commands of the form `{queryName}$`, for example the chainable version of `getByText` is `getByText$`. Infer the types for `ChainablePromiseElement` and `ChainablePromiseArray` from the `Browser` and `Element` types, that way we don't need to lock in a specific version of WebdriverIO's types. To add the types of the chainable commands to the global WebdriverIO types users now need to add `WebdriverIOQueriesChainable` to the global `Browser`, `Element` and `ChainablePromiseElement` interfaces. This should not break existing behaviour or types, and the chainable custom commands should behave the same as the existing commands if the WebdriverIO version is less than v7.19.0. Typescript users need to use at least v4.1 as the types now make use of template literal strings to modify the query name to include `$` at the end. Bump development version of WebdriverIO packages to at least v7.19.0 and add tests for chaining queries.
- Loading branch information
1 parent
09183e8
commit 8274749
Showing
6 changed files
with
145 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {setupBrowser} from '../../src' | ||
|
||
describe('chaining', () => { | ||
it('can chain browser getBy queries', async () => { | ||
setupBrowser(browser) | ||
|
||
const button = await browser | ||
.getByTestId$('nested') | ||
.getByText$('Button Text') | ||
|
||
await button.click() | ||
|
||
expect(await button.getText()).toEqual('Button Clicked') | ||
}) | ||
|
||
it('can chain element getBy queries', async () => { | ||
const {getByTestId} = setupBrowser(browser) | ||
|
||
const nested = await getByTestId('nested') | ||
await nested.getByText$('Button Text').click() | ||
|
||
expect(await browser.getByText$('Button Clicked').getText()).toEqual( | ||
'Button Clicked', | ||
) | ||
}) | ||
|
||
it('can chain browser getAllBy queries', async () => { | ||
setupBrowser(browser) | ||
|
||
await browser.getByTestId$('nested').getAllByText$('Button Text')[0].click() | ||
|
||
expect(await browser.getAllByText('Button Clicked')).toHaveLength(1) | ||
}) | ||
|
||
it('can chain element getAllBy queries', async () => { | ||
const {getByTestId} = setupBrowser(browser) | ||
|
||
const nested = await getByTestId('nested') | ||
await nested.getAllByText$('Button Text')[0].click() | ||
|
||
expect(await nested.getAllByText('Button Clicked')).toHaveLength(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters