【问题标题】:poltergeist working on development, not on CI致力于开发而不是 CI 的捣蛋鬼
【发布时间】:2015-07-13 19:39:32
【问题描述】:

我一直在使用 poltergeist 和 capybara 为我的网站编写一些测试,它们都通过了我的开发机器,但在我正在使用的持续集成平台(Codeship)上失败了。我已经查过它并尝试了所有不同的解决方案,但我唯一可以让它工作的是如果我切换到 selenium,如果可能的话我宁愿不这样做。我想知道是否有人对此有一些建议,我在网上看到了很多关于它的主题,但到目前为止没有任何东西对我有用。

在我的代码中,page.should have_content("Post created successfully.") 在我的所有测试中都失败了,因为它无法在创建地图文件时加载的页面上找到此消息(因为由于某种原因它还没有到达那里) .我已经尝试过所有类型的睡眠,现在我的 spec_helper.rb 中的等待时间设置为 20 秒。

示例代码如下:

add_mapfile_spec.rb

before(:each) do 
    sign_in_and_create_facility
end

scenario 'Creating a mapfile works from locations path' do
    add_mapfile_to_facility_from_main("Bat Cave", "save")  

    page.should have_content("Post created successfully.")
    page.should have_content("Facility: Bat Cave")
    page.should have_content("definitelynotbrucewayne@digitallumens.com")
    page.should have_content("save.map")
    page.should have_content("Cannot Move")


    visit locations_path
    page.should have_content("definitelynotbrucewayne@digitallumens.com")
    page.should have_content("save.map")
end

添加地图文件功能

  def add_mapfile_to_facility_from_main(name, mapfile)
    visit locations_path
    find('#create-map').click
    select "#{name}", :from => "post[location_id]"
    attach_file('post_mapfile', File.join(Rails.root.to_s, 'spec', 'fixtures', "#{mapfile}.map"))
    find('#submit-map').click
    sleep(1)
  end

Sign_in_and_create_facility 按预期工作,所以我知道它不是那个功能。 js 在这些上设置为 true。

非常感谢任何帮助,我已经为此苦苦挣扎了几天

【问题讨论】:

  • 这可能是由于多种原因...我可以建议调试这是查看失败后生成的屏幕截图...将以下代码添加到您在 spec_helper 中的水豚配置中:水豚: :Screenshot.register_filename_prefix_formatter(:rspec) 做 |example| "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}" end screenshot_path = "#{PROJECT_ROOT}/screenshot/#{ENV ['ENV']}" config.save_and_open_page_path = screenshot_path

标签: javascript ruby-on-rails testing capybara poltergeist


【解决方案1】:

这可能是由于很多原因...我可以建议调试这是查看失败后生成的屏幕截图...将以下代码添加到您在 spec_helper 中的 capybara 配置中:

Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
    "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
end
screenshot_path = "#{PROJECT_ROOT}/screenshot/"
config.save_and_open_page_path = screenshot_path

【讨论】:

    【解决方案2】:

    真的从来没有找到答案,只是偶尔失败/通过,所以我添加了一个名为 rspec-rerun 的新 gem,并将其设置为 CI 平台上的默认 rake 命令。多次重新运行测试似乎可以使其工作,但速度并不快。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 2019-08-22
      • 2018-06-03
      相关资源
      最近更新 更多