React的Robot Framework库。
项目描述
简介
ReactLibrary是React的Robot Framework库。它目前提供了一个“等待React”关键字,确保您的React应用程序已完全加载并可交互。
安装
使用pip安装robotframework-react
$ pip install robotframework-react
用法
为了编写您的第一个测试用例,请确保包含SeleniumLibrary和ReactLibrary。创建一个包含以下内容的test.robot文件
*** Settings *** Library SeleniumLibrary timeout=10 implicit_wait=0 Library React Library Suite Setup Open browser https://airbnb.com chrome Suite Teardown Close browser *** Test Cases *** Scenario: Wait for react Go To https://airbnb.com Wait for react Page Should Contain Airbnb Book unique homes Scenario: Wait for react with reducer Go To https://airbnb.com Wait for react reducer=headlines Page Should Contain Airbnb Book unique homes
关键字
robotframework-react 目前只提供单个关键字“等待React”。该关键字确保React应用完全加载。
Plain React 示例
在没有任何参数的情况下使用“等待React”,它期望React应用在应用完全加载时将全局变量“window.appStatus”设置为true。
为了与您的React应用一起使用,请在您的index.js中添加全局变量window.appStatus
window.appStatus = false const updateStatus = () => { window.appStatus = true } ReactDOM.render(<App updateStatus={updateStatus} />, document.getElementById('root'));
在App中添加一个“isLoading”状态,并在componentDidMount和componentDidUpdate(App.js)中更新它
class App extends Component { state = { isLoading: true, } componentDidMount() { wait(2000).then(() => { this.setState({ isLoading: false }) }) } componentDidUpdate() { if (!this.state.isLoading) { this.props.updateStatus() } } ... }
您可以在以下位置找到完整的示例: https://github.com/kitconcept/robotframework-react/tree/master/tests/create-react-app
Robot 测试: https://github.com/kitconcept/robotframework-react/blob/master/tests/create-react-app/test.robot
Redux
当与Redux一起工作时,您必须将还原器的名称传递给“等待React”关键字
Wait for react reducer=headlines
还原器应在Redux状态中实现“isFetching”属性
const initialState = { isFetching: false, ... };
您也可以将属性命名为任何您想要的名字,并通过“stateName”参数传递给“等待React”键盘
Wait for react reducer=headlines stateName=isLoading
您可以在以下位置找到完整的示例
https://github.com/kitconcept/robotframework-react/tree/master/tests/create-react-app-with-redux
带有Redux的Robot测试
1.0.0a2 (2018-07-10)
从robotframework-selenium2library切换到robotframework-seleniumlibrary。[timo]
添加一个名为“stateName”的参数,允许配置可变属性名,因此对于Redux功能不需要“isFetching”。[bxie1]
1.0.0a1 (2018-03-08)
初始发布。[timo, davidrf]
项目详情
robotframework-react-1.0.0a2.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4c3010f3368eda3d10fda96598d3b04f7acce25c543a195a10c45b04fdcc9ea4 |
|
MD5 | 73fa2d7093eed1226004e28615795af0 |
|
BLAKE2b-256 | c04bdea67e396e693fce04d908eedd695df16a14c4acda1bda3c2fb5fe6d0616 |