π± How to Read Desired Capabilities from Excel and Set Them in DriverFactory β Java + Appium

In mobile test automation using Appium, itβs common to manage desired capabilities directly in the code or through .properties
or .json
files. But in dynamic enterprise frameworks, reading them from an external Excel file offers better scalability and flexibility.
In this blog, weβll walk through how to:
β
Read desired capabilities from an Excel sheet using Apache POI
β
Map them to a DesiredCapabilities
object
β
Use them in a centralized DriverFactory
class
π§ Tools and Libraries Used
Java
Appium
Apache POI (to handle Excel)
TestNG (optional)
Excel file (stored in
src/test/resources
)
ποΈ Excel File Structure
Save your Excel file as Capabilities.xlsx
with the following structure:
Capability | Value |
platformName | Android |
deviceName | emulator-5554 |
appPackage | com.example.app |
appActivity | com.example.Main |
automationName | UiAutomator2 |
π₯ Step 1: Add Apache POI Dependencies
In your pom.xml
:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
π Step 2: Excel Reader Utility
public class ExcelUtils {
public static Map<String, String> getCapabilitiesFromExcel(String filePath, String sheetName) {
Map<String, String> capabilities = new HashMap<>();
try (FileInputStream fis = new FileInputStream(filePath);
Workbook workbook = new XSSFWorkbook(fis)) {
Sheet sheet = workbook.getSheet(sheetName);
boolean firstRow = true;
for (Row row : sheet) {
// Skip the first row (header)
if(firstRow){
firstRow = false;
continue;
}
Cell keyCell = row.getCell(0);
Cell valueCell = row.getCell(1);
if (keyCell != null && valueCell != null) {
capabilities.put(keyCell.getStringCellValue(), valueCell.getStringCellValue());
}
}
} catch (IOException e) {
e.printStackTrace();
}
return capabilities;
}
}
π Step 3: DriverFactory Class
public class DriverFactory {
public static AppiumDriver driver;
public static void initializeDriver() {
String filePath = "src/test/resources/Capabilities.xlsx";
Map<String, String> capsMap = ExcelUtils.getCapabilitiesFromExcel(filePath, "Sheet1");
DesiredCapabilities caps = new DesiredCapabilities();
for (Map.Entry<String, String> entry : capsMap.entrySet()) {
caps.setCapability(entry.getKey(), entry.getValue());
}
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public static AppiumDriver getDriver() {
return driver;
}
}
π Conclusion
This approach centralizes capability management and allows QA teams or stakeholders to update device/test configurations without modifying code.
Pros:
Easy to update for non-developers
Supports multiple test environments
Scalable for CI/CD integration
π In upcoming posts, Iβll explore multi-device testing using data-driven capabilities and CI/CD integrations with Jenkins.
Subscribe to my newsletter
Read articles from Dinesh Y S directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Dinesh Y S
Dinesh Y S
Automation Engineer | Java + Selenium | Appium + Java | RestAssured | Sharing real-world automation tips