在Mac上运行Selenium遇到的问题以及解决办法
Ruby的Selenium以及selenium-client是Web应用集成测试的常用工具。今天我装上这两个gem之后,却发现以下代码跑不起来:require "rubygems"gem "selenium-client", ">=1.2.16"require "selenium/client"begin@browser = Selenium::Client::Driver.new \ :host => "localhost", :port => 4444, :browser => "*firefox", :url => "http://www.google.com", :timeout_in_second => 60@browser.start_new_browser_session@browser.open "/"@browser.type "q", "Selenium seleniumhq.org"@browser.click "btnG", :wait_for => :pageputs @browser.text?("seleniumhq.org")ensure@browser.close_current_browser_session end
第一个错误是说找不到firefox-bin,这个好解决,在/usr/local/bin下面建一个软连接,指向/Applications/Firefox.app/Contents/MacOS/firefox-bin即可
cd /usr/local/binsudo ln -s /Applications/Firefox.app/Contents/MacOS/firefox-bin firefox-bin
第二个错误是说sqlite库的版本太低。google了一番,发现最好的办法就是用Selenium-server.jar的最新版,替换gem库中的那个版本,可以到这里下载:
http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.0a4.jar
被替换的那个文件一般位于/Library/Ruby/Gems/1.8/gems/Selenium-1.1.14/lib/selenium/openqa/selenium-server.jar.txt,如果你的gem安装地址不同,可以使用gem list -d Selenium查看一下。
这番折腾之后,终于运行正常了。
页:
[1]