简体   繁体   English

使用rspec / Capybara找到了Rails Testing链接,但单击时未生成表格

[英]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. 我打算进行此测试的目的是找到“创建”链接-因此我first使用了许多链接-然后填写单击该链接时使用javascript生成的表单。 Despite successfully finding the Create link and calling click on it, the form is not generated. 尽管成功找到了Create链接并调用了它,但仍未生成该表单。

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? 这可能是javascript / rspec问题吗? 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. 在实现phantomjs和poltergeist在无头浏览器上生成JS操作之后,我无法模拟访问Create链接所需的on-hover效果,因此我不确定要采用哪种测试方法来改善我的情况。

You need to use a driver that supports javascript for that, capybara's default driver does not. 您需要使用支持javascript的驱动程序,而capybara的默认驱动程序则不支持。

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. 我更喜欢poltergeist,因为它完全没有头(不需要实际的浏览器),因此可以在无头的无聊的盒子中运行。 Selenium requires almost no setup if you already have Firefox installed. 如果您已经安装了Firefox,则Selenium几乎不需要进行任何设置。

To solve my issue I went with using poltergeist and phantomjs and then using the mouseover action as follows 为了解决我的问题,我使用了poltergeist和phantomjs,然后使用mouseover操作,如下所示

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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