How to Upload Files to a Remote Web Server Using Selenium in TestGrid
We’re covering WebDriver’s native solution to a very common issue when doing distributed cross-browser testing: uploading files to remote servers. One of the most common online activities people undertake is uploading files. Selenium is one of the best tools for automation testing websites because it allows testers to automate valuable functions. This step-by-step guide will simplify how to upload files in Selenium using relevant code snippets and use them in our TestGrid Scriptless tool.
Step 1: How to Upload a File Using Selenium Webdriver Using TestGrid Tools
While there are multiple approaches to uploading a file in Selenium, this article will describe the action using the SendKeys method. The sample snapshot below depicts the page to which the user must upload a sample file using the Choose File or File Uploading button.
The element for uploading files on the web page should be in the CSS selector and ID form once you open any web URL. It must be used as a send key to give the file path of the TestGrid Cloud Server.
Refer to the below screen for instructions on how to grab this element.
Letβs see how to use the file uploading test scenario in our TestGrid Tools using a scriptless
Step 2: Open the TestCase writer screen and use Custom Script to add some steps for uploading the file button element.
Now you must create a two-liner, small custom script that will upload any file to a remote web server.
Before you can check whether any sample files on a specific TestGrid cloud server are present or not. The path to check is shown below.
> https://{your_server}.testgrid.io/assets/upload_test_file/
This is the path that the script uses.
/home/seluser/Downloads/{A.png and all other files}
Note: Please ensure that the above file path is used for all sample files hosted in TestGrid Cloud Server. If not, please contact our support team.
This is a Java working script created for the File Upload scenario in Web Selenium.
Ex:
// Locate the file input element using a known locator (e.g. by ID, cssSelector only) WebElement fileInput = driver.findElement(By.cssSelector("input[type='file']")); // System file upload, with using remote file path fileInput.sendKeys("/home/seluser/Downloads/A.png");
The custom script Manually One above should be added to the TestCase writer steps.
Step3: In our TestGrid Test Case Writer steps, use the above custom script.
Step4: Now run the test case file and check the logs to see if the file was successfully uploaded.
happy Testing π !