跳转到主要内容

React的Robot Framework库。

项目描述

https://travis-ci.org/kitconcept/robotframework-react.svg?branch=master Egg Status Latest Version License

kitconcept

简介

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测试

https://github.com/kitconcept/robotframework-react/blob/master/tests/create-react-app-with-redux/test.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 (54.8 kB 查看哈希)

上传时间:

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面