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--百度搜索示例


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM