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.

Alex Kulinkovich
6272 gold badges8 silver badges18 bronze badges
asked Oct 10, 2015 at 12:43

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.

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

answered Oct 11, 2015 at 6:08
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

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
answered Sep 25, 2018 at 0:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.