Tag: capybara

为什么capybara在请求规格中不可用?

使用rspec和capybara处理新的Rails 3.2.9应用程序。 我在Gemfile中有以下内容: gem ‘rspec-rails’ gem ‘capybara’ 以及spec / spec_helper.rb中的以下内容: require ‘rspec/rails’ require ‘capybara/rspec’ 并在spec / requests / asdf_spec.rb中: require ‘spec_helper’ describe ‘Asdf’ do describe “GET /asdfs” do it “should list asdfs” do visit asdfs_path end end end 此测试失败: Failure/Error: visit asdfs_path NoMethodError: undefined method `visit’ for # # ./spec/requests/asdfs_spec.rb:19:in `block (4 levels) in ‘ […]

Capybara需要睡觉吗?

显然,根据网页 更新 ,使用最新版本的wait_until , sleep或wait_until无效。 但是,如果我在测试中添加sleep(1)调用,我有一组仅适用于快速计算机的测试。 也就是说,测试看起来像: describe “dosimeters page” do before do click_link(“Dosimeter Read History”, :match=>:first) end … 变 describe “dosimeters page” do before do unix_wait click_link(“Dosimeter Read History”, :match=>:first) end … 我把unix_wait定义为: def unix_wait case RbConfig::CONFIG[‘host_os’] when /darwin/ when /linux-gnu/ sleep(1) end end 问题是,我有一台旧的Ubuntu 12.04四核笔记本电脑在Jenkins上运行这些测试,一切都运行良好,没有unix_wait调用。 测试在运行Ubuntu 13.10和macbook pro笔记本电脑的unix_wait桌面上随机失败,但如果我添加了unix_wait调用,则测试通过。 测试失败本身表示加载失败(即某些运行中缺少css元素,但其他运行中没有),并且当手动加载站点时,被测试的内容实际上有效。 那么这里适当的行动是什么? 显然,测试期间不允许sleep , wait_until也wait_until […]

为什么我不能从Rspec测试中访问Rails的URL助手?

最初我用Cucumber和Capybara写了我的测试,这很好。 然后我转而使用Rpsec和Capybara,这也很好。 然后我在尝试让资产管道工作时删除了我的gemlock文件,突然我的测试中的URL帮助程序停止工作。 示例错误: Failure/Error: visit report_areas_path(@report) NoMethodError: undefined method `visit’ for # # ./spec/features/area_spec.rb:12:in `block (3 levels) in ‘ 我想让URL助手再次工作,这样我的测试可以指导我完成资产管道的实施。 我怎样才能解决这个问题? 我的所有测试都在/ spec / features中。 相关软件如下…… /spec/spec_helper.rb: require ‘rubygems’ require ‘spork’ Spork.prefork do end Spork.each_run do # This code will be run each time you run your specs. end ENV[“RAILS_ENV”] ||= ‘test’ require File.expand_path(“../../config/environment”, […]

如何在Rails 5.1中运行无头浏览器系统测试?

Rails 5.1系统测试的文档有点稀疏。 我无法进行执行javascript运行的无头测试。 我认为一种方法需要安装和运行xvf。 但这比我在其他版本的rails中运行capybara时使用的手动设置更多。 实现这一目标最简单的方法是什么?

测试此post模型的草稿属性(Rspec + Capybara)

我想用Rspec和Capybara写一个测试。 我有一个Post模型,我想为它添加一个draft属性。 如果用户检查该字段,则将post保存为草稿( draft = true )。 只有属性draft = false的post才会显示在post索引页面中。 draft = truepost只会显示在创建该post的用户的页面中。 在我的生命中,我从未做过Rspec + Capybara测试。 所以我想知道是否有人可以告诉我如何开始或给我一个例子。 提前致谢! schema.rb: create_table “posts”, :force => true do |t| t.string “title” t.string “content” t.integer “user_id” t.datetime “created_at”, :null => false t.datetime “updated_at”, :null => false t.integer “comments_count”, :default => 0, :null => false t.datetime “published_at” t.boolean “draft”, :default […]

rspec + capybara undefined局部变量或方法

#gemfile … gem ‘rspec-rails’ gem ‘capybara’ 我根据官方文档在spec_helper.rb中添加了’require’capybara / rails’。 我已经生成了一个测试: $rails generate integration_test authentication_pages 我写了一个测试: #spec/features/authentication_pages_spec.rb describe “Authentication” do subject { page } describe “signin” do before { visit new_user_session_path } describe “with invalid information” do before { click_button “Sign in” } it { should have_title(‘Sign in’) } end end end 运行测试我有一个错误: $rspec spec/features/authentication_pages_spec.rb F […]

NoMethodError:在rails控制台中运行capybara测试时未定义的方法`color_enabled =’

NoMethodError: undefined method `color_enabled=’ for # from /Users/apple/.rvm/gems/ruby-2.0.0-p247@global/gems/rspec-console-0.2.7/lib/rspec-console/config_cache.rb:69:in `method_missing’ 我不知道怎么解决它〜 有什么建议吗? THX〜

如何在集成测试中编写用于签署用户的快捷方式?

在这个问题的讨论的启发下,我想为我的集成测试编写一个登录方法。 在我的test_helper.rb我甚至找到了这样一个方法,但它是在ActiveSupport::TestCase类中定义的,我的测试inheritance自ActionDispatch::IntegrationTest 。 所以我复制了方法并将它(在test_helper.rb )放入ActionDispatch::IntegrationTest类中。 但它不起作用,我的测试失败了这条消息: Capybara::ExpectationNotMet: expected “data:,” to include “Study | Word Up” 它实际上从未在浏览器中实际打开应用程序。 所以我的问题是,我可以在集成测试中使用这样的快捷方式,如果是的话,怎么样? 我正在使用带有has_secure_password的构建身份validation和Michael Hartl在他的Railstutorial中显示的机制。 这是我的test_helper.rb : ENV[‘RAILS_ENV’] ||= ‘test’ require File.expand_path(‘../../config/environment’, __FILE__) require ‘rails/test_help’ require ‘minitest/rails’ require ‘minitest/rails/capybara’ require ‘capybara/rails’ require ‘capybara/poltergeist’ class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! fixtures :all # Logs in a test user. def log_in_as(user, options = {}) password = […]

FactoryGirl – validation失败:时区未包含在列表中

我正在使用Rspec,FactoryGirl和Capybara。 使用ActiveSupport :: TimeZone.us_zones时。 我为我的requests/users_spec运行我的测试,它甚至没有达到测试,因为它在工厂有问题。 这是错误: Failure/Error: make_user_and_login ActiveRecord::RecordInvalid: Validation failed: Time zone is not included in the list # ./spec/support/user_macros.rb:3:in `make_user_and_login’ # ./spec/requests/users_spec.rb:7:in `block (3 levels) in ‘ 这是我的设置: 应用程序/模型/ user.rb class User /^(?=(.*[a-zA-Z]){3})[a-zA-Z0-9]+$/ validates_uniqueness_of :email validates_uniqueness_of :username, :case_sensitive => false validates_length_of :username, :within => 3..26 validates_inclusion_of :time_zone, :in => ActiveSupport::TimeZone.us_zones end 投机/ spec_helper.rb […]

从capybara-webkit #execute_script访问DOM?

所以我试图测试jQueryUI可排序库触发ajax请求并且我没有成功触发它,我已经尝试使用jquery.simulate.drag-sortable.js库,但无济于事。 我也尝试过执行脚本function,也无济于事。 我试图手动触发可排序的停用事件,因为即使在浏览器中jQuery.trigger()似乎也无法使用它。 执行的脚本是$sortable.sortable(“option”, “deactivate”)(event, ui) ,事件和ui正确注入,当我直接将它输入浏览器时,此代码可以正常工作。 问题似乎源于无法访问DOM。 当我在驱动程序上启用调试模式时,错误是TypeError: ‘[object Object]’ is not a function (evaluating ‘$sortable.sortable(“option”, “deactivate”)(event, ui)’) 。 深入挖掘后发现,Javascript驱动程序无法访问#execute_javascript DOM节点。 当我输入console.log(document.getElementById(‘sortable’)); 响应为’null’ 。 有关如何使用capybara-webkit触发使用deactivate事件的jQueryUI可排序函数的任何想法?