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

How to build a winium Driver service on Windows 10?


The problem here is that, 'startDriver' is executing before setupEnvironment method and the variables service and options are not initialized. Hence it is throwing null pointer exception.

because the order of execution in testNG is given below.

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

There are three solutions.

  1. change the annotation for the following methods as given below. so that, the start driver will run after the setup environment method.

     @BeforeMethod public void startDriver(){    driver = new WiniumDriver(service,options); }@AfterMethodpublic void stopDriver(){   driver.close();}
  2. change the annotations as given below.

    @BeforeTestpublic 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();    }}@BeforeClasspublic void startDriver(){    driver = new WiniumDriver(service,options);}@AfterClasspublic void stopDriver(){    driver.close();}@AfterTestpublic void tearDown(){    service.stop();}
  3. change the annotations as given below. I believe, this one will be optimal solution.

    @BeforeTestpublic 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();    }}@BeforeMethodpublic void startDriver(){    driver = new WiniumDriver(service,options);}@AfterMethodpublic void stopDriver(){    driver.close();}@AfterTestpublic void tearDown(){    service.stop();}