简体   繁体   English

Cron,Ruby和watir-webdriver问题

[英]Cron, Ruby and watir-webdriver issue

i have simple ruby+watir-webdriver example: 我有简单的ruby + watir-webdriver示例:

#!/usr/bin/env ruby

require "rubygems"
require 'watir-webdriver'

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

when i run this file manually with: 当我手动运行此文件时:

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

it works fine. 它工作正常。 When i put this in cronjob, doesnt work...i've changed the cronjob to 当我将其放在cronjob中时,不起作用...我已将cronjob更改为

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

but was again not working. 但再次无法正常工作。 any ideas how to locate the problem? 任何想法如何定位问题?

@Kevin here the output: @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'

I have found the solution - i need to start the browser in headless mode, here my working example: 我找到了解决方案-我需要以无头模式启动浏览器,这里是我的工作示例:

#!/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

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

Thanks a lot for the help! 非常感谢您的帮助!

What you need is some output to explain what the issue is. 您需要的是一些输出来解释问题所在。 Try the following and send us the contents of the cron_out.log file. 请尝试以下操作,然后将cron_out.log文件的内容发送给我们。

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

Also, try "/path_to_ruby_exec/ruby" instead of "ruby" 另外,请尝试使用“ / path_to_ruby_exec / ruby​​”而不是“ ruby​​”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM