Tag: capybara

button_to表单提交在浏览器中工作但是没有rspec / capybara测试,路由错误

我正在使用rspec和capybara编写集成测试,用于覆盖现有function的rails4应用程序(当我第一次编写应用程序时,我很懒)。 以下提交按钮在浏览器(Chrome)中正常工作,并重定向到成功页面(如预期的那样) “open-contacts-dialog-btn”, :class => “inbox-sf-add-btn tip”, :style => “background:lightgreen” %> 但是,以下测试失败, describe “should show confirmation message after submitting the form” do it “should go to success message when form submitted” do click_link ‘See more details’ click_button ‘Sign Me Up!’ fill_in ‘Email’, with: “simon@example.com” fill_in ‘attendee_name’, with: “Simon T” fill_in ‘attendee_phone’, with: “1234567890” fill_in ‘attendee_num_guests’, […]

Capybara :: Webkit :: Driver的未定义方法accept_modal

在Rails应用程序中,我使用RSpec(使用Capybara Webkit)来测试Delete链接是否正常工作。 在我的Rails模板中,我有: 这是我的规格: require ‘rails_helper’ describe “Deleting a movie”, js: true do it “destroys the movie and shows the movie listing without the deleted movie” do movie = Movie.create(movie_attributes) visit movie_path(movie) page.accept_confirm do click_link ‘Delete’ end expect(current_path).to eq(movies_path) expect(page).not_to have_text(movie.title) end end 我收到错误: NoMethodError: undefined method `accept_modal’ for # 它使用正确的驱动程序(Webkit),但它似乎没有找到accept_modal (必须由page.accept_confirm )。 我正在使用: capybara […]

如何在页面顶部包含javascript_include_tag的javascript以进行水豚测试

我试图用capybara在spec测试中测试一个javascript类。 我有静态页面player.haml,我在其中使用javascript_include_tag加载javascript类定义。 它看起来像那样 .container = javascript_include_tag “../player” #player 我的测试看起来像那样 it ‘can autoplay a video’ do visit player_path video = Fabricate(:video) options = { autoplay: true, … } page.execute_script(“var options = ‘#{options}’; videoId = ‘#{video.id}’; var player = new Player(videoId, options);”) expect(page).to have_content(video.title) end 问题是javascript_include_tag包含页面底部的脚本和execute_script调用之后的脚本。 我在访问该页面后尝试了睡眠,但结果是一样的。 如何在使用execute_script之前加载类定义? 最终的瓶颈是具有播放器定义的文件是.coffee.erb。 我可以更改,因为它使用应用程序中的一些设置。

attach_file与capybara-webkit的工作方式不正确

我正在尝试将一些文件附加到此输入: 当我使用selenium驱动程序时,我的代码是: attach_file(‘image’, File.absolute_path(‘../pictures/pic1.JPG’)) attach_file(‘image’, File.absolute_path(‘../pictures/pic2.JPG’)) attach_file(‘image’, File.absolute_path(‘../pictures/pic3.JPG’)) 当我使用capybara-webkit时出现问题:由于隐藏了输入并且某些元素与其重叠,我需要更改一些css属性: page.execute_script(“$(‘input[name=image]’).css(‘opacity’,’1′)”) page.execute_script(“$(‘input[name=image]’).css(‘position’,’fixed’)”) page.execute_script(“$(‘input[name=image]’).css(‘top’,’620px’)”) 即使测试通过,图片也不会以正确的方式上传。 如果我使用page.save_screenshot(‘after_upload.png’)来查看发生了什么: 预期结果(使用selenium驱动时的结果) – > 使用capybara-webkit时的实际结果 – >

未定义的方法’has_selector?’ 用于rspec装饰器

我有以下rspec测试: # spec/decorators/user_decorator_spec.rb require File.expand_path ‘spec/spec_helper’ describe UserDecorator do let(:user) { UserDecorator.new build(:user, level: build(:level)) } subject { user } its(:avatar) { should have_selector ‘h6’ } end 我得到错误: Failure/Error: its(:avatar) { should have_selector ‘h6′ } NoMethodError: undefined method `has_selector?’ for # # ./spec/decorators/user_decorator_spec.rb:7:in `block (2 levels) in ‘ 我尝试了流行的建议: before { ApplicationController.new.set_current_view_context } 但后来它说undefined method […]

