对watirspec运行safariwatir

时间:2011-08-08 10:41:55

标签: ruby watir safariwatir

我正在跟踪对safariwatir readme中的watirspec 指令运行safariwatir。

$ git clone git://github.com/redsquirrel/safariwatir.git
Cloning into safariwatir...
...

$ cd safariwatir

$ git submodule update --init
Submodule 'spec/watirspec' (git://github.com/jarib/watirspec.git) registered for path 'spec/watirspec'
Cloning into spec/watirspec...
...
Submodule path 'spec/watirspec': checked out '4e080506694b079d08135e610716e5655f07183f'

由于我有rspec 2,我已将spec spec替换为rspec spec

$ rspec spec
/Users/zeljko/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': /Users/zeljko/Documents/projekt/safariwatir/spec/watirspec/lib/server.rb:91: invalid multibyte char (US-ASCII) (SyntaxError)
...

正如jarib在他的回答中所说,safariwatir的watirspec指向和旧提交(2009年4e08),所以我已将其更新为指向watirspec的watir2分支中的最新提交。

$ cd spec/watirspec && git pull origin watir2
From git://github.com/jarib/watirspec
 * branch            watir2     -> FETCH_HEAD
Updating 4e08050..fa27ccf
...

safariwatir的watirspec现在指向fa27ccf,但是rspec spec现在抱怨它找不到spec/implementation.rb文件。

$ rspec spec
/Users/zeljko/Documents/projekt/safariwatir/spec/watirspec/lib/runner.rb:58:in `load': no such file to load -- /Users/zeljko/Documents/projekt/safariwatir/spec/implementation.rb (LoadError)

我已根据watirspec自述文件的说明以及阅读watirwatir-webdrivercelerity spec/implementation.rb文件创建了implementation.rb文件。

$LOAD_PATH.unshift("../lib")
require "safariwatir"

include Watir::Exception

WatirSpec.implementation do |imp|
  imp.name = :safariwatir
  imp.browser_class = Watir::Safari
end

最后它有效:

$ rspec spec
...
Finished in 27.89 seconds
1005 examples, 997 failures

99%的失败看起来像这样:

  10) Browser#html returns the DOM of the page as an HTML string
     Failure/Error: browser.goto(WatirSpec.files + "/right_click.html")
     Appscript::CommandError:
       CommandError
            OSERROR: -609
            MESSAGE: Connection is invalid.
            COMMAND: app("/Applications/Safari.app").documents[1].URL.set("file:///Users/zeljko/Documents/projekt/safariwatir/spec/watirspec/html/right_click.html")
     # ./lib/safariwatir/scripter.rb:253:in `block in navigate_to'
     # ./lib/safariwatir/scripter.rb:697:in `page_load'
     # ./lib/safariwatir/scripter.rb:252:in `navigate_to'
     # ./lib/safariwatir.rb:960:in `goto'
     # ./spec/watirspec/browser_spec.rb:23:in `block (4 levels) in <top (required)>'

环境:

Mac OS X 10.6.8,Safari 5.1。

$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

$ gem list
*** LOCAL GEMS ***
...
rspec (2.6.0)
...
rubygems-update (1.8.7)
...
safariwatir (0.4.0)

1 个答案:

答案 0 :(得分:1)

您应该运行rspec spec(规范二进制文件似乎指向/ Library /中的非RVM Ruby安装)。

编码问题已修复here - 所以safariwatir的watirspec子模块已经过时了。更新子模块,或使用1.8.7来避免问题。