2

我有简单的 ruby​​+watir-webdriver 示例:

#!/usr/bin/env ruby

require "rubygems"
require 'watir-webdriver'

browser = Watir::Browser.new
...
# do something
...
browser.close

当我手动运行此文件时:

/path/to/my/ruby/example.rb

它工作正常。当我将其放入 cronjob 时,它不起作用...我已将 cronjob 更改为

ruby /path/to/my/ruby/example.rb

但再次无法正常工作。任何想法如何定位问题?

@Kevin 这里是输出:

/home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/firefox/launcher.rb:77:in `connect_until_stable': unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/firefox/launcher.rb:37:in `block in launch'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/firefox/bridge.rb:19:in `initialize'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/common/driver.rb:31:in `new'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/common/driver.rb:31:in `for'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver.rb:63:in `for'
        from /home/lks/.rvm/gems/ruby-1.9.3-p194/gems/watir-webdriver-0.6.1/lib/watir-webdriver/browser.rb:35:in `initialize'
4

2 回答 2

3

我找到了解决方案 - 我需要以无头模式启动浏览器,这是我的工作示例:

#!/usr/bin/env ruby

require 'rubygems'
require 'watir-webdriver'
require 'headless'

headless = Headless.new
headless.start
browser = Watir::Browser.start 'http://www.url.com'
...
# do something
...
browser.close
headless.destroy

来源:http ://watirwebdriver.com/headless/

非常感谢您的帮助!

于 2012-05-30T17:13:46.797 回答
1

您需要的是一些输出来解释问题所在。尝试以下操作并将 cron_out.log 文件的内容发送给我们。

/path_to_ruby_exec/ruby /path/to/my/ruby/example.rb >/homedir/cron_out.log 2>&1

另外,尝试“/path_to_ruby_exec/ruby”而不是“ruby”

于 2012-05-28T17:57:48.017 回答