Ruby Watir自动化环境搭建

一、Ruby安装
1、下载最新版的Ruby安装程序:rubyinstaller-1.9.3-p194.exe
下载地址:http://rubyforge.org/frs/?group_id=167&release_id=46722
2、安装Ruby,安装完成后,位于C:\Ruby193
3、开始->运行->输入cmd回车,可以显示Ruby的版本,即Ruby安装成功。

二、RubyGems
1、>gem -v
显示:1.8.11
更新gem,用如下命令:
>gem update --system
2、>gem -v
显示:1.8.21
证明gem已更新成功

三、DevKit
Watir和watir-webdriver gems需要ffi gem, 还需要
RubyInstaller Development Kit (DevKit)
如果不安装DevKit,在安装Watir和Watir-Webdriver时会报错。
1、下载DevKit
下载地址:http://www.softpedia.com/progDownload/DevKit-Download-193050.html
2、安装DevKit,放在C盘devkit
3、在控制台,切换至devkit目录下
C:\devkit>ruby dk.rb init
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.
4、安装
C:\devkit>ruby dk.rb install
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operating_system.rb'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

四、准备安装Watir和Watir-webdriver
1、在命令行输入命令
gem install watir
如果不想安装Watir的帮助文档,就用下面的命令
gem install watir --no-ri --no-rdoc
(...)
Successfully installed watir-2.0.4
(...)
安装成功后,可以测试是否能够在IE执行
>irb

> require "watir"
=> true

> browser = Watir::Browser.new
=> #<Watir::IE:0x..f8169d746 url="about:blank" title="">

> browser.goto "watir.com"
=> 16.998912

五、watir-webdriver
>gem install watir-webdriver --no-ri --no-rdoc
...)
Successfully installed watir-webdriver-0.4.1
(...)
在命令行验证是否能跑起来
>irb

> require "watir-webdriver"
=> true

> browser = Watir::Browser.new :ie
Selenium::WebDriver::Error::NoSuchDriverError: Unexpected error
launching Internet Explorer. Protected Mode must be set to the
same value (enabled or disabled) for all zones.
(...)

可以驱动Firefox吗?可以
>irb

> require "watir-webdriver"
=> true

> browser = Watir::Browser.new :ff
=> #<Watir::Browser:0x62d8c4a6 url="about:blank" title="">

> browser.goto "watir.com"
=> "http://watir.com/"

Chrome with watir-webdriver
>irb

> require "watir-webdriver"
=> true

> browser = Watir::Browser.new :chrome
Selenium::WebDriver::Error::WebDriverError: Unable to find the
chromedriver executable. Please download the server from
http://code.google.com/p/chromium/downloads/list and place it
somewhere on your PATH. More info at
http://code.google.com/p/selenium/wiki/ChromeDriver.
(...)


Watir-webdrirver API
http://rubydoc.info/gems/watir-webdriver/0.1.8/frames

你可能感兴趣的:(Ruby Watir自动化环境搭建)