简体   繁体   中英

Rails Testing link found with rspec/Capybara but form not generated on click

My intention with this test is to find a Create link -- one of many hence I'm using first -- and then fill out a form that is generated with javascript upon clicking that link. Despite successfully finding the Create link and calling click on it, the form is not generated.

require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!

describe "user log in" do
  it "allows an existing user to sign in" do 
    visit "/users/sign_in"

    fill_in "Login", with: "Kevin"
    fill_in "Password", with: "abcdef"

    visit "/students/2/schedule"
    first(:link, 'Create').click

    within '#session_minutes' do
     find("option[value='60']").click
    end

  end
end

Is this possibly a javascript/rspec issue? After implementing phantomjs and poltergeist to generate JS actions on a headless browser I could not simulate the on hover effect needed to access the Create link so I'm not sure which testing method to pursue to ameliorate my situation.

You need to use a driver that supports javascript for that, capybara's default driver does not.

You can find the documentation for drivers here .

I prefer poltergeist because it's totally headless (doesn't require an actual browser) and so can run in a headless vagrant box. Selenium requires almost no setup if you already have Firefox installed.

To solve my issue I went with using poltergeist and phantomjs and then using the mouseover action as follows

require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!

describe "user log in" do
  it "allows an existing user to sign in" do 
    visit "/users/sign_in"

    fill_in "Login", with: "Kevin"
    fill_in "Password", with: "abcdef"

    visit "/students/2/schedule"
    first('.open').trigger('mouseover')

  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM