robotframework ride + selenium grid自动化测试套件的安装与使用示例

来源:互联网 发布:网易课堂mac版 编辑:程序博客网 时间:2024/04/28 11:36

1.安装Robot Framework RIDE以及Selenium2Library

本篇blog提供了完整的安装robot framework ride的步骤,并提供了用robotframework调用selenium grid的示例脚本;此脚本可在selenium grid服务器集群的node节点上正常操作IE、Chrome、Firefox浏览器。搭建selenium grid服务器集群的步骤,在上篇blog中提供。

1.1安装wxPython

1.1.1安装python-2.7.11.msi (x86版,安装时勾选设置path环境变量)


1.1.2安装wxPython unicode-2.8

下载地址:

http://sourceforge.net/projects/wxpython/files/wxPython/2.8.12.1/wxPython2.8-win32-unicode-2.8.12.1-py27.exe/download


1.2安装robotframework和Selenium2Library

1.2.1下载以下source包,如docutils-0.12.tar.gz

https://pypi.python.org/pypi/docutils

https://pypi.python.org/pypi/robotframework

https://pypi.python.org/pypi/robotframework-ride

https://pypi.python.org/pypi/decorator

https://pypi.python.org/pypi/selenium

https://pypi.python.org/pypi/robotframework-selenium2library/


1.2.2用python提供的pip工具安装source包

以管理员身份运行cmd,按以下命令格式,依次安装上述source包:

pip install docutils-0.12.tar.gzpip install robotframework-3.0.tar.gzpip install robotframework-ride-1.5.tar.gzpip install decorator-4.0.6.tar.gzpip install selenium-2.48.0.tar.gzpip install robotframework-selenium2library-1.7.4.tar.gz



2.启动Robot Framework RIDE,建立测试用例

以管理员身份运行cmd,运行ride.py,以启动RIDE;

依次按层级建立project(type:directory)、suit、test case。


3.robotframework调用selenium grid进行web自动化测试

以下是test suit的脚本,内容包括:引入Selenium2Library,连接到selenium hub节点,远程启动浏览器,打开百度,提交搜索条件,等待并检测搜索结果。

*** Settings ***Documentation     web testing through selenium gridSuite Setup       Prepare DesireCaps    # 准备提供给selenium hub的,启动浏览器的参数Suite Teardown    Close All Browsers    # 关闭所有打开的浏览器窗口,包括驱动浏览器的driver进程Library           Selenium2Library*** Variables ***${BROWSER}        ff    # 可以是ie、chrome、ff${HUB}            http://localhost:802/wd/hub    # 搭建selenium grid的方法见上篇blog*** Test Cases ***搜索    Open Browser    http://www.baidu.com    ${BROWSER}    b1    ${HUB}    ${DC}    Switch Browser    b1    Maximize Browser Window    Title Should Be    百度一下,你就知道    ${el}    Get Webelement    id=kw    Input Text    ${el}    莆田医院    #定位在输入框,也可以直接提交搜索,相当于输入完成后按回车键    Submit Form    ${el}    ${result}    Set Variable    xpath=//*[@class='nums']    #等待搜素结果出现    Wait Until Element Is Visible    ${result}    10    ${el}    Get Webelement    ${result}    ${result}    Get Text    ${el}    Should Contain    ${result}    百度为您找到相关结果*** Keywords ***Prepare DesireCaps    [Documentation]    用变量${DC}保存了用selenium启动浏览器的参数设置    ${chromeSwitches}    Create List    ignore-certificate-errors    ${chromeOptions}    Create Dictionary    excludeSwitches=${chromeSwitches}    ${DC}    Create Dictionary    ignoreProtectedModeSettings=${True}    ingoreZoomSettings=${True}    chromeOptions=${chromeOptions}    Set Suite Variable    ${DC}


1 0