The desktop driver (VerisoftDesktopDriver) lets you automate Windows desktop applications using Appium with the Windows Desktop Driver. This guide covers everything needed to write a desktop test from scratch.
Although there are different ways of declaring and using the driver, this is the recommended way.
Prerequisites
An Appium server with the appium-wincore-driver driver installed must be running. Windows only — macOS is not supported.
Install the driver:
appium driver install --source=npm appium-wincore-driver
Start Appium:
appium
1 - Declare Capabilities
For desktop tests, capabilities are declared as Spring beans in a configuration class.
Create a class annotated with @Configuration:
@Configuration
public class DesktopCapabilitiesConfig {
@Bean("windows-notepad")
public DesiredCapabilities windowsNotepad() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "Windows");
caps.setCapability("appium:automationName", "Wincore");
caps.setCapability("appium:app", "C:/Windows/System32/notepad.exe");
caps.setCapability("ms:waitForAppLaunch", 5);
return caps;
}
}
Key capabilities explained
- platformName: always "Windows"
- appium:automationName: always "Wincore"
- appium:app: full path to the .exe, or the app package name for Microsoft Store apps
- ms:waitForAppLaunch : seconds to wait for the app to launch
The string in @Bean("windows-notepad") is the bean name. You will reference this name later in the test.
2 - Wire the capabilities config to your test class
Use Spring's @ContextConfiguration to point at your config class. Also register SpringExtension so JUnit 5 knows to use Spring:
@ContextConfiguration(classes = DesktopCapabilitiesConfig.class)
@ExtendWith(SpringExtension.class)
class MyDesktopTest { ... }
This makes your @Bean definitions available to the framework so it knows how to build the driver.
3 - Use DriverInjectionExtension
DriverInjectionExtension explanation
DriverInjectionExtension is a JUnit 5 extension that automatically creates the driver before each test and passes it as a parameter. You never call "new VerisoftDesktopDriver(...)" in your test code.
Add it to @ExtendWith alongside SpringExtension:
@ExtendWith({SpringExtension.class, DriverInjectionExtension.class})
Then declare the driver as a parameter in your test method, and annotate it to tell the extension which bean to use and which Appium server to connect to:
@Test
void myTest(
@DriverCapabilities("windows-notepad")
@DriverUrl("http://127.0.0.1:4723/")
VerisoftDesktopDriver driver) {
// your test here
}
- @DriverCapabilities("windows-notepad"): references the @Bean name from your config class
- @DriverUrl("http://127.0.0.1:4723/"): the Appium server address
- VerisoftDesktopDriver: the driver type for desktop
Test code example
@ExtendWith({SpringExtension.class, DriverInjectionExtension.class})
@ContextConfiguration(classes = DesktopCapabilitiesConfig.class)
class CalculatorDesktopTest {
@Test
void onePlusTwoEqualsThree(
@DriverCapabilities("windows-calculator")
@DriverUrl("http://127.0.0.1:4723/")
VerisoftDesktopDriver driver) {
driver.findElement(AppiumBy.accessibilityId("num1Button")).click();
driver.findElement(AppiumBy.accessibilityId("plusButton")).click();
driver.findElement(AppiumBy.accessibilityId("num2Button")).click();
driver.findElement(AppiumBy.accessibilityId("equalButton")).click();
String result = driver
.findElement(AppiumBy.accessibilityId("CalculatorResults"))
.getText();
Asserts.assertTrue(result.contains("3"), "Expected result to contain '3' but was: " + result);
}
}
There are other example tests in the verisoft framework example repo