使用FactoryGirl创建的模型在控制器中不可用

原始问题 我正在尝试用RSpec和Capybara编写一些function测试,并想知道为什么我的gon对象总是空的,尽管它是在我的控制器中设置的: app/controllers/timetrackings_controller.rb : class TimetrackingsController false).order(:number) gon.projects = group_by_customer(projects).to_h gon.services = Service.all_cached.select(‘id, name’).where(:archived => false).order(‘LOWER(name)’) end … 现在我想知道为什么这些数据没有呈现到我的视图中(使用save_and_open_page : // ),所以我只是试图在我的测试文件中获取gon值: require ‘spec_helper’ describe ‘the timetracking page’, :js => true do before :each do switch_to_subdomain(‘test’) @project = FactoryGirl.create(:project) @service = FactoryGirl.create(:service) user = FactoryGirl.create(:user) login_as(user, :scope => :user) visit ‘/timetracking’ save_and_open_page end it ‘renders […]

Capybara 2.0和rspec-rails – 帮助程序在规范/function中不起作用

我正在尝试使用辅助模块中的方法,但rspec似乎没有识别spec/features下的测试帮助程序。 请注意,对spec_helper.rb的唯一更改是添加spec_helper.rb require ‘capybara/rspec’ 。 我尝试将helper.rb移动到spec/support , spec/helpers和spec/features (包含我的测试的目录),但没有运气。 测试表明辅助方法未定义。 让它“工作”的唯一方法是将我的测试移动到另一个目录,例如spec/integration 。 但现在水豚将无法工作( visit undefined ),因为它不符合spec/features 。 这是我的帮助模块( authentication_helper.rb ): module AuthenticationHelper def sign_in_as!(user) visit ‘/users/sign_in’ fill_in “Email”, with: user.email fill_in “Password”, with: “password” click_button “Sign in” page.should have_content(“Signed in successfully.”) end end RSpec.configure do |c| c.include AuthenticationHelper, type: :request end

如何在rails app上点击ruby中的水豚按钮

我正在尝试选择带水豚的单选按钮,但找不到单选按钮。 这是我的rspec测试,视图和错误。 请注意我使用工厂用于用户,技能等。 Rspec测试 scenario “user chooses a couple skills and moves on to bio” do user = create(:user) skill = create(:skill) skill_two = create(:skill) skill_three = create(:skill) sign_in(user) visit onboard_skills_path choose(skill.name) end 视图 “, class: “submit_skills” %> 我得到的错误是: Unable to find radio button “Development 1”

Capybara + Poltergeist与Database-cleaner没有找到FactoryGirl记录

我正在编写集成测试并使用FactoryGirl创建记录。 当测试具有js: true (使用Poltergeist)时,我的控制器正在抛出RecordNotFound ,即使它们是在非js测试中找到的(没有Poltergeist)。 我确实将use_transactional_fixtures设置为false ,将DatabaseCleaner.strategy设置为:truncation ,它似乎涵盖了此问题上每个现有的SO问题。 我尝试用Selenium(用Firefox)代替Poltergeist,但我得到了相同的结果。 ETA我用RSpec-Rails 3.3.3,Capybara 2.4.4,Poltergeist 1.6.0,PhantomJS 1.9.8,Database Cleaner 1.4.1开始了一个新的Rails 4.2.3项目,并在测试一个新的未经编辑的脚手架时获得相同的结果。 为什么Poltergeist找不到我的记录? 任何建议都会有所帮助,因为我已经在这里工作了几个小时。 前两个测试通过,而最后一个测试通过RecordNotFound在第二行失败: require ‘spec_helper’ before :each do @vehicle = FactoryGirl.create :vehicle end it “should work on vehicle path” do visit vehicle_path(@vehicle) expect(page).to have_content @vehicle.name end describe “with js”, js: true do it “should work on root path” […]

Rspec + Capybara可选择更改JS驱动程序

我使用poltergeist / phantomjs作为CI,但我希望能够选择将JS驱动程序更改为selenium以观察我的本地测试运行。 理想情况下,我想为这个默认的poltergeist设置一个命令行标志,但是能够运行rspec –driver = selenium(或类似的东西) 有任何想法吗?