Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes to react$ and react$$ scripts (#3862)
* first implementation of react$ command (#3794) * implement react60245 command * add note for react support * add unit tests * don't throw error when no element is found * add better docs for react29872 * minor wording * remove workaround * webdriverio: cleanup resq scripts * webdriverio: add tests for resq script * webdriverio: cleanup resq script test * webdriverio: add module test. adjust error message for react32456 * webdriverio: element > elem in resq script * webdriverio: return empty array if no components foudn in react32456 * webdriverio: adjust react script when selecting multiple fragments * webdriverio: doc update for react scripts * docs: finalize docs for react$ and react58211 commands * webdriverio: adjust resq version. add more tests to resq script
- Loading branch information
1 parent
78ca355
commit d006047
Showing
16 changed files
with
615 additions
and
192 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
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,35 @@ | ||
/** | ||
* | ||
* The `react$$` command is a useful command to query multiple React Components | ||
* by their actual name and filter them by props and state. | ||
* | ||
* **NOTE:** the command only works with applications using React v16.x | ||
* | ||
* <example> | ||
:pause.js | ||
it('should calculate 7 * 6', () => { | ||
browser.url('https://ahfarmer.github.io/calculator/'); | ||
const orangeButtons = browser.react$$('t', { orange: true }) | ||
console.log(orangeButtons.map((btn) => btn.getText())); // prints "[ '÷', 'x', '-', '+', '=' ]" | ||
}); | ||
* </example> | ||
* | ||
* @alias browser.react$ | ||
* @param {Object=} props React props the element should contain | ||
* @param {Object=} state React state the element should be in | ||
* @return {Element} | ||
* | ||
*/ | ||
import fs from 'fs' | ||
import { getElements } from '../../utils/getElementObject' | ||
import { waitToLoadReact, react$$ as react$$Script } from '../../scripts/resq' | ||
|
||
const resqScript = fs.readFileSync(require.resolve('resq')) | ||
|
||
export default async function react$$ (selector, props = {}, state = {}) { | ||
await this.executeScript(resqScript.toString(), []) | ||
await this.execute(waitToLoadReact) | ||
const res = await this.execute(react$$Script, selector, props, state) | ||
return getElements.call(this, selector, res) | ||
} |
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,39 @@ | ||
/** | ||
* | ||
* The `react$` command is a useful command to query React Components by their | ||
* actual name and filter them by props and state. | ||
* | ||
* **NOTE:** the command only works with applications using React v16.x | ||
* | ||
* <example> | ||
:pause.js | ||
it('should calculate 7 * 6', () => { | ||
browser.url('https://ahfarmer.github.io/calculator/'); | ||
browser.react$('t', { name: '7' }).click() | ||
browser.react$('t', { name: 'x' }).click() | ||
browser.react$('t', { name: '6' }).click() | ||
browser.react$('t', { name: '=' }).click() | ||
console.log($('.component-display').getText()); // prints "42" | ||
}); | ||
* </example> | ||
* | ||
* @alias browser.react$ | ||
* @param {Object=} props React props the element should contain | ||
* @param {Object=} state React state the element should be in | ||
* @return {Element} | ||
* | ||
*/ | ||
import fs from 'fs' | ||
import { getElement } from '../../utils/getElementObject' | ||
import { waitToLoadReact, react$ as react$Script } from '../../scripts/resq' | ||
|
||
const resqScript = fs.readFileSync(require.resolve('resq')) | ||
|
||
export default async function react$ (selector, props = {}, state = {}) { | ||
await this.executeScript(resqScript.toString(), []) | ||
await this.execute(waitToLoadReact) | ||
const res = await this.execute(react$Script, selector, props, state) | ||
return getElement.call(this, selector, res) | ||
} |
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
Oops, something went wrong.