'How to build a winium Driver service on Windows 10?

I am using the following class code for launching calculator via WiniumDriver. Before creating an instance of WiniumDriver, I am starting a winium driver service.

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.openqa.selenium.winium.WiniumDriverService;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CalculatorTest {

    static WiniumDriver driver = null;
    static WiniumDriverService service = null;
    static DesktopOptions options = null;

    @BeforeClass
    public static void setupEnvironment(){
        options = new DesktopOptions(); //Instantiate Winium Desktop Options
        options.setApplicationPath("C:\\Windows\\System32\\calc.exe");
        File driverPath = new File("C:\\Winium\\Winium.Desktop.Driver.exe");
        System.setProperty("webdriver.winium.desktop.driver","C:\\Winium\\Winium.Desktop.Driver.exe");
        service = new WiniumDriverService.Builder().usingDriverExecutable(driverPath).usingPort(9999).withVerbose(true)
                .withSilent(false).buildDesktopService();
        try {
            service.start();
        } catch (IOException e) {
            System.out.println("Exception while starting WINIUM service");
            e.printStackTrace();
        }
    }

    @BeforeTest
    public void startDriver(){
        driver = new WiniumDriver(service,options);
    }

    @AfterTest
    public void stopDriver(){
        driver.close();
    }

    @AfterClass
    public void tearDown(){
        service.stop();
    }

After running the test class as TestNG item, following exception is observed.

FAILED CONFIGURATION: @BeforeTest startDriver
java.lang.NullPointerException
    at org.openqa.selenium.winium.WiniumDriverCommandExecutor.<init>(WiniumDriverCommandExecutor.java:59)
    at org.openqa.selenium.winium.WiniumDriver.<init>(WiniumDriver.java:75)
    at com.bravura.automation.CalculatorTest.startDriver(CalculatorTest.java:41)

I double checked the path to calc.exe and Winium.Desktop.Driver.exe, still I am not able to launch the WiniumDriverService. Is there any other way to start this service? Does winium support windows 10?



Solution 1:[1]

  1. Here is the correct way of using it
public class SimpleTest
{
    DesktopOptions options;
    WiniumDriverService service;
    WiniumDriver driver;

    @BeforeTest
    public void bt()
    {
        //Instantiate Winium Desktop Options
        options = new DesktopOptions();
        
        // Path of application you want to run and test
        options.setApplicationPath("C:\\Windows\\System32\\calc.exe");
        
        //Path for Winium Desktop Driver
        File driverPath = new File(System.getProperty("user.dir")+File.separator+"drivers"+File.separator+"Winium.Desktop.Driver.exe");
        
        //Port is 9999, you can change it
        service = new WiniumDriverService.Builder().usingDriverExecutable(driverPath).usingPort(9999).withVerbose(true).withSilent(false).buildDesktopService();
        
        try
        {
             service.start();
        }
        catch (IOException e)
        {
            System.out.println("Exception while starting WINIUM service");
            e.printStackTrace();
        }
        driver = new WiniumDriver(service,options);
    }

    @AfterTest
    public void at()
    {
        service.stop();
    }
}
  1. If you need other configuration you can refer this link. However, I would not recommend that you use Winium for Windows automation even for basic Calculator program it will not work properly, last release of Winium was in 2016, I don't think it is regularly maintained now. Instead use WinAppDriver, which is far better tool and with good documentation. To start with refer this link

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1