2

我有一个下载文件的黄瓜步骤,但我无法单击浏览器提供的对话框中的保存按钮,带有黄瓜步骤。

我找到了一些解决类似问题的页面,但它没有解决我的问题

如何用 Cucumber 测试确认对话框?

我已包含此黄瓜步骤以供文件下载

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

但是没有用。

谢谢

4

2 回答 2

3

您是否尝试过 page.driver 语法?

即,来自:如何使用 Cucumber 测试确认对话框?

When /^I confirm popup$/ do
  page.driver.browser.switch_to.alert.accept    
end

When /^I dismiss popup$/ do
 page.driver.browser.switch_to.alert.dismiss
end

伊恩

于 2011-06-22T00:33:36.117 回答
1

我知道这是旧的,但由于这是我在搜索解决方案时遇到的第一个 SO 帖子之一,我想我会发布一个解决方案。

我们可以使用好的 ol Ruby 以及 open-uri(如果您还没有使用它,请在您的 Gemfile 中包含 open-uri):

Then /^I receive a PDF$/ do
  link_url = find_link("Report")[:href]
  file = open(link_url)
  file.content_type.should == 'application/pdf'
end
于 2014-04-26T21:20:23.300 回答