Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:06:31+00:00 2026-06-06T01:06:31+00:00

I am working on a tests scenario that downloads a file from a website

  • 0

I am working on a tests scenario that downloads a file from a website and adds it to folder.
For the download part, I am using the code described on the browser-downloads page within the Watir documentation.
The main problem was encountered in my tests when I am waiting for the file to be downloaded:

    def verify_csv_file_exists
     path = Dir.getwd + "/downloads/"
     until File.exist?("#{path}*.csv") == true
      sleep 1
     end 
    end

When running the tests, the procedure above never stops, because it cannot see the file in the directory, although the file is downloaded.

Does anyone know a way how I can handle this situation?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:06:33+00:00Added an answer on June 6, 2026 at 1:06 am

    You simply check the directory contents before you download the file, then wait until there’s a new file added to the directory (by comparing the current content with the previous content). This is how you get the new file name:

    This should do the job:

    require 'watir-webdriver'
    
    file_name = nil
    download_directory = "#{Dir.pwd}/downloads"
    download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
    downloads_before = Dir.entries download_directory
    
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile['browser.download.folderList'] = 2 # custom location
    profile['browser.download.dir'] = download_directory
    profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
    
    b = Watir::Browser.new :firefox, :profile => profile
    
    b.goto 'https://dl.dropbox.com/u/18859962/hello.csv'
    
    30.times do
      difference = Dir.entries(download_directory) - downloads_before
      if difference.size == 1
        file_name = difference.first 
        break
      end  
      sleep 1
    end
    raise "Could not locate a new file in the directory '#{download_directory}' within 30 seconds" if not file_name
    puts file_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project using Scala running Selenium tests as part of a
I'm writing Unit-Tests for an OK_Execute Command in an MvvM-Scenario. Now that's working fine
I am working a project with many NUnit tests, that were already written long
I have a working workflow in CruiseControl.Net that successfully builds and tests an MSBuild
So here's the scenario. I've got a script that runs some tests. I need
I've started using a WebRequest to retrieve a file from a given URL. If
I am working on a asp.net web application that has is a part of
I'm working on creating a tests, and I can't figure out why the creation
I am working with Erlang and EUnit to do unit tests, and I would
I am working on a project to automate the calibration tests for some usints

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.