WinAppDriver Java Example

Profile picture for user arilio666

Today in this article, we will perform our first automation script using WinAppDriver and Java. We will open notepad application and type in current date in Notepad.

Follow Below Steps to Configure and Run WinAppDriver using Java:

Step 1: Add WinAppDriver Maven Dependency

Since WinAppDriver is bundled with io.appium. Add the IO Appium dependency to the pom.xml file in the maven project. You can check the latest one here

<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>8.0.0</version>
</dependency>

Also, there should be selenium dependency because that’s where we will be calling the WinAppDriver from the server default IP it gave, and automating Windows applications.To inspect UI elements, we are using inspect.exe, which is free.

public class WinAppDriver
{
    public static void main(String[] args) throws MalformedURLException
    {
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("app", "C:\\Windows\\System32\\notepad.exe");
        cap.setCapability("platformName","Windows");
        cap.setCapability("deviceName","WindowsPC");
      
        WindowsDriver wd = new WindowsDriver(new URL("http://127.0.0.1:4723/"), cap);
        LocalDate date = LocalDate.now();
        String datee = date.toString();
        
        wd.findElement(By.className("RichEditD2DPT")).sendKeys(datee);
    }
}
  • We have declared the desired capabilities from selenium first.
  • Then we set capabilities based on the argument app and then pass in the location to notepad.
  • Then we are announcing the WebDriver, which is the main thing we need.
  • We are then giving the running server IP of winappdriver.exe.
  • Then we converted the local date to a string using the java time package.
  • Using inspect.exe, we fetched the class name and sent keys to the variable containing the date in string format.

  • This is the inspect.exe app, and here we can see a list of locators for the UI elements.
  • Just pointing the cursor to the needed place fetches all the attributes.