Phantomjs无法在Jenkins中间歇性地渲染/导航到网页

时间:2016-02-09 20:04:20

标签: ruby jenkins selenium-webdriver phantomjs capybara

我正在使用(Phantomjs -v:1.9.8)和cucumber-ruby-capybara Framework。最近我在Jenkins看到了一些有线问题。偶尔Phantomjs无法渲染我的登录网址,它会抛出错误:

unexpected response, code=404, content-type="text/plain"
Variable Resource Not Found - {"headers":    
{"Accept":"application/json","Accept-Encoding":"gzip;q=1.0,deflate;q=0.6,
identity;q=0.3","Connection":"close","Content-Length":"18",
"Content-Type":"application/json; charset=utf-8",
"Host":"127.0.0.1:8910","User-Agent":"Ruby"},"httpVersion":"1.1","method":"POST",
"post":"{\"type\":\"browser\"}",
"url":"/session/c9asdf6b0-cr62-g1e5-a4c1-c58werebf0/log","urlParsed":
{"anchor":"","query":"","file":"log","directory":
"/session/c95fc6b0-cf62-11e5-a4c1-c5870519ebf0/",
"path":"/session/c95fc6b0-cf62-11e5-a4c1-c587asddasbf0/log","relative":
"/session/c95fc6b0-cf62-11e5-a4c1-c5870asdasebf0/log","port":"","host":"",
"password":"","user":"",
"userInfo":"","authority":"","protocol":"","source":"/session/************/log",
"queryKey":{},"chunks":
["session","c95fc6b0-cf62-11e5-a4c1-c5870519ebf0","log"]}} 
(Selenium::WebDriver::Error::WebDriverError)

失败截图,我得到的是一个空白的黑色图像,里面有一个小的矩形灰色框。

1 个答案:

答案 0 :(得分:0)

如果出现此错误,您可以尝试重新启动phantomjs,然后重试,重启phantomjs的方法如下所示

def restart_phantomjs
        session_pool = Capybara.send('session_pool')
        session_pool.each do |mode,session|
          driver = session.driver
            driver.restart
          end
        end
      end
      module_function :restart_phantomjs
 end