Ruby+watir自动化测试环境搭建

下载ruby的windows版本的安装程序,下载地址:http://rubyforge.org/frs/?group_id=167或者http://files.rubyforge.vm.bytemark.co.uk/rubyinstaller/

下载exe版本的ruby,我下载的是rubyinstaller-1.9.3-p327.exe,有人说ruby1.9.3版本的不稳定,建议用ruby1.8.6版本的,也不知道哪里不稳定,就捡这个版本用吧, 187、192、193版本的没有这个SciTE编辑器(可以网上下载)。

安装过程倒是很简单,直接安装在C盘的根目录下即可(C:\Ruby),下面的3个选项选中,一路【Next】安装成功。

进入CMD命令提示行,来对Rubygems进行升级,并安装watir,他们都是通过网络安装的,执行前最好把本地的防火墙关掉。

具体的安装可以参考:http://watir.com/installation/

gem update –system(如果网络安装rubygems失败,可以尝试http://rubyforge.org/frs/?group_id=126下载最新版,线下安装)

gem install watir[版本号] #不写版本号则取最新版本

复制代码
C:\Documents and Settings\Administrator>gem -v

1.8.24

C:\Documents and Settings\Administrator>ruby -v

ruby 1.9.3p327 (2012-11-10) [i386-mingw32]

C:\>cd Ruby

C:\Ruby>gem update --system

Updating installed gems

Nothing to update

C:\Ruby>gem install watir -v 3.0.0

Fetching: commonwatir-4.0.0.gem (100%)

Fetching: multi_json-1.3.7.gem (100%)

Fetching: rubyzip-0.9.9.gem (100%)

Fetching: ffi-1.2.0-x86-mingw32.gem (100%)

Fetching: childprocess-0.3.6.gem (100%)

Fetching: websocket-1.0.3.gem (100%)

Fetching: libwebsocket-0.1.6.1.gem (100%)

Fetching: selenium-webdriver-2.26.0.gem (100%)

Fetching: watir-webdriver-0.6.1.gem (100%)

Fetching: win32-process-0.7.0.gem (100%)

Fetching: win32-api-1.4.8-x86-mingw32.gem (100%)

Fetching: windows-api-0.4.2.gem (100%)

Fetching: windows-pr-1.2.2.gem (100%)

Fetching: nokogiri-1.5.5-x86-mingw32.gem (100%)

Fetching: rautomation-0.7.3.gem (100%)

Fetching: xml-simple-1.1.2.gem (100%)

Fetching: hoe-3.3.0.gem (100%)

Fetching: s4t-utils-1.0.4.gem (100%)

Fetching: builder-3.1.4.gem (100%)

Fetching: user-choices-1.1.6.1.gem (100%)

Fetching: subexec-0.0.4.gem (100%)

Fetching: mini_magick-3.2.1.gem (100%)

Fetching: win32screenshot-1.0.7.gem (100%)

Fetching: watir-classic-3.3.0.gem (100%)

Fetching: watir-4.0.2-x86-mingw32.gem (100%)

Successfully installed commonwatir-4.0.0

Successfully installed multi_json-1.3.7

Successfully installed rubyzip-0.9.9

Successfully installed ffi-1.2.0-x86-mingw32

Successfully installed childprocess-0.3.6

Successfully installed websocket-1.0.3

Successfully installed libwebsocket-0.1.6.1

Successfully installed selenium-webdriver-2.26.0

Successfully installed watir-webdriver-0.6.1

Successfully installed win32-process-0.7.0

Successfully installed win32-api-1.4.8-x86-mingw32

Successfully installed windows-api-0.4.2

Successfully installed windows-pr-1.2.2

Successfully installed nokogiri-1.5.5-x86-mingw32

Successfully installed rautomation-0.7.3

Successfully installed xml-simple-1.1.2

Successfully installed hoe-3.3.0

Successfully installed s4t-utils-1.0.4

Successfully installed builder-3.1.4

Successfully installed user-choices-1.1.6.1

Successfully installed subexec-0.0.4

Successfully installed mini_magick-3.2.1

Successfully installed win32screenshot-1.0.7

Successfully installed watir-classic-3.3.0

Successfully installed watir-4.0.2-x86-mingw32

25 gems installed

Installing ri documentation for commonwatir-4.0.0...

Installing ri documentation for multi_json-1.3.7...

Installing ri documentation for rubyzip-0.9.9...

Installing ri documentation for ffi-1.2.0-x86-mingw32...

Enclosing class/module 'moduleFFI' for class AbstractMemory not known

Enclosing class/module 'moduleFFI' for class NullPointerError not known

Enclosing class/module "classMemory" for alias put_" #name, "put_" #old); \

    rb_define_alias(classMemory, "get_" #name, "get_" #old); \

    rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \

    rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \

    rb_define_alias(classMemory, "write_" #name, "write_" #old); \

    rb_define_alias(classMemory, "read_" #name, "read_" #old); \

    rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \

    rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \

    rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \

 

    rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \

 

    rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old);

 \

    rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old);

 \

    rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old

); \

    rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old);

 \

    rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #o

