Twitter引导模式的黄瓜功能

Cucumber feature for twitter bootstrap modal

本文关键字:黄瓜 功能 模式 Twitter      更新时间:2023-09-26

>我正在编写一个黄瓜功能,我想删除一个类别,但在删除它之前,我会显示一个模态屏幕来询问用户的体型。

我正在使用Twitter引导程序并使用他们提供的javscript模式。

但是我被困住了,所以任何人都可以直接帮助我如何测试这个。这是我到目前为止的功能:

  Scenario: Delete category with articles
   Given I am logged in as an admin
   And I have category titled Paints
   When I go to the list of categories
   And I push delete button for the Paints category
   Then I should get a popup to confirm

我已经实现了该功能的必要步骤,当然接受最后一个。但是我不知道如何开始:

我读了一些关于page.driver.browser.switch_to.alert的东西,但现在不要,如果这可行的话。

有人有一些建议吗?

多谢。

正如您在问题中所建议的,您可以使用硒驱动程序访问对话框。 我假设您使用的是 Capybara,因此您可以通过以下方式定义用于接受/取消弹出窗口的步骤定义:

Then /^I accept the popup to confirm$/
  page.driver.browser.switch_to.alert.accept 
end
Then /^I cancel the popup to confirm$/
 page.driver.browser.switch_to.alert.dismiss
end

编辑:似乎模态实际上不是一个窗口...让我们像这样尝试一下:

创建一个帮助程序函数来检测模态元素是否在周围:

def find_modal_element
  wait_until { page.find(modal_element_id).visible? }
end

然后让我们更改步骤定义:

Then /^I should see a popup window$/
 find_modal_element
 page.find(modal_element_id).text.must_match "Whatever you want it to match"
end