@@ -65,115 +65,7 @@ npm install --save-dev @testing-library/webdriverio
6565
6666## Usage
6767
68- ### setupBrowser
69-
70- Accepts a WebdriverIO BrowserObject and returns dom-testing-library queries
71- modifed to return WebdriverIO Elements. All the queries are async, including
72- queryBy and getBy variants, and are bound to ` document.body ` by default.
73-
74- ```
75- const {setupBrowser} = require('@testing-library/webdriverio');
76-
77- it('can click button', async () => {
78- const {getByText} = setupBrowser(browser)
79-
80- const button = await getByText('Button Text');
81- await button.click();
82-
83- expect(await button.getText()).toEqual('Button Clicked')
84- })
85- ```
86-
87- Queries are also added to the BrowserObject and Elements as commands. The
88- browser commands are scoped to the ` document.body ` as above and the Element
89- commands are scoped to the element.
90-
91- ```
92- it('adds queries as browser commands', async () => {
93- setupBrowser(browser);
94-
95- expect(await browser.getByText('Page Heading')).toBeDefined()
96- })
97-
98- it('adds queries as element commands scoped to element', async () => {
99- setupBrowser(browser);
100-
101- const nested = await browser.$('*[data-testid="nested"]');
102- const button = await nested.getByText('Button Text')
103- await button.click()
104-
105- expect(await button.getText()).toEqual('Button Clicked')
106- })
107- ```
108-
109- ### within
110-
111- Returns queries scoped to a WebdriverIO element
112-
113- ```
114- const {within} = require('@testing-library/webdriverio')
115-
116- it('within scopes queries to element', async () => {
117- const nested = await browser.$('*[data-testid="nested"]');
118-
119- const button = await within(nested).getByText('Button Text');
120- await button.click();
121-
122- expect(await button.getText()).toEqual('Button Clicked')
123- });
124- ```
125-
126- ### configure
127-
128- Lets you pass a config to dom-testing-library
129-
130- ```
131- const {configure} = require('@testing-library/webdriverio')
132-
133- beforeEach(() => {
134- configure({testIdAttribute: 'data-automation-id'})
135- })
136- afterEach(() => {
137- configure(null)
138- })
139-
140- it('lets you configure queries', async () => {
141- const {getByTestId} = setupBrowser(browser)
142-
143- expect(await getByTestId('testid-in-data-automation-id-attr')).toBeDefined()
144- })
145- ```
146-
147- ### Typescript
148-
149- All the above methods are fully typed. To use the Browser and Element commands
150- added by ` setupBrowser ` the global ` WebdriverIO ` namespace will need to be
151- modified. Add the following to a typescript module:
152-
153- ```
154- import {WebdriverIOQueries} from '@testing-library/webdriverio';
155-
156- declare global {
157- namespace WebdriverIO {
158- interface Browser extends WebdriverIOQueries {}
159- interface Element extends WebdriverIOQueries {}
160- }
161- }
162- ```
163-
164- If you are using the ` @wdio/sync ` framework you will need to use the
165- ` WebdriverIOQueriesSync ` type to extend the interfaces:
166-
167- ```
168- import {WebdriverIOQueriesSync} from '@testing-library/webdriverio';
169-
170- declare global {
171- namespace WebdriverIO {
172- interface Browser extends WebdriverIOQueriesSync {}
173- interface Element extends WebdriverIOQueriesSync {}
174- }
175- }
176- ```
68+ [ Usage Docs] ( https://testing-library.com/docs/webdriverio-testing-library/intro )
17769
17870## Other Solutions
17971
0 commit comments