用capybara点击div规范之外

时间:2014-05-08 07:39:03

标签: javascript ruby-on-rails rspec capybara

我目前有一个按钮点击弹出的模态。如果用户在主模式对话框外单击,我将执行该工作,它将关闭模式。

我现在正在用rspec和capybara编写规范。我之前的块

  before do
    find("#inquiries-new").click
    should_not have_content('CAMPAIGN INQUIRY')
  end

当我运行规范

时,我得到了这个
  1) Inquiry popup close popup by clicking outside modal-dialog open again to test duplicated view
  Sauce public job link: 
     Failure/Error: should_not have_content('CAMPAIGN INQUIRY')
       expected not to find text "CAMPAIGN INQUIRY" in "Lorem Ipsum Customers Close CAMPAIGN INQUIRY NAME EMAIL COMPANY CAMPAIGN TITLE BUDGET PHONE DESCRIPTION SEND INQUIRY"
     # ./spec/features/home/inquiry_popup_spec.rb:34:in `block (4 levels) in <top (required)>'

有没有办法为此行为创建规范?

2 个答案:

答案 0 :(得分:1)

我可以通过执行一些带有capybara的JavaScript来点击模态外部

    page.execute_script('$(document.elementFromPoint(50, 350)).click();')

坐标适用于我的特定情况,但其他人应该能够根据自己的情况编辑它们。

答案 1 :(得分:0)

page.find(:xpath, "//*[text()='#{text_to_click}']").click

text_to_click是模型之外的某些文字。