react$
react$
命令是一个有用的命令,可以通过组件的实际名称查询 React 组件,并通过 props 和 state 进行过滤。
信息
该命令仅适用于使用 React v16.x 的应用程序。在选择器指南中了解更多关于 React 选择器的信息。
用法
$(selector).react$(selector, { props, state })
参数
名称 | 类型 | 详情 |
---|---|---|
selector | string | React 组件的 |
options 可选 | ReactSelectorOptions | React 选择器选项 |
options.props 可选 | Object | 元素应包含的 React props |
options.state 可选 | Array<any>, number, string, object, boolean | 元素应处于的 React state |
示例
pause.js
it('should calculate 7 * 6', async () => {
await browser.url('https://ahfarmer.github.io/calculator/');
const appWrapper = await browser.$('div#root')
await browser.react$('t', {
props: { name: '7' }
}).click()
await browser.react$('t', {
props: { name: 'x' }
}).click()
await browser.react$('t', {
props: { name: '6' }
}).click()
await browser.react$('t', {
props: { name: '=' }
}).click()
console.log(await $('.component-display').getText()); // 打印 "42"
});
返回值
- <WebdriverIO.Element>