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:
- the end-user needs to be able to click on a button on the web UI
- then the resultant export file is downloaded.
With import
uploads, the idea is:
- to have a local file relevant to the application
- then use the web UI to upload this file
- 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
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");
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
File Upload: use "Send Files with the Request" field of the HTTP Request sampler as per image below:
See Performance testing: Upload and Download Scenarios with Apache JMeter for more detailed instructions on how to conduct your use case with JMeter
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.
Explore related questions
See similar questions with these tags.