简体   繁体   English

如何在Windows 10上搭建winium Driver服务?

[英]How to build a winium Driver service on Windows 10?

I am using the following class code for launching calculator via WiniumDriver.我正在使用以下 class 代码通过 WiniumDriver 启动计算器。 Before creating an instance of WiniumDriver, I am starting a winium driver service.在创建 WiniumDriver 实例之前,我启动了一个 winium 驱动程序服务。

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.在运行测试 class 作为 TestNG 项目后,观察到以下异常。

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.我仔细检查了 calc.exe 和 Winium.Desktop.Driver.exe 的路径,但仍然无法启动 WiniumDriverService。 Is there any other way to start this service?还有其他方法可以启动此服务吗? Does winium support windows 10? winium是否支持windows 10?

The problem here is that, 'startDriver' is executing before setupEnvironment method and the variables service and options are not initialized. 这里的问题是, 'startDriver'setupEnvironment方法之前执行,并且变量serviceoptions未初始化。 Hence it is throwing null pointer exception. 因此它抛出空指针异常。

because the order of execution in testNG is given below. 因为testNG的执行顺序如下。

@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); } @AfterMethod public void stopDriver(){ driver.close(); } 
  2. change the annotations as given below. 更改下面给出的注释。

     @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(); } 
  3. change the annotations as given below. 更改下面给出的注释。 I believe, this one will be optimal solution. 我相信,这个将是最佳解决方案。

     @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(); } 
  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.但是,我不建议您将 Winium 用于 Windows 自动化,即使对于基本的计算器程序,它也无法正常工作,Winium 的最后一个版本是在 2016 年,我认为它现在不会定期维护。 Instead use WinAppDriver, which is far better tool and with good documentation.而是使用 WinAppDriver,它是更好的工具并且有很好的文档。 To start with refer this link首先参考这个链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows 7驱动程序服务启动 - Windows 7 driver service start gRPC C++ 如何在 Windows 10 上构建? - gRPC C++ build on Windows 10 how? 如何在Windows 10上通过自定义的inf文件安装WinUSB驱动程序? - How to install WinUSB driver through customized inf file on Windows 10? 如何在 Windows 10 驱动程序级别模拟键盘输入? - How to simulate keyboard input at driver level in Windows 10? 如何在Windows 10上为Sony Smartwatch 3设置ADB的USB驱动程序 - How to setup USB driver for ADB for Sony Smartwatch 3 on Windows 10 如何在 Windows 10 上远程启动服务 - How to tart service remotely on Windows 10 如何使用MinGW在Windows上构建Qt QOCI(Oracle数据库驱动程序)? - How to build Qt QOCI (Oracle Database driver) on Windows with MinGW? 如何在 windows 中安装和运行 Tor 服务? (Windows v.10) - How to install and run the Tor service in windows ? (windows v.10) 将Windows驱动程序连接到Userland服务 - Connecting Windows Driver to Userland Service 错误 MSB6006:“link.exe”以代码 1 退出运行 SDV(Static 驱动程序验证程序)时,Visual Studio 2019、SDK 10 build 19041、windows 10 build 19041 - error MSB6006: "link.exe" exited with code 1 When run SDV ( Static Driver Verifier) , Visual studio 2019 , SDK 10 build 19041, windows 10 build 19041
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM