Ruby 黄瓜+;水豚。PhantomJS崩溃或不呈现页面?

Ruby 黄瓜+;水豚。PhantomJS崩溃或不呈现页面?,ruby,phantomjs,cucumber,capybara,poltergeist,Ruby,Phantomjs,Cucumber,Capybara,Poltergeist,你好,Stackoverflow社区,我使用Cucumber+Capybara和Chrome/firefox驱动程序测试后端/前端的Canvas/React.js元素,现在我坚持使用PhantomJS(Poltergeist) 我所有的测试在Chromedriver/Firefox上都运行良好且非常稳定,但是我在无头浏览器上遇到了很多意想不到的问题/错误 通常,我会遇到两种类型的错误: 1.后端,JS,登录页面,水豚在我访问页面时引发错误: PhantomJS has crashed. Plea

你好,Stackoverflow社区,我使用Cucumber+Capybara和Chrome/firefox驱动程序测试后端/前端的Canvas/React.js元素,现在我坚持使用PhantomJS(Poltergeist)

我所有的测试在Chromedriver/Firefox上都运行良好且非常稳定,但是我在无头浏览器上遇到了很多意想不到的问题/错误

通常,我会遇到两种类型的错误: 1.后端,JS,登录页面,水豚在我访问页面时引发错误:

PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
  Background: Log In backend                                # features/HS_smoke_backend.feature:5
    Given HS Backend Login Page                             # features/step_definitions/links.rb:5
      PhantomJS client died while processing {"id":"34954a92-1af2-4e1f-a37c-0342d8d04179","name":"visit","args":["https://backend.xxx.com/",1000]} (Capybara::Poltergeist::DeadClient)
      ./lib/capybara/session.rb:252:in `visit'
      ./lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
      ./features/step_definitions/links.rb:6:in `/^HS Backend Login Page$/'
      features/HS_smoke_backend.feature:6:in `Given HS Backend Login Page'
links.rb

Given(/^HS Backend Login Page$/) do
  visit "https://backend.xxx.com/"
end
When(/^I Log In with login "([^"]*)" and password "([^"]*)"$/) do |login,password|
  fill_in('user', :with => login)
  fill_in('pass', :with => password)
  click_button('Log In')
end

And(/I click on Profile$/) do
  page.find(:css,'#dropdownMenuArrow').click
  page.find(:css, '#profile').click
end
require 'rubygems'
require 'bundler/setup'

require 'capybara/cucumber'
require 'capybara/spec/test_app'
require 'capybara/poltergeist'
require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
require 'yaml'

Capybara.app = TestApp


Capybara.javascript_driver = :poltergeist
Capybara.default_driver = :selenium
Capybara.default_max_wait_time = 10
Capybara.ignore_hidden_elements = false


Capybara.register_driver :poltergeist do |app|
        options = {
            :timeout => 1000,
            :extensions => [],
            :js_errors => false,
            :debug => false,
            :window_size => [1600, 1200],
            :inspector => true,
            :phantomjs_options => ['--load-images=no',
                                   '--debug=no',
                                   '--proxy-type=none',
                                   '--disk-cache=false',
                                   '--ignore-ssl-errors=yes',
                                   '--ssl-protocol=tlsv1',
                                   '--web-security=false'],
                  }
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.javascript_driver = :poltergeist


Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new app, browser: :chrome
end

Before '@selenium' do
  page.driver.browser.manage.window.resize_to(1600, 1200)
end
#World(Capybara::DSL)
动作。rb

Given(/^HS Backend Login Page$/) do
  visit "https://backend.xxx.com/"
end
When(/^I Log In with login "([^"]*)" and password "([^"]*)"$/) do |login,password|
  fill_in('user', :with => login)
  fill_in('pass', :with => password)
  click_button('Log In')
end

And(/I click on Profile$/) do
  page.find(:css,'#dropdownMenuArrow').click
  page.find(:css, '#profile').click
end
require 'rubygems'
require 'bundler/setup'

require 'capybara/cucumber'
require 'capybara/spec/test_app'
require 'capybara/poltergeist'
require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
require 'yaml'

Capybara.app = TestApp


Capybara.javascript_driver = :poltergeist
Capybara.default_driver = :selenium
Capybara.default_max_wait_time = 10
Capybara.ignore_hidden_elements = false


Capybara.register_driver :poltergeist do |app|
        options = {
            :timeout => 1000,
            :extensions => [],
            :js_errors => false,
            :debug => false,
            :window_size => [1600, 1200],
            :inspector => true,
            :phantomjs_options => ['--load-images=no',
                                   '--debug=no',
                                   '--proxy-type=none',
                                   '--disk-cache=false',
                                   '--ignore-ssl-errors=yes',
                                   '--ssl-protocol=tlsv1',
                                   '--web-security=false'],
                  }
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.javascript_driver = :poltergeist


Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new app, browser: :chrome
end

Before '@selenium' do
  page.driver.browser.manage.window.resize_to(1600, 1200)
end
#World(Capybara::DSL)
env.rb

Given(/^HS Backend Login Page$/) do
  visit "https://backend.xxx.com/"
end
When(/^I Log In with login "([^"]*)" and password "([^"]*)"$/) do |login,password|
  fill_in('user', :with => login)
  fill_in('pass', :with => password)
  click_button('Log In')
end

And(/I click on Profile$/) do
  page.find(:css,'#dropdownMenuArrow').click
  page.find(:css, '#profile').click
end
require 'rubygems'
require 'bundler/setup'

require 'capybara/cucumber'
require 'capybara/spec/test_app'
require 'capybara/poltergeist'
require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
require 'yaml'

Capybara.app = TestApp


Capybara.javascript_driver = :poltergeist
Capybara.default_driver = :selenium
Capybara.default_max_wait_time = 10
Capybara.ignore_hidden_elements = false


Capybara.register_driver :poltergeist do |app|
        options = {
            :timeout => 1000,
            :extensions => [],
            :js_errors => false,
            :debug => false,
            :window_size => [1600, 1200],
            :inspector => true,
            :phantomjs_options => ['--load-images=no',
                                   '--debug=no',
                                   '--proxy-type=none',
                                   '--disk-cache=false',
                                   '--ignore-ssl-errors=yes',
                                   '--ssl-protocol=tlsv1',
                                   '--web-security=false'],
                  }
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.javascript_driver = :poltergeist


Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new app, browser: :chrome
end

Before '@selenium' do
  page.driver.browser.manage.window.resize_to(1600, 1200)
end
#World(Capybara::DSL)
Gemfile

source 'https://rubygems.org'

gem 'bundler', '~> 1.1'
gemspec

gem 'xpath', :git => 'git://github.com/jnicklas/xpath.git'

group :doc do
  gem 'redcarpet', :platforms => :mri
end

group :test do
  gem 'poltergeist'
  gem 'phantomjs', :require => 'phantomjs/poltergeist'
  gem 'cucumber-rails'
  gem 'chromedriver-helper'
  gem 'cucumber'
  gem 'selenium-webdriver'
end
我的宝贝:

    <body data-gr-c-s-loaded="true">
        <div id="root"><div data-reactroot="" class="login-body"><div id="login"><form name="form-login"><div class="image"><img src="/static/bd592ccc4d8f1bd5ec54f462b6da0e82.png" width="192px" height="" alt="logo"></div><div class="block1"><div class="name"><p>Username</p></div><input type="text" id="user" required="" placeholder="" value="admin"></div><div class="block2"><div class="passw"><p>Password</p></div><input type="password" id="pass" required="" placeholder="" value="admin123"></div><div style="padding: 15px; height: 50px;"><p class="forgot"><a href=""></a></p></div></form><div id="submit"><input type="button" id="loginButton" value="Log In"></div></div></div></div>
        <script src="/static/bundle.js"></script><iframe src="about:blank" frameborder="0" id="FirebugUI" style="border: 0px; visibility: visible; z-index: 2147483647; position: fixed; width: 100%; left: 0px; bottom: 0px; height: 300px; display: none;"></iframe>
      <script type="text/javascript" src="/static/bundle.js"></script>
    </body>
Feature: Regression backend
  As a account manager
  I would like to see working backend

  Background: Log In backend
    Given HS Backend Login Page
    And I Log In with login "admin" and password "admin123"

  @javascript
  Scenario: Smoke test backend
    And I click on Profile
actionpack (4.2.7.1)
actionview (4.2.7.1)
activesupport (4.2.7.1)
addressable (2.5.0)
afm (0.2.2)
archive-zip (0.7.0)
Ascii85 (1.0.2)
bigdecimal (default: 1.2.8)
builder (3.2.3)
bundler (1.14.4)
bundler-unload (1.0.2)
capybara (2.12.0)
capybara-screenshot (1.0.14)
childprocess (0.6.1)
chromedriver-helper (1.0.0)
cliver (0.3.2)
coderay (1.1.1)
cucumber (2.4.0)
cucumber-core (1.5.0)
cucumber-rails (1.4.5)
cucumber-wire (0.0.1)
did_you_mean (1.0.0)
diff-lcs (1.3)
erubis (2.7.0)
executable-hooks (1.3.2)
ffi (1.9.17)
fuubar (2.2.0)
gem-wrappers (1.2.7)
gherkin (4.0.0)
hashery (2.1.2)
i18n (0.8.0)
io-console (default: 0.4.5)
io-like (0.3.0)
json (1.8.6, default: 1.8.3)
launchy (2.4.3)
loofah (2.0.3)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1, 5.8.5)
multi_json (1.12.1)
multi_test (0.1.2)
net-telnet (0.1.1)
nokogiri (1.7.0.1)
pdf-reader (1.4.1)
phantomjs (2.1.1.0)
poltergeist (1.13.0)
power_assert (0.2.6)
pry (0.10.4)
psych (default: 2.1.0)
public_suffix (2.0.5)
rack (2.0.1, 1.6.5)
rack-protection (1.5.3)
rack-test (0.6.3)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.8)
rails-html-sanitizer (1.0.3)
railties (4.2.7.1)
rake (12.0.0, 10.5.0, 10.4.2)
rdoc (default: 4.2.1)
redcarpet (3.4.0)
rspec (3.5.0)
rspec-core (3.5.4)
rspec-expectations (3.5.0)
rspec-mocks (3.5.0)
rspec-support (3.5.0)
ruby-progressbar (1.8.1)
ruby-rc4 (0.1.5)
rubygems-bundler (1.4.4)
rubyzip (1.2.1)
rvm (1.11.3.9)
selenium-webdriver (3.1.0)
sinatra (1.4.8)
slop (3.6.0)
test-unit (3.1.5)
thor (0.19.4)
thread_safe (0.3.5)
tilt (2.0.6)
ttfunk (1.4.0)
tzinfo (1.2.2)
websocket (1.2.4)
websocket-driver (0.6.5)
websocket-extensions (0.1.2)
xpath (2.0.0)
yard (0.9.8)

对于PhantomJS崩溃,除了确保运行最新的PhantomJS(目前为2.1.1,还有2.5测试版可用)和确保将任何JS传输到最大ES5之外,您没有什么可以做的。任何正在使用的ES6特性(let/const/=>函数等)都可能导致JS被忽略或导致PhatnomJS崩溃。您可能还希望在调试时启用
js_errors
。除此之外,为什么要指定
Capybara.app=TestApp
?您确定可以通过CodeShip访问您试图联系的URL吗?此外,在
单击按钮(“登录”)后,
您应该对成功登录后页面上出现的内容有所期待,以确保在您对页面执行任何其他操作之前完成登录,否则登录可能会中止,没有实际返回会话cookies等。您好@ThomasWalpole,谢谢您的回答!你说得对,Capybara.app=TestApp不是必需的,我想我是从以前的项目中获取的。另外,我在验证成功登录的步骤之后添加了期望值。使用js_errors=>true,我看到:“ReferenceError:Strict模式禁止隐式创建全局属性'_temp'。来自本地机器的幻影不断崩溃。URL是可访问的。第一步是通过找出定义_temp的位置来修复JS错误,并修复错误。除了查看应用程序请求的JS,确保它实际上符合ES5(no-let/const/etc)谢谢@ThomasWalpole,问题在于登录页面存在JS错误,我决定切换到真正的浏览器bc Codeship支持它