黄瓜文件结束达成(EOFError)

时间:2016-04-03 17:03:08

标签: ruby cucumber watir watir-webdriver selenium-firefoxdriver

运行黄瓜测试会给我以下错误

  end of file reached (EOFError)
  /usr/lib64/ruby/2.0.0/net/protocol.rb:153:in `read_nonblock'
  /usr/lib64/ruby/2.0.0/net/protocol.rb:153:in `rbuf_fill'
  /usr/lib64/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
  /usr/lib64/ruby/2.0.0/net/protocol.rb:144:in `readline'
  /usr/lib64/ruby/2.0.0/net/http/response.rb:39:in `read_status_line'
  /usr/lib64/ruby/2.0.0/net/http/response.rb:28:in `read_new'
  /usr/lib64/ruby/2.0.0/net/http.rb:1406:in `block in transport_request'
  /usr/lib64/ruby/2.0.0/net/http.rb:1403:in `catch'
  /usr/lib64/ruby/2.0.0/net/http.rb:1403:in `transport_request'
  /usr/lib64/ruby/2.0.0/net/http.rb:1376:in `request'
  /usr/lib64/ruby/2.0.0/net/http.rb:1369:in `block in request'
  /usr/lib64/ruby/2.0.0/net/http.rb:852:in `start'
  /usr/lib64/ruby/2.0.0/net/http.rb:1367:in `request'
  ./features/step_definitions/my_steps.rb:110:in `block (2 levels) in <top (required)>'
  ./features/step_definitions/my_steps.rb:58:in `each'
  ./features/step_definitions/my_steps.rb:58:in `/^action$/'
  features/myFeature.feature:18:in `Then I should XY'
  Connection refused - connect(2) (Errno::ECONNREFUSED)
  /usr/lib64/ruby/2.0.0/net/http.rb:878:in `initialize'
  /usr/lib64/ruby/2.0.0/net/http.rb:878:in `open'
  /usr/lib64/ruby/2.0.0/net/http.rb:878:in `block in connect'
  /usr/lib64/ruby/2.0.0/timeout.rb:66:in `timeout'
  /usr/lib64/ruby/2.0.0/net/http.rb:877:in `connect'
  /usr/lib64/ruby/2.0.0/net/http.rb:862:in `do_start'
  /usr/lib64/ruby/2.0.0/net/http.rb:851:in `start'
  /usr/lib64/ruby/2.0.0/net/http.rb:1367:in `request'
  ./features/support/env.rb:45:in `After' 

我的gemlist来自bundle:

* activemodel (4.2.6)
* activerecord (4.2.6)
* activesupport (4.2.6)
* addressable (2.4.0)
* arel (6.0.3)
* builder (3.2.2)
* bundler (1.6.5)
* capybara (2.6.2)
* childprocess (0.5.9)
* cucumber (2.3.3)
* cucumber-core (1.4.0)
* cucumber-wire (0.0.1)
* data_magic (0.22)
* diff-lcs (1.2.5)
* faker (1.6.3)
* ffi (1.9.10)
* gherkin (3.2.0)
* headless (2.2.3)
* i18n (0.7.0)
* json (1.8.3)
* mime-types (3.0)
* mime-types-data (3.2016.0221)
* mini_portile2 (2.0.0)
* minitest (5.8.4)
* multi_json (1.11.2)
* multi_test (0.1.2)
* mysql2 (0.4.3)
* nokogiri (1.6.7.2)
* page-object (1.1.1)
* page_navigation (0.9)
* rack (1.6.4)
* rack-test (0.6.3)
* rspec (3.4.0)
* rspec-core (3.4.4)
* rspec-expectations (3.4.0)
* rspec-mocks (3.4.1)
* rspec-support (3.4.1)
* rubyzip (1.2.0)
* selenium-webdriver (2.53.0)
* snapurl (0.0.3)
* syntax (1.2.0)
* thread_safe (0.3.5)
* tzinfo (1.2.2)
* watir-webdriver (0.9.1)
* websocket (1.2.2)
* xpath (2.0.0)
* yml_reader (0.7)
* zip-zip (0.3)

操作系统:openSuSE 13.1 浏览器:Firefox 45.0

错误发生在每个循环内(1到2分钟之后),无论我是在观看Firefox还是让它无头运行。

步骤代码(来自评论中的pastebin链接)

Then /^I should XY$/ do
  today = Date.today
  heute = today.to_s.sub(/(\w+)-(\w+)-(\w+)/, '\\3.\\2.\\1')
  letzter_tag = Date.today.end_of_month
  differenz = letzter_tag - today
  ueber_naechster_monats_beginn = Date.today.at_beginning_of_month.next_month.next_month
  deutscher_ueber_naechster_monats_beginn = ueber_naechster_monats_beginn.to_s.sub(/(\w+)-(\w+)-(\w+)/, '\\3.\\2.\\1')
  puts 'Heute ist das Datum: '+today.to_s
  puts 'Der letzte Tag des aktuellen Monats ist: '+letzter_tag.to_s
  puts 'Bis zum letzten Tag des aktuellen Monats sind es noch: '+differenz.to_s+' Tage'
  if differenz < 9 || differenz < 0
    puts "Der Monatswechsel liegt an, das neue Datum für den Monatsbeginn ist: "+ueber_naechster_monats_beginn.to_s
  else
    puts "Kein Monatswechsel liegt an."
  end
  tabellen_zeilen = @browser.table(:id => 'tabellenanfang').tbody.rows
  puts tabellen_zeilen.count.to_s+' Tabellenzeilen gefunden'
  link_list_2_mit_monats_wechsel = Array.new
  link_list_2_ohne_monats_wechsel = Array.new
  link_list_2 = Array.new
  link_list_1 = Array.new
  tabellen_zeilen.each do |tabellen_zeile|
    if !tabellen_zeile.cell(:index => 2).div.text.include?("nicht veröffentlicht")
      link_list_2 << tabellen_zeile.cell(:index => 0).div.a.text
      puts 'veröffentlicht: '+tabellen_zeile.cell(:index => 0).div.a.text
      beginn_datum = Date.parse(tabellen_zeile.cell(:index => 3).div.text)
      puts '  Beginn Datum ist: '+beginn_datum.to_s
      aktuelle_differenz = beginn_datum - today
      puts ' '
      # 
      if aktuelle_differenz < 10 || aktuelle_differenz < 0
        link_list_2_mit_monats_wechsel << tabellen_zeile.cell(:index => 0).div.a.text
        puts "  "
      else
        link_list_2_ohne_monats_wechsel << tabellen_zeile.cell(:index => 0).div.a.text
        puts "  "
      end
    else
      link_list_1 << tabellen_zeile.cell(:index => 0).div.a.text
      puts ' '
    end
  end
  puts ' '
  link_list_2.each { |link_text|
    puts '____________________________________________________________________________________________'
    puts ''
    puts link_text
    puts ''
    puts '____________________________________________________________________________________________'
    link = @browser.link(:text => link_text)
    begin
      link.click
    rescue Watir::Exception::UnknownObjectException => i #catch the Exception
      @browser.refresh
      link.wait_until_present(600)
      link.click
      puts "Objekt konnte nicht geklickt werden: #{i}"
    end
    puts '    Link geöffnet'
    begin
        @browser.input(:id => 'tab1').wait_until_present(600)
        @browser.input(:id => 'tab1').click
    rescue Watir::Exception::UnknownObjectException, TimeoutError => j #catch the Exception
      @browser.refresh
      @browser.input(:id => 'tab1').wait_until_present(600)
      @browser.input(:id => 'tab1').click
      puts "Objekt konnte nicht geklickt werden: #{j}"
    end
    puts ' '
    @browser.element(:id => 'begin_field').wait_until_present(600)
    @browser.element(:id => 'begin_field').exists?.should == true
    @browser.text_field(:id => 'begin_field').set heute
    @browser.element(:id => 'speichern_unten').wait_until_present(100)
    @browser.input(:id => 'speichern_unten').click
    begin
      @browser.input(:id => 'tab2').click
    rescue Watir::Exception::UnknownObjectException => e #catch the Exception
      @browser.refresh
      @browser.input(:id => 'tab2').wait_until_present(100)
      @browser.input(:id => 'tab2').click
      puts "Objekt konnte nicht geklickt werden: #{e}"
    end
    puts ' '
    begin
      @browser.element(:id => 'begin_date').wait_until_present(100)
      @browser.element(:id => 'begin_date').exists?.should == true
      @browser.text_field(:id => 'begin_date').set heute
    rescue Watir::Exception::UnknownObjectException, TimeoutError => l #catch the Exception
      @browser.refresh
      @browser.element(:id => 'begin_date').wait_until_present(100)
      @browser.element(:id => 'begin_date').exists?.should == true
      @browser.text_field(:id => 'begin_date').set heute
    end    
    begin
      @browser.element(:id => 'speichern_unten').wait_until_present(600)
      @browser.input(:id => 'speichern_unten').click
    rescue Watir::Exception::UnknownObjectException, TimeoutError => h #catch the Exception
      puts "Objekt konnte nicht geklickt werden: #{h}"
      @browser.refresh
      @browser.element(:id => 'speichern_unten').wait_until_present(600)
      @browser.input(:id => 'speichern_unten').click
    end    
    begin
      @browser.element(:id => 'tab1').wait_until_present(600)
      @browser.input(:id => 'tab1').click
    rescue Watir::Exception::UnknownObjectException, TimeoutError => g #catch the Exception
      puts "Objekt konnte nicht geklickt werden: #{g}"
      @browser.refresh
      @browser.element(:id => 'tab1').wait_until_present(600)
      @browser.input(:id => 'tab1').click
    end
    puts ' '
    begin
      @browser.element(:id => 'begin_field').wait_until_present(600)
    rescue Watir::Wait::TimeoutError => k
      puts "Objekt konnte nicht geklickt werden: #{k}"
      @browser.refresh
      @browser.element(:id => 'begin_field').wait_until_present(600)
    end
    @browser.element(:id => 'begin_field').exists?.should == true
    @browser.element(:id => 'begin_field').html.include?(heute).should == true
    @browser.element(:id => 'tab2').wait_until_present(600)
    @browser.input(:id => 'tab2').click
    begin
      @browser.element(:id => 'begin_date').wait_until_present(100)
    rescue Watir::Wait::TimeoutError => f
      puts "Objekt konnte nicht geklickt werden: #{f}"
      @browser.refresh
      @browser.element(:id => 'begin_date').wait_until_present(100)
    end
    @browser.element(:id => 'begin_date').exists?.should == true
    @browser.element(:id => 'begin_date').html.include?(heute).should == true 
    puts '    neuer Veröffentlichungszeitraum auf '+heute+' gesetzt'
    @browser.link(:text => 'buttonText').click
    puts '____________________________________________________________________________________________'
    puts ''
  }
  puts ' '
  puts "----------------------------------------------------------------------------------------------"
  puts ' '
  puts ' '
  puts ' '
  puts ' '
  link_list_2_mit_monats_wechsel.each { |monats_wechsel_link_text|
    puts '____________________________________________________________________________________________'
    puts ''
    puts monats_wechsel_link_text
    puts ''
    puts '____________________________________________________________________________________________'
    link = @browser.link(:text => monats_wechsel_link_text)
    link.click    
    puts '    Link geöffnet'
    @browser.input(:id => 'tab3').click   
    puts '    Reiter 1 Stelleninfo geöffnet'
    @browser.element(:id => 'dateField').wait_until_present(600)
    @browser.element(:id => 'dateField').exists?.should == true
    puts ' '
    @browser.text_field(:id => 'dateField').set deutscher_ueber_naechster_monats_beginn
    @browser.input(:id => 'speichern_unten').click
    sleep 1
    @browser.input(:id => 'tab1').click
    sleep 1
    @browser.input(:id => 'tab3').click   
    puts '    Reiter 1 Stelleninfo zur Kontrolle geöffnet'
    sleep 1
    @browser.element(:id => 'dateField').wait_until_present(600)
    @browser.element(:id => 'dateField').exists?.should == true
    @browser.element(:id => 'dateField').html.include?(deutscher_ueber_naechster_monats_beginn).should == true
    puts ' '
    @browser.link(:text => 'buttonText').click
    puts '____________________________________________________________________________________________'
    puts ' '
  }
  puts ' '
end

env.rb(来自评论中的pastebin链接)

#!/bin/env ruby
# encoding: utf-8
# -*- coding: utf-8 -*- 
require 'rubygems'
require 'capybara'
# active_support wird fuer die Funktion end_of_month benoetigt
require 'active_support'
require 'active_support/core_ext'
require 'minitest'
require 'minitest/autorun'
require 'rspec/expectations'
require 'capybara/rspec'
require 'capybara/cucumber'
#require 'ruby_gntp'
require 'net/http'
#require 'escape_utils'
require 'watir-webdriver'
require 'page-object/page_factory'
World(PageObject::PageFactory)
require 'headless'
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 600 # seconds – default is 60
Capybara.run_server = true #Whether start server when testing
Capybara.default_selector = :css #default selector , you can change to :css
Capybara.default_max_wait_time = 180 #When we testing AJAX, we can set a default wait time
Capybara.ignore_hidden_elements = false #Ignore hidden elements when testing, make helpful when you hide or show elements using javascript

Before do
  @headless = Headless.new()
  @headless.start
  $DEBUG = true

  #profile = Selenium::WebDriver::Firefox::Profile.new
  @browser  = Watir::Browser.new :firefox, :http_client => client
  #@browser = Watir::Browser.new
  @browser.window.resize_to(2250, 1024)
end


After do
   @headless.destroy
   #@browser.close
end

我能尝试什么?

2 个答案:

答案 0 :(得分:0)

我刚刚想通了。在您的env.rb中,您正在设置水豚,但您正在使用watir创建浏览器。这不好,因为水豚和watir同时可能会产生冲突。切掉Capybara。仅使用watir。不要把水豚&#39;要求。这个建议比评论中的我的建议好得多。但我仍然不是百分百肯定。试试吧。

答案 1 :(得分:0)

这个链接起到了作用:https://watirmelon.com/2013/05/16/stop-firefox-auto-updating-and-breaking-your-ci-build/

启用全局调试后,我可以看到Firefox内部的h264插件正在尝试更新并破坏构建。

非常感谢你的帮助!