黄瓜+水豚。 PhantomJS崩溃或不渲染页面?

时间:2017-02-17 01:32:59

标签: ruby phantomjs cucumber capybara poltergeist

Hello Stackoverflow社区,我使用Cucumber + Capybara和Chrome / firefox驱动程序来测试带有Canvas / React.js元素的Backend / FrontEnd,现在我坚持使用PhantomJS(Poltergeist)。

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

通常,我会遇到两种错误: 1.当我访问该页面时,后端,JS,登录页面,capybara引发了错误:

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'
  1. 如果我使用最新的PhantomJS在CI(Codeship)上运行相同的测试,那么我会收到另一个错误(但它在ChromeDriver本地工作正常)。我猜安全模块有问题,这就是PhantomJS崩溃的原因。 有什么想法吗?
  2. 错误(Codeship)

        Background: Log In backend                                # features/HS_smoke_backend.feature:5
        Given HS Backend Login Page                             # features/step_definitions/links.rb:5
        And I Log In with login "admin" and password "admin123" # features/step_definitions/actions.rb:3
              Unable to find field "user" (Capybara::ElementNotFound)
              ./lib/capybara/node/finders.rb:44:in `block in find'
              ./lib/capybara/node/base.rb:85:in `synchronize'
              ./lib/capybara/node/finders.rb:33:in `find'
              ./lib/capybara/node/actions.rb:92:in `fill_in'
              ./lib/capybara/session.rb:780:in `block (2 levels) in <class:Session>'
              ./lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
              ./features/step_definitions/actions.rb:4:in `/^I Log In with login "([^"]*)" and password "([^"]*)"$/'
              features/HS_smoke_backend.feature:7:in `And I Log In with login "admin" and password "admin123"'
    

    登录页面:

        <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>
    

    backend.feature:

    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
    

    links.rb

    Given(/^HS Backend Login Page$/) do
      visit "https://backend.xxx.com/"
    end
    

    actions.rb

    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
    

    env.rb

    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
    

    我的宝石:

    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)
    

0 个答案:

没有答案