How to build a winium driver service in Windows 10?

I use the following class code to run the calculator through WiniumDriver. Before creating an instance of WiniumDriver, I start the 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, the following exception is observed as a TestNG element.

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, but I can not start WiniumDriverService. Is there any other way to start this service? Does winium support windows 10?

+6
source share
1 answer

, 'startDriver' setupEnvironment, service options . , .

testNG .

@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite

.

  • , . .

     @BeforeMethod
     public void startDriver(){
        driver = new WiniumDriver(service,options);
     }
    
    @AfterMethod
    public void stopDriver(){
       driver.close();
    }
    
  • , .

    @BeforeTest
    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();
        }
    }
    
    @BeforeClass
    public void startDriver(){
        driver = new WiniumDriver(service,options);
    }
    
    @AfterClass
    public void stopDriver(){
        driver.close();
    }
    
    @AfterTest
    public void tearDown(){
        service.stop();
    }
    
  • , . , .

    @BeforeTest
    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();
        }
    }
    
    @BeforeMethod
    public void startDriver(){
        driver = new WiniumDriver(service,options);
    }
    
    @AfterMethod
    public void stopDriver(){
        driver.close();
    }
    
    @AfterTest
    public void tearDown(){
        service.stop();
    }
    
+6

All Articles