πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Scenarios
Scenario 44 of 100
File Upload/Download
Advanced

Automating File Upload in Remote Jenkins Execution

☁️Scenario Overview

Automating File Upload in Remote Jenkins Execution

Key Takeaways & Cheat Sheet

  • βœ“Recognize that remote execution grids run on separate network nodes
  • βœ“Configure LocalFileDetector on the RemoteWebDriver instance
  • βœ“Acknowledge LocalFileDetector automatically zips and uploads files to the grid
  • βœ“Use standard sendKeys() with the local file path as usual

Short Direct Answer

When tests run on a remote server (like Selenium Grid, SauceLabs, or browser containers in Jenkins), standard file paths don't work because the file is on the Jenkins agent, not the remote browser node. To resolve this, configure a `LocalFileDetector` on your `RemoteWebDriver` object. Selenium will automatically compress the file, upload it to the remote browser node, and execute the test seamlessly.

⚠️ Senior Warning (Red Flag)

Do not attempt to upload files using standard sendKeys on a remote Selenium Grid without setting a LocalFileDetector. The remote node will look for the file on its own filesystem and throw a WebDriverException.

πŸ’‘ STAR Deep Dive Explanation & Pro Tip

LocalFileDetector acts as an automated bridge that transfers file assets to remote browsers before execution, ensuring reliable cross-machine automation.

SeleniumAutomation.java
Selenium 4 + Java
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.LocalFileDetector;

// βœ… Check if driver is executing remotely
if (driver instanceof RemoteWebDriver) {
    // Configure Remote WebDriver to auto-detect and upload local files to remote grid node
    ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
}

// βœ… Perform standard upload; file is dynamically transferred to grid node!
WebElement uploadInput = driver.findElement(By.cssSelector("input[type='file']"));
uploadInput.sendKeys("C:\jenkins-workspace\data-sheet.xlsx");