1

我正在按照safariwatir自述文件中的 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 specrspec 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)

spec/implementation.rb根据 watirspec 自述文件中的说明并通过阅读watirwatir-webdrivercelerity 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)
4

1 回答 1

1

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

编码问题在这里得到了修复——所以 safariwatir 的 watirspec 子模块已经过时了。要么更新子模块,要么使用 1.8.7 来避免这个问题。

于 2011-08-08T10:51:52.797 回答