如何在Windows 10上构建winium驱动服务?

2024-01-07

我正在使用以下类代码通过 WiniumDriver 启动计算器。在创建 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();
    }

作为 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)

我仔细检查了 calc.exe 和 Winium.Desktop.Driver.exe 的路径,但仍然无法启动 WiniumDriverService。还有其他方法可以启动这个服务吗? winium支持windows 10吗?


这里的问题是,'startDriver'之前正在执行setupEnvironment方法和变量service and options没有初始化。因此它抛出空指针异常。

因为执行顺序在testNG下面给出。

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

共有三种解决方案。

  1. 更改以下方法的注释,如下所示。这样,启动驱动程序将在设置环境方法之后运行。

     @BeforeMethod
     public void startDriver(){
        driver = new WiniumDriver(service,options);
     }
    
    @AfterMethod
    public void stopDriver(){
       driver.close();
    }
    
  2. 更改注释,如下所示。

    @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. 更改注释,如下所示。我相信,这将是最佳解决方案。

    @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();
    }
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在Windows 10上构建winium驱动服务? 的相关文章

随机推荐

  • 随着 TestFlight 被 iTunes Connect 取代,企业应用 Beta 测试将会发生什么?

    我在 中找不到任何有关企业 Beta 测试的信息iTunes Connect 开发人员指南 https developer apple com library ios documentation LanguagesUtilities Con
  • 扩展jQuery的ajax功能

    我想扩展 ajax 函数 以便每当调用它时 页面上就会出现一个图像 指示正在加载内容 我可以使用本页讨论的预过滤器http api jquery com extending ajax http api jquery com extendin
  • 在 WinDbg 中定义自定义错误检查代码

    有没有一种方法可以定义自定义代码 带有消息 描述等 以便当我在 Windows 的内核模式驱动程序中调用KeBugCheckEx要发出自定义 BugCheck 代码 WinDbg 会显示该自定义 BugCheck 代码附带的关联消息吗 有关
  • 使用虚拟目录将 ASP.NET MVC 部署到 IIS 5/6

    我有一个 asp net MVC 应用程序 我想使用虚拟目录将其部署到 IIS 5 和 或 6 我已经执行了通配符路由 但相对路径有问题 假设我创建了一个名为 myApp 的虚拟目录 部署后我可以去http localhost myApp
  • pandas DataFrame旋转问题

    我有一些格式有点奇怪的雷达数据 我不知道如何使用 pandas 库正确地旋转它 My data speed time loc A 63 0000 B 61 0000 C 63 0000 D 65 0000 A 73 0005 B 71 00
  • FreeT 生成的解释器 monad 转换器的 MonadFix 实例?

    我有一个由以下命令生成的标准解释器 monad 转换器的简化版本FreeT data InteractiveF p r a Interact p r gt a type Interactive p r FreeT InteractiveF
  • 找出给定函数中调用了哪些函数[重复]

    这个问题在这里已经有答案了 可能的重复 在 R 中生成调用图 https stackoverflow com questions 4795982 generating a call graph in r 我想系统地分析给定的函数 以找出该函
  • 雄猫并没有停止。我该如何调试这个?

    我有一个Tomcat 7在我启动的 Linux 中运行 CATALINA HOME bin startup sh并通过关闭 CATALINA HOME bin shutdown sh from etc init d 除了 1 个问题外 一切
  • Qt 中的阿拉伯语与 QString

    我想向我的 Qt 应用程序添加阿拉伯语标题 但没有成功 这是我的代码 include mainwindow h include
  • Java 1.6 中的枚举类主体功能

    enum CoffeeSize BIG 8 HUGE 10 OVERWHELMING 16 public String getLidCode return A private int ounces public int getOunces
  • 使用 stackdriver CLI 查找时间戳之间的日志

    我需要使用 stackdriver CLI 查找两个时间戳之间的日志 我使用了下面的命令 gcloud beta logging read timestamp gt 2017 02 19T00 00 00Z AND timestamp lt
  • 中止多文件上传 AJAX 请求

    我试图用进度条中止多个文件上传 显示进程的状态 我想要实现的是在单击中止按钮时完全中止多个文件上传 停止进度条并清除在最初触发的多个文件上传过程中可能已上传的每个文件 下面是我的代码 var AJAX ajax xhr function v
  • 如何让 python 脚本安全退出?

    这是我有一个必须输入的密码的情况 如果输入错误 脚本将无法继续并自行退出 但我怎样才能告诉脚本安全地退出呢 I tried sys exit 但这会产生回溯错误 并且看起来不是一个非常干净的退出方法 实际上 sys exit 只会抛出一个S
  • AWS lambda无服务器网站会话维护

    我使用 Node js 作为后端开发了一个网站 最近我正在尝试将其变成无服务器并部署到 lambda 我将重写大部分代码 但只是还没弄清楚如何在用户登录后维护会话 我使用的是 express session 模块 会话数据全部记录在数据库中
  • 启动ejb bean不工作

    我正在尝试使用启动 ejb 在启动时做一些事情 但我的豆子从来没有被调用过 这是我的豆子 import javax annotation PostConstruct import javax ejb Startup import javax
  • Django cookies 在电子邮件地址周围放置双引号

    在我的登录脚本中 它为用户登录其电子邮件地址和密码创建一个 cookie 我遇到的问题是 当设置电子邮件地址时 它将整个电子邮件地址放在双引号之间 我怎样才能让它不呢 if request method POST post request
  • iOS9 self.canDisplayBannerAds = true 不显示任何广告 [关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 非常简单的iAd代码 import UIKit import iAd class ViewController UIViewCon
  • Linux 上的 SAFEARRAY

    我在 Linux 上使用一个专有库 它使用SAFEARRAY输入回调函数 HRESULT Write SAFEARRAY Data SAFEARRAY在头文件中定义为typedef void SAFEARRAY 我必须定义一个回调函数来获取
  • ASP.NET MVC Html.Editor 将模型传递给编辑器模板

    我有一个名为 Address cshtml 的编辑器模板 其模型定义为 model Acme Models Address 在视图中 我想调用编辑器模板并传递相同类型的局部变量 并定义它将用于变量的名称 我尝试了很多方法 包括 Html E
  • 如何在Windows 10上构建winium驱动服务?

    我正在使用以下类代码通过 WiniumDriver 启动计算器 在创建 WiniumDriver 实例之前 我将启动一个 winium 驱动程序服务 import java io File import java io IOExceptio