2

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

Community
  • 1
  • 1
Gagan
  • 4,278
  • 7
  • 46
  • 71

2 Answers2

3

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.

Community
  • 1
  • 1
ipd
  • 5,674
  • 3
  • 34
  • 49
1

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
Cory Foy
  • 7,202
  • 4
  • 31
  • 34