capybara

How can I include javascript with javascript_include_tag at the top of the page for a capybara test

一个人想着一个人 提交于 2019-12-23 23:16:26
问题 I am trying to test one javascript class in a spec test with capybara. I have static page player.haml in which I am loading the javascript class definition with javascript_include_tag. It looks like that .container = javascript_include_tag "../player" #player My test looks like that 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,

Models created with FactoryGirl aren't available in controller

谁都会走 提交于 2019-12-23 22:25:46
问题 Original question I'm trying to write some feature tests with RSpec and Capybara and wonder, why my gon object is always empty allthough it was set in my controller: app/controllers/timetrackings_controller.rb : class TimetrackingsController < ApplicationController include ApplicationHelper before_action :authenticate_user! before_action :set_timetracking, only: [:update, :destroy] # GET /timetrackings def index projects = Project.all_cached.select('id, name, category, number, customer_id')

How to test for input title/tooltip with rspec

社会主义新天地 提交于 2019-12-23 20:01:27
问题 How do you test for an input's title/tooltip with rspec? I wasn't testing for tooltips until I noticed a few stopped working and it wasn't caught by the other tests. (Had to add something so the question would be accepted) 回答1: How about: find('#element-locator')['title'].should == 'Expected title' 回答2: You can also look at the HTML attributes: expect(page).to have_selector("<selector>[data-content='<content>']") 来源: https://stackoverflow.com/questions/16698902/how-to-test-for-input-title

Trying to fillin second text box in capybara

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 19:26:40
问题 I am trying to fill in both textboxes that are labeled id="admin_passsword". I can access the first on easy but since there are NO differences other than the placeholder and the label above it I do not know how to access the second textbox to fill in that field. <div class="fields"> <div class="field-row"> <label for="admin_email">Email</label> <input autocapitalize="off" id="admin_email" name="admin[email]" placeholder="Email" size="30" type="text" value=""> </div> <div class="field-row">

How do I use Capybara get, show, post, put in controller tests?

拟墨画扇 提交于 2019-12-23 18:25:22
问题 I'm just not sure what the exact way to word it is.. This tells me 'No response yet. Request a page first.' it "should list searches" do get 'index' page.should have_selector('tr#search-1') end Is it meant to be like this instead? it "should list searches" do get 'index' do page.should have_selector('tr#search-1') end end That way doesn't seem to actually test anything though. What's the correct way? 回答1: According to this, Capybara doesn't support PUT and DELETE requests with the default

Capybara + Poltergeist with Database-cleaner not finding FactoryGirl records

懵懂的女人 提交于 2019-12-23 17:24:51
问题 I'm writing integration tests and creating records with FactoryGirl . My controllers are throwing RecordNotFound when the test has js: true (with Poltergeist) even though they are found in a non-js test (without Poltergeist). I do have use_transactional_fixtures set to false and DatabaseCleaner.strategy set to :truncation , which seemingly covers every existing SO question on this issue. I tried substituting Selenium (with Firefox) for Poltergeist but I get the same result. ETA I started a

Understanding native and send_keys in Capybara

痞子三分冷 提交于 2019-12-23 15:35:57
问题 I am trying to understand the meaning of the following Capybara syntax. What exactly does native do? What is send_keys used for? Also, I would like to understand what this particular block does. within('#step-3') do recipe_name = first(:xpath, '//*[@id="recipe-name"]').native recipe_name.clear recipe_name.send_keys('Email recipe') end 回答1: Capybara uses a driver to control a browser or browser simulator (Rack::Test, Poltergeist, Selenium, etc.). Each driver must implement the API that

Capybara and before(:all) in rspec

独自空忆成欢 提交于 2019-12-23 15:29:08
问题 Here's my complete spec: require 'spec_helper' describe "Idea page", js: true do subject { page } before(:all) do create(:idea) visit root_path click_link "Log In" end context "Single idea" do before do page.find(:xpath, '//*[@id="accordion"]/div/div[1]/a').click end it { should have_selector('a',text:'Claim') } it "should have a button for reporting the idea" it "should have a button for opening all links" describe "Claiming" do before do click_link "Claim" end it {should have_selector('a',

capybara finds button but clicking it does nothing

£可爱£侵袭症+ 提交于 2019-12-23 15:11:51
问题 UPDATE: I removed most javascript dependencies and it worked. Don't know what library or code is the evil part, I needed none of it. simple form, two input fields and a button fill_in 'cellNumber', :with => '13245678' fill_in 'password', :with => 'mypass' click_button('OK') It finds the button, but nothing happens. Important!, if I click the myself, everything works as expected. <button type="submit" id="loginid">OK</button> </form> Using ruby-debug, I find that find_button("OK").click

Capybara & RSpec

こ雲淡風輕ζ 提交于 2019-12-23 13:03:23
问题 I can't make Capybara to work successfully, it complains that has_text is an undefined method. I have created a new rails 3.1 project ( rails new test -T ). Gemfile: source 'http://rubygems.org' gem 'rails', '3.1.3' gem 'sqlite3' group :assets do gem 'sass-rails', '~> 3.1.5' gem 'coffee-rails', '~> 3.1.1' gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' group :test do gem 'rspec-rails' gem 'capybara' end I have installed the spec folder: rails g rspec:install . spec/spec_helper.rb: ENV[