3

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.

Export functionality is simple, but tied to the UI:

  1. the end-user needs to be able to click on a button on the web UI
  2. then the resultant export file is downloaded.

With import uploads, the idea is:

  1. to have a local file relevant to the application
  2. then use the web UI to upload this file
  3. then test the import functionality.

Ideally I'm 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.

2 Answers 2

2
  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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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