2

In a series of applications my team is building we would like to test our import and export functionality which requires the respective upload and download to be automated.

The functionality is simple but tied to the UI; the end-user needs to be able to click on a button on the web UI and then the resultant export file is downloaded. With uploads, the idea is to have a local file relevant to the application and then use the web UI to upload said file and then test the import functionality.

Ideally I am looking for the ability to do this via Selenium IDE but as I understand it that is not possible.

Can this be done via Selenium WebDriver (via C#)?

If not, what is the best strategy to test this functionality? I'd like to test this as the end user and not simply pointing to some back-end URL to perform these tests.

Thank you for your time.

1
  1. The way to do it with Firefox browser

    • File download:

      FirefoxProfile profile = new FirefoxProfile();
      
      profile.SetPreference("browser.download.folderList",2);
      profile.SetPreference("browser.download.manager.showWhenStarting",false);
      profile.SetPreference("browser.download.dir", @"c:\path\to\downloads\folder");   
      profile.SetPreference("browser.helperApps.neverAsk.saveToDisk","MIME/TYPE");     
      FirefoxDriver driver = new FirefoxDriver(profile);
      
      driver.Get("http://path/of/your.file");
      

    change MIME/TYPE to be correct MIME type of the file(s) you're uploading, for instance: application/pdf for PDF files, application/vnd.openxmlformats-officedocument.wordprocessingml.template for MS Word 2007+ .docx files, etc.

    • File upload: it is quite enough to provide full path of the file you need to upload to SendKeys method

      IWebElement element = FindElement(By.Locator.of.your.file.type.input);
      element.SendKeys(@"c:\full\path\to\file\for.upload.txt");
      
  2. The other way to simulate files upload/download is using Apache JMeter tool, it is free, open source and designed for load testing so you will not only be able to test functionality, but also assess performance.

    • File Download: it is enough to add Save Responses to a file Post Processor to save response data to specified location

      Save Responses to file

    • File Upload: use "Send Files with the Request" field of the HTTP Request sampler as per image below:

      HTTP Request for file upload

    See Performance testing: Upload and Download Scenarios with Apache JMeter for more detailed instructions on how to conduct your use case with JMeter

0

It is possible to upload the files using selenium IDE. It can be done as mentioned below.

|Command|Target|Value|

|type|target_location_path|location_of_the_file_in_your_system|

Example:

|type|id=ConsignmentCustomerInvoiceFilename|C:\Users\abc\Desktop\img1.jpg|

You can identify the "target_location_path" by manually uploading the file and then finding the xpath of the uploaded file in the web app.

Please refer below screenshot to get a better understanding.

SeleniumIDE_uploadfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.