【问题标题】:Allure listener throwing exception倾城监听器抛出异常
【发布时间】:2021-11-03 10:29:27
【问题描述】:

运行我的代码时遇到异常,它达到了诱惑侦听器类:

java.lang.ClassCastException: class test.loginTest cannot be cast to class base.DriverContext 

我怀疑我没有按照我应该的方式在框架中流动驱动程序对象,但没有得到任何解决方案。

如果我的诱惑成功方法如下:

 public void onTestSuccess(ITestResult iTestResult) {
        System.out.println("Method" + GetTestMethodName(iTestResult) + " Pass");
        Object testClass = iTestResult.getInstance();
        WebDriver driver = ((DriverContext) testClass).Driver;
        if (driver instanceof WebDriver) {
            System.out.println("Screen captured for test case : " + GetTestMethodName(iTestResult) + ":Pass");
            saveScreenshotPNG(driver);

        }

    }

【问题讨论】:

    标签: selenium-webdriver maven-2 allure


    【解决方案1】:

    检查 LoginTest 是否扩展了 DriverContext 如果是这种情况,那么你不能使用派生类的引用来存储超类的对象。

    在您的情况下,您可以直接从测试本身获取驱动程序实例,而不是通过超类调用它。

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多