用于react的robot框架库。
robotframework-react的Python项目详细描述
简介
react library是一个用于react的robot框架库。它目前提供一个“wait for react”关键字,确保您的react应用程序已完全加载并可以与之交互。
安装
安装robotframework react with pip:
$ 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目前只提供一个关键字“wait for react”。 关键字确保react应用程序已完全加载。
简单反应示例
在没有任何参数的情况下使用时,“wait for react”期望react应用程序 当应用程序完全运行时,将名为“window.appstatus”的全局变量设置为true 加载。
若要使此应用程序与您的React应用程序协同工作,请将global window.appstatus添加到 index.js:
window.appStatus = false const updateStatus = () => { window.appStatus = true } ReactDOM.render(<App updateStatus={updateStatus} />, document.getElementById('root'));
向应用程序添加“正在加载”状态,并在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
机器人测试:https://github.com/kitconcept/robotframework-react/blob/master/tests/create-react-app/test.robot
红色
使用redux时,必须将还原程序的名称传递给“wait for react”关键字:
Wait for react reducer=headlines
还原器应在redux状态下实现“isfetching”属性:
const initialState = { isFetching: false, ... };
除了添加“isfetching”,您还可以根据需要命名属性,并将“statename”参数传递到“wait for react”键盘:
Wait for react reducer=headlines stateName=isLoading
您可以在此处找到完整的工作示例:
https://github.com/kitconcept/robotframework-react/tree/master/tests/create-react-app-with-redux
带redux的机器人测试:
1.0.0a2(2018-07-10)
- 从robotframework-selenium2库切换到robotframework seleniumlibrary。 [timo]
- 添加名为“statename”的参数以允许可配置的属性名,因此redux功能不需要“isfetching” [BXIE1]
1.0.0a1(2018-03-08)
- 初次发布。 [蒂莫,大卫夫]