• Ubuntu上搭建Watir-Webdriver与Cucumber环境


    本文主要演示如何在Ubuntu上搭建Watir-Webdriver与Cucumber环境,用于自动化测试。

    1. Ubuntu环境

    A. 安装

    因为我的工作机是Windows,所以采用虚拟机的方式使用Ubuntu。

    1. 首先安装虚拟机软件,可以使用VMware workstation、VirtualBox等虚拟机软件。

    2. 在虚拟机中安装Ubuntu,我使用了Ubuntu 13.10 32位.

    注意:Ubuntu 32位与64位对于我们的环境搭建没有区别,因为我的虚拟机内存为1G,所以使用了Ubuntu 32位;如果你的虚拟机内存大于2G,可以使用Ubuntu 64位,此时需要注意在电脑的BIOS中开启硬件虚拟化选项。

    B. 配置

    安装完成后,需要设置系统的Terminal选型。

    打开一个GNOME Terminal,然后去到 编辑 --》 配置文件首选项 --》 标题和命令,勾选“已登录Shell方式运行命令"。具体可以参见: https://rvm.io/integration/gnome-terminal

    2. Chrome安装

    A. 安装Chrome

    Ubuntu上的Chrome需要从Chrome官网下载安装文件,然后双击运行安装即可。

    B. 安装Chrome Webdriver

    为了Webdriver正常使用Chrome,需要安装Chrome Webdriver。

    可以从http://chromedriver.storage.googleapis.com/index.html下载对应版本的chrome driver。

    下载完成后,解压文件,并将文件移动到指定位置,并赋予读取执行权限。

    例如我的chromedriver放在Downloads目录下,将chromedriver文件放到/usr/bin目录, 并赋予读和执行的权限。

    sudo cp Downloads/chromedriver /usr/bin
    sudo chmod +x /usr/bin/chromedriver

    3. Ruby安装

    A. RVM安装

    在Linux上推荐使用rvm进行ruby的版本管理和安装。

    (1)在Linux Shell下执行以下命令安装rvm

    curl -L https://get.rvm.io | bash -s stable --auto-dotfiles

    (2)验证安装

    如果安装和配置成功,每次打开一个新的Shell会话,rvm都会被加载。可以打开一个新的Terminal,执行以下命令进行测试。

    type rvm | head -n 1

    该命令的输出应该是

    rvm is a function

    如果你的系统是中文,上述命令的输出也是中文的.

    (3) 检查依赖项

    打开一个Terminal,执行命令检查依赖项.

    rvm requirements

    (4) 修改bash_profile文件

    在安装rvm的时候,安装完成后会有以下提示:

    Upgrade Notes:
    
      * WARNING: You're using ~/.profile, make sure you load it,
        add the following line to ~/.bash_profile if it exists
        otherwise add it to ~/.bash_login:
    
          source ~/.profile
    
      * No new notes to display.

    所以需要打开 ~/.bash_profile文件,在文件的最后添加如下行:

    if [ -f "$HOME/.profile" ] ; then
        source "$HOME/.profile" 
    fi

    B. Ruby安装

    打开Terminal,执行以下命令安装ruby。

    rvm install 1.9.3
    rvm gemset create autotest
    rvm use 1.9.3@autotest --default

    解释:

    (1)watir-webdriver网站描述最合适的ruby版本是1.9.3,所以我们安装的是1.9.3.

    (2)创建一个单独的gemset是为了保证环境的互不干扰,可以将自动化测试所需要的gem都安装到autotest这个gemset里面。

    (3)设置默认的ruby使用环境。

    4. Watir-Webdriver安装

    watir-webdriver来负责跟浏览器进行交互。

    打开一个Terminal,执行以下命令安装:

    gem install watir-webdriver --no-ri --no-rdoc

    以下是我的屏幕输出,仅供参考:

    andy@ubuntu:~$ gem install watir-webdriver --no-ri --no-rdoc
        Fetching: rubyzip-0.9.9.gem (100%)
        Fetching: ffi-1.8.1.gem (100%)
        Building native extensions.  This could take a while...
        Fetching: childprocess-0.3.9.gem (100%)
        Fetching: websocket-1.0.7.gem (100%)
        Fetching: selenium-webdriver-2.33.0.gem (100%)
        Fetching: watir-webdriver-0.6.4.gem (100%)
        Successfully installed rubyzip-0.9.9
        Successfully installed ffi-1.8.1
        Successfully installed childprocess-0.3.9
        Successfully installed websocket-1.0.7
        Successfully installed selenium-webdriver-2.33.0
        Successfully installed watir-webdriver-0.6.4
        6 gems installed

    5. Cucumber安装

    Cucumber是行为驱动开发的一种工具,可以很好的与多种语言集成.自动化测试使用cucumber中的feature文件描述软件行为, 使用watir-webdriver执行浏览器操作.

    这里同样使用gem安装, 打开一个Terminal,执行以下命令安装:

    gem install cucumber --no-ri --no-rdoc

    以下是我的屏幕输出,仅供参考:

    andy@ubuntu:~$ gem install cucumber --no-ri --no-rdoc
        Fetching: builder-3.2.2.gem (100%)
        Fetching: diff-lcs-1.2.4.gem (100%)
        Fetching: multi_json-1.7.6.gem (100%)
        Fetching: gherkin-2.12.0.gem (100%)
        Building native extensions.  This could take a while...
        Fetching: cucumber-1.3.2.gem (100%)
        Successfully installed builder-3.2.2
        Successfully installed diff-lcs-1.2.4
        Successfully installed multi_json-1.7.6
        Successfully installed gherkin-2.12.0
        Successfully installed cucumber-1.3.2
  • 相关阅读:
    POJ-3131-Cubic Eight-Puzzle(双向BFS+哈希)
    Android WebView与JavaScript交互操作(Demo)
    程序猿Web面试之jQuery
    Java数据类型(基本数据类型和引用数据类型)
    Swift学习——A Swift Tour 枚举和结构体
    大龙的学习笔记之“虚方法,抽象方法,重写,抽象类,接口”
    thinkphp curd的事务回滚 一看就会
    图书源代码下载: Modern Differential Geometry of CURVES and SURFACES with Mathematica
    UOJ#422. 【集训队作业2018】小Z的礼物
    删除所选项(附加搜索部分的jquery)
  • 原文地址:https://www.cnblogs.com/andycnzh/p/3627755.html
Copyright © 2020-2023  润新知