capybara selenium和JavaScript Destroy

Nic*_*ilt 5 selenium ruby-on-rails cucumber capybara

我正在使用rails 2.3.5,这就是我所做的.我安装了最新的黄瓜,黄瓜导轨和水豚.

rails demo
cd demo
ruby script/generate cucumber --rspec --capybara
ruby script/generate feature post title:string body:text published:boolean
ruby script/generate scaffold post title:string body:text published:boolean
rake db:migrate
rake cucumber
Run Code Online (Sandbox Code Playgroud)

所有的测试都在通过.现在我想用Javascript测试.

此时这就是场景的样子

  Scenario: Delete post
    Given the following posts:
      |title|body|published|
      |title 1|body 1|false|
      |title 2|body 2|true|
      |title 3|body 3|false|
      |title 4|body 4|true|
    When I delete the 3rd post
    Then I should see the following posts:
      |Title|Body|Published|
      |title 1|body 1|false|
      |title 2|body 2|true|
      |title 4|body 4|true|
Run Code Online (Sandbox Code Playgroud)

我在顶部添加了@javascript.

现在,当我运行rake cucumber时,我看到一个确认页面.但是在我点击之前没有任何反应

我需要做什么才能自动点击确定并提前进行测试.

spa*_*pas 8

嗯,这是一种黑客,但我认为现在它是唯一的方式:

When /^I confirm a js popup on the next step$/ do
  page.evaluate_script("window.alert = function(msg) { return true; }")
  page.evaluate_script("window.confirm = function(msg) { return true; }")
end
Run Code Online (Sandbox Code Playgroud)

您必须将此步骤放在触发确认弹出窗口的步骤前面(在链接后面).它将修改标准警报并确认行为始终返回true.所以你不必自己点击"确定"按钮.