ld); \

    rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old

);

 

    ALIAS(char, int8);

    ALIAS(short, int16);

    ALIAS(int, int32);

    ALIAS(long_long, int64);

 

    /*

     * Document-method: put_float32

     * call-seq: memory.put_float32offset, value)

     * @param [Numeric] offset

     * @param [Numeric] value

     * @return [self]

     * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_f

loat).

     */

    rb_define_method(classMemory, "put_float32", memory_put_float32, 2);

    /*

     * Document-method: get_float32

     * call-seq: memory.get_float32(offset)

     * @param [Numeric] offset

     * @return [Float]

     * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).

     */

    rb_define_method(classMemory, "get_float32", memory_get_float32, 1);

    rb_define_alias(classMemory, "put_float put_float32 not known

Enclosing class/module "classMemory" for alias get_float get_float32 not known

Enclosing class/module "classMemory" for alias put_array_of_float put_array_of_f

loat32 not known

Enclosing class/module "classMemory" for alias get_array_of_float get_array_of_f

loat32 not known

Enclosing class/module "classMemory" for alias put_double put_float64 not known

Enclosing class/module "classMemory" for alias get_double get_float64 not known

Enclosing class/module "classMemory" for alias put_array_of_double put_array_of_

float64 not known

Enclosing class/module "classMemory" for alias get_array_of_double get_array_of_

float64 not known

Enclosing class/module "classMemory" for alias size total not known

Enclosing class/module 'moduleFFI' for class ArrayType not known

Enclosing class/module 'moduleFFI' for class Buffer not known

Enclosing class/module "BufferClass" for alias length total not known

Enclosing class/module 'moduleFFI' for module DataConverter not known

Enclosing class/module 'moduleFFI' for class DynamicLibrary not known

Enclosing class/module 'LibraryClass' for class Symbol not known

Enclosing class/module 'rbffi_TypeClass' for class Mapped not known

Enclosing class/module 'rbffi_StructClass' for class InlineArray not known

Enclosing class/module 'rbffi_StructLayoutClass' for class CharArray not known

Enclosing class/module "rbffi_StructLayoutCharArrayClass" for alias to_str to_s

not known

Installing ri documentation for childprocess-0.3.6...

Installing ri documentation for websocket-1.0.3...

Installing ri documentation for libwebsocket-0.1.6.1...

Installing ri documentation for selenium-webdriver-2.26.0...

Installing ri documentation for watir-webdriver-0.6.1...

Installing ri documentation for win32-process-0.7.0...

Installing ri documentation for win32-api-1.4.8-x86-mingw32...

Installing ri documentation for windows-api-0.4.2...

Installing ri documentation for windows-pr-1.2.2...

Installing ri documentation for nokogiri-1.5.5-x86-mingw32...

unable to convert "\xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for CHANGELOG.ja.rdoc, skipping

unable to convert "\xE8" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for CHANGELOG.rdoc, skipping

unable to convert "\xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for README.ja.rdoc, skipping

unable to convert "\xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for README.rdoc, skipping

unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for ext/nokogiri/xml_node_set.c, skipping

Installing ri documentation for rautomation-0.7.3...

Installing ri documentation for xml-simple-1.1.2...

Installing ri documentation for hoe-3.3.0...

unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for README.txt, skipping

Installing ri documentation for s4t-utils-1.0.4...

Installing ri documentation for builder-3.1.4...

Installing ri documentation for user-choices-1.1.6.1...

Installing ri documentation for subexec-0.0.4...

Installing ri documentation for mini_magick-3.2.1...

Installing ri documentation for win32screenshot-1.0.7...

Installing ri documentation for watir-classic-3.3.0...

Installing ri documentation for watir-4.0.2-x86-mingw32...

Installing RDoc documentation for commonwatir-4.0.0...

Installing RDoc documentation for multi_json-1.3.7...

Installing RDoc documentation for rubyzip-0.9.9...

Installing RDoc documentation for ffi-1.2.0-x86-mingw32...

Enclosing class/module 'moduleFFI' for class AbstractMemory not known

Enclosing class/module 'moduleFFI' for class NullPointerError not known

Enclosing class/module "classMemory" for alias put_" #name, "put_" #old); \

    rb_define_alias(classMemory, "get_" #name, "get_" #old); \

    rb_define_alias(classMemory, "put_u" #name, "put_u" #old); \

    rb_define_alias(classMemory, "get_u" #name, "get_u" #old); \

    rb_define_alias(classMemory, "write_" #name, "write_" #old); \

    rb_define_alias(classMemory, "read_" #name, "read_" #old); \

    rb_define_alias(classMemory, "write_u" #name, "write_u" #old); \

    rb_define_alias(classMemory, "read_u" #name, "read_u" #old); \

    rb_define_alias(classMemory, "put_array_of_" #name, "put_array_of_" #old); \

 

    rb_define_alias(classMemory, "get_array_of_" #name, "get_array_of_" #old); \

 

    rb_define_alias(classMemory, "put_array_of_u" #name, "put_array_of_u" #old);

 \

    rb_define_alias(classMemory, "get_array_of_u" #name, "get_array_of_u" #old);

 \

    rb_define_alias(classMemory, "write_array_of_" #name, "write_array_of_" #old

); \

    rb_define_alias(classMemory, "read_array_of_" #name, "read_array_of_" #old);

 \

    rb_define_alias(classMemory, "write_array_of_u" #name, "write_array_of_u" #o

ld); \

    rb_define_alias(classMemory, "read_array_of_u" #name, "read_array_of_u" #old

);

 

    ALIAS(char, int8);

    ALIAS(short, int16);

    ALIAS(int, int32);

    ALIAS(long_long, int64);

 

    /*

     * Document-method: put_float32

     * call-seq: memory.put_float32offset, value)

     * @param [Numeric] offset

     * @param [Numeric] value

     * @return [self]

     * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_f

loat).

     */

    rb_define_method(classMemory, "put_float32", memory_put_float32, 2);

    /*

     * Document-method: get_float32

     * call-seq: memory.get_float32(offset)

     * @param [Numeric] offset

     * @return [Float]

     * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).

     */

    rb_define_method(classMemory, "get_float32", memory_get_float32, 1);

    rb_define_alias(classMemory, "put_float put_float32 not known

Enclosing class/module "classMemory" for alias get_float get_float32 not known

Enclosing class/module "classMemory" for alias put_array_of_float put_array_of_f

loat32 not known

Enclosing class/module "classMemory" for alias get_array_of_float get_array_of_f

loat32 not known

Enclosing class/module "classMemory" for alias put_double put_float64 not known

Enclosing class/module "classMemory" for alias get_double get_float64 not known

Enclosing class/module "classMemory" for alias put_array_of_double put_array_of_

float64 not known

Enclosing class/module "classMemory" for alias get_array_of_double get_array_of_

float64 not known

Enclosing class/module "classMemory" for alias size total not known

Enclosing class/module 'moduleFFI' for class ArrayType not known

Enclosing class/module 'moduleFFI' for class Buffer not known

Enclosing class/module "BufferClass" for alias length total not known

Enclosing class/module 'moduleFFI' for module DataConverter not known

Enclosing class/module 'moduleFFI' for class DynamicLibrary not known

Enclosing class/module 'LibraryClass' for class Symbol not known

Enclosing class/module 'rbffi_TypeClass' for class Mapped not known

Enclosing class/module 'rbffi_StructClass' for class InlineArray not known

Enclosing class/module 'rbffi_StructLayoutClass' for class CharArray not known

Enclosing class/module "rbffi_StructLayoutCharArrayClass" for alias to_str to_s

not known

Installing RDoc documentation for childprocess-0.3.6...

Installing RDoc documentation for websocket-1.0.3...

Installing RDoc documentation for libwebsocket-0.1.6.1...

Installing RDoc documentation for selenium-webdriver-2.26.0...

Installing RDoc documentation for watir-webdriver-0.6.1...

Installing RDoc documentation for win32-process-0.7.0...

Installing RDoc documentation for win32-api-1.4.8-x86-mingw32...

Installing RDoc documentation for windows-api-0.4.2...

Installing RDoc documentation for windows-pr-1.2.2...

Installing RDoc documentation for nokogiri-1.5.5-x86-mingw32...

unable to convert "\xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for CHANGELOG.ja.rdoc, skipping

unable to convert "\xE8" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for CHANGELOG.rdoc, skipping

unable to convert "\xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for README.ja.rdoc, skipping

unable to convert "\xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for README.rdoc, skipping

unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for ext/nokogiri/xml_node_set.c, skipping

Installing RDoc documentation for rautomation-0.7.3...

Installing RDoc documentation for xml-simple-1.1.2...

Installing RDoc documentation for hoe-3.3.0...

unable to convert "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK

for README.txt, skipping

Installing RDoc documentation for s4t-utils-1.0.4...

Installing RDoc documentation for builder-3.1.4...

Installing RDoc documentation for user-choices-1.1.6.1...

Installing RDoc documentation for subexec-0.0.4...

Installing RDoc documentation for mini_magick-3.2.1...

Installing RDoc documentation for win32screenshot-1.0.7...

Installing RDoc documentation for watir-classic-3.3.0...

Installing RDoc documentation for watir-4.0.2-x86-mingw32...
复制代码

然后再安装gem install watir-webdriver

验证ruby是否成功:

复制代码
C:\Ruby>irb

irb(main):001:0> puts "my ruby1.9.3"

my ruby1.9.3

=> nil

irb(main):002:0> puts 6/3

  2

  => nil

  irb(main):002:0>

复制代码

在Ruby186版本中,是自带这个编辑器的,最新版的Ruby没有这个编辑器,我们可以手动去下载安装。

说到ruby+watir自动化测试用的编辑器,主要有一下几个:rubymine(开发专用)、SciTE、NETBeans(有支持ruby版本的)、Eclipse(要安装插件 Ruby Development Tools)。

Ruby编辑器scite下载地址:http://download.csdn.net/detail/wy3552128/4797736

由于当时安装的是最新版本rubyinstaller-1.9.3-p327.exe,安装后,可能会提示:“ruby Watir::IE (NameError)”的错误,也不知道为什么,最后降低了watir、commonwatir、watir-classic、win32-process的版本就可以啦。具体的请查看我的下一遍博文:

复制代码
gem uninstall watir -v 4.0.2

gem install watir -v 3.0.0

gem uninstall watir-classic -v 3.3.0

gem install watir-classic -v 3.0.0


gem uninstall win32-process -v 0.7.0

gem install win32-process -v 0.6.6

你可能感兴趣的:(Ruby+watir自动化测试环境搭建)