黄瓜文件下载确认

发布于 2024-10-10 19:21:23 字数 520 浏览 4 评论 0原文

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

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

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

我已包含此 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

,但不起作用。

谢谢

I have a cucumber step where the file gets downloaded, but i am unable to click the save button in the dialog box that a browser provides, with cucumber step.

I have found some pages which solves the similar kind of problems, but it didn't solve mine

How to test a confirm dialog with Cucumber?

I have included this cucumber step for file download

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

But didn't work.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极致的悲 2024-10-17 19:21:23

您尝试过 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

伊恩。

Did you try the page.driver syntax?

i.e., from: How to test a confirm dialog with Cuccumber?:

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

ian.

萧瑟寒风 2024-10-17 19:21:23

我知道这已经很旧了,但由于这是我在寻找解决方案时遇到的第一个 SO 帖子之一,我想我应该发布一个解决方案。

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

Then /^I receive a PDF$/ do
  link_url = find_link("Report")[:href]
  file = open(link_url)
  file.content_type.should == 'application/pdf'
end

I know this is old, but since this was one of the first SO posts I came across when searching for solutions, I figured I'd post a solution.

We can use good ol Ruby, along with open-uri (so include open-uri in your Gemfile if you aren't already using it):

Then /^I receive a PDF$/ do
  link_url = find_link("Report")[:href]
  file = open(link_url)
  file.content_type.should == 'application/pdf'
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文