Ubuntu上搭建Watir-Webdriver与Cucumber环境

系统 1744 0

本文主要演示如何在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
      
    

Ubuntu上搭建Watir-Webdriver与Cucumber环境


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论