Button 尝试单击按钮/提交表单时,Capybara rspec行为不一致
这是导致我浪费时间的事情,我希望我知道为什么。我发现了很多例子(不是全部答案),表格没有被提交,它在网页上工作,但在水豚中不起作用。像find/xpath这样的东西在irb中工作 网页 带有上载按钮的文件框,附加文件有效(我使用poltergeist渲染查看附加的文件名) 已尝试调试/选项Button 尝试单击按钮/提交表单时,Capybara rspec行为不一致,button,rspec,capybara,Button,Rspec,Capybara,这是导致我浪费时间的事情,我希望我知道为什么。我发现了很多例子(不是全部答案),表格没有被提交,它在网页上工作,但在水豚中不起作用。像find/xpath这样的东西在irb中工作 网页 带有上载按钮的文件框,附加文件有效(我使用poltergeist渲染查看附加的文件名) 已尝试调试/选项 find()工作,例如在irb中,它返回一个对象:Capybara元素tag=input 如果我尝试“访问“”,它将返回{“status”=>“fail”,“click”=>{“x”=>124,“y”=>2
- find()工作,例如在irb中,它返回一个对象:Capybara元素tag=input
- 如果我尝试“访问“”,它将返回{“status”=>“fail”,“click”=>{“x”=>124,“y”=>283}[该操作调用的日志中没有任何内容。在开发环境中肯定有效]
- 点击“上传”失败:{“状态”=>“失败”,“点击”=>{“x”=>124,“y”=>283}
- 查找按钮(“上载”)。单击:{“状态”=>“失败”,“单击”=>{“x”=>124,“y”=>283}}
- 查找(“上传账单”按钮1)。触发(“点击”):返回“点击”
- 我尝试过javascript checkBill()的exec_脚本。page.execute_脚本('checkBill()'):返回nil
- 查找(:css,#upload_bill_button1')。单击。返回:{“x”=>124,“y”=>282}
- js=>true作为javascript提交(首先进行测试,代码如下)
- 确保所有ID都是唯一的
- 添加了水豚::DSL
- macoxx
- 恶鬼(为我所有的其他测试工作)
- ruby 1.9.3
- 幻影1.9.2
<div class="row">
<div class="large-10 columns" >
<%=form_tag( "/upload_bill", :method=>:post, :multipart => true, :id => "form_upload1") do -%>
<fieldset>
<legend>Select your bill file</legend>
<%=file_field_tag 'bill', :onclick => "checkBill()" -%>
<div class="large-2 columns" >
<!-- TODO: make the browse button the zurb class type -->
<%- if params[:action].eql?( 'index')%>
<%=submit_tag "Upload", :onclick => "checkBill();return false;", :id => "upload_bill_button1", :class => "button postfix" -%>
<% end %>
</div>
</fieldset>
<% end %>
</div>
</div>
<%- if params[:action].eql?('import_bill')%>
<%=link_to (image_tag "/images/btn-uploadbill.png"), "#", :onclick=>"checkBill();return false;", :id => "upload_bill_button2" -%>
<%=link_to (image_tag "/images/btn-cancel.png"), root_path %>
<%- end %>
<script type="text/javascript">
function checkBill(){
var bill = $("#bill").val();
if(bill.split('.').reverse()[0]=="csv"||bill.split('.').reverse()[0]=="pdf"||bill.split('.').reverse()[0]=="pdftranslatedtxt"){
//success bill supported, data send to app
jQuery('#form_upload1').submit();
}
else if(bill==""){return false; }
else{// return error wrong format of bill alert('We only currently support PDF or CSV file format.')
}
}
</script>
我已经调试了页面输出
puts page.html
工作的页面html和不工作的页面html之间没有区别,但在某些情况下,它拒绝单击或poltergeist.render不更新
根据这个恶作剧bug(),我尝试删除full:true。没有区别
还有其他人遇到过这些不一致吗?我遇到了一些奇怪的情况,有时测试正常通过,但有时我得到
Capybara::ElementNotFound
。在我的用例中,涉及到一些角度,所以我想知道这是否是原因。
puts page.html