Capybara的have_selector没有看到jQuery fileupload输入

时间:2013-09-16 09:39:58

标签: ruby-on-rails rspec capybara rspec2 jquery-file-upload

我正在使用Rails 3.2.14,Capybara 2.1.0,jquery-fileupload-rails 0.4.1。

如果我尝试围绕文件上传编写测试,但是capybara找不到文件输入。规范片段:

  describe "Create with all required fields filled" do
    before do
      choose "Revision File"
      select "Publish", from: "file_asset[file_type_ref_id]"
      click_button "Next"
      script = "$('input[type=file]').show();" # added later
      page.driver.browser.execute_script(script)
      print page.html # to debug the page
      subject { page }
    end

    describe "Save should create a FileAsset" do
      it { should have_selector("span.fileinput-button span") }
      it { should have_selector("span.fileinput-button input") }
    end

rspec结果:

Failures:

  1) FileAsset Pages New-Create (revision file) Without Authorizations Create with all required fields filled Save should create a FileAsset
     Failure/Error: it { should have_selector("span.fileinput-button input") }
       expected #has_selector?("span.fileinput-button input") to return true, got false
     # ./spec/requests/file_asset_pages_spec.rb:63:in `block (6 levels) in <top (required)>'

Finished in 16.95 seconds
2 examples, 1 failure

即,第一个示例成功运行,但第二个示例不成功,但html页面包含两个(print page.html的输出片段):

<div class="row fileupload-buttonbar">
  <div class="span7">
    <!-- The fileinput-button span is used to style the file input field as button -->
    <span class="btn btn-small btn-success fileinput-button">
      <i class="icon-plus icon-white"></i>
      <span>Select and Upload File</span>
      <input type="file" name="upload[upload]" id="upload_upload" />
    </span>
  </div>
</div>

输入未隐藏,跨度位于同一div中。我当然试过“#upload_upload”作为选择器,结果是一样的。在规范中我稍后将两行添加到show()输入,没有它们的结果是相同的。

感谢任何帮助。

0 个答案:

没有答案