【问题标题】:Exception while taking screenshotSession ID is null. Using WebDriver after calling quit()?(TestNG)截屏时出现异常会话 ID 为空。调用 quit() 后使用 WebDriver?(TestNG)
【发布时间】:2018-07-24 23:44:02
【问题描述】:

我得到的会话 ID 为空。调用 quit() 后使用 WebDriver?异常当任何测试用例的运行模式设置为 NO。我正在使用 TestNg 框架。

如果所有测试用例的 Runmode 都是 Yes 那么它工作正常。

我为套件创建一个 Java 类,并为单个测试用例创建多个内部类。

下面是我的代码。

    package com.smoke;

    import org.testng.SkipException;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;
    import com.util.TestUtil;

    @Listeners(com.listener.ListenerTestNG.class)

    public class Testxls extends TestSuiteBase {    
        @BeforeMethod
        public void checkTestSkip() {    
        APP_LOGS.debug("Checking Runmode of Testxls Test Case");    
      if(!TestUtil.isTestCaseRunnable(smoke,this.getClass().getSimpleName())) {
      APP_LOGS.debug("Skipping Test Case" + this.getClass().getSimpleName() + " as runmode set to NO");
      throw new  SkipException("Skipping Test Case as runmode is set to NO");
  }
        }
        @BeforeTest
        public void testData() {
            try {
                objData=smoke.getTestCaseData("DataSheet", "Testxls");
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println(objData);

        }
        @Test()
        public void f() throws Exception {
            openBrowser();//Calling method to open browser
            Thread.sleep(5000);
            tearDown(); //calling method to quit browser

        }
    }

@Listeners(com.listener.ListenerTestNG.class)
class Testxls1 extends TestSuiteBase {

    @BeforeMethod
    void checkTestSkip()    {
        System.out.println(this.getClass().getSimpleName());
        APP_LOGS.debug("Checking Runmode of Testxls1 Test Case");
        if(!TestUtil.isTestCaseRunnable(smoke, this.getClass().getSimpleName())) {
            APP_LOGS.debug("Skipping Test Case" + this.getClass().getSimpleName() + " as runmode set to NO");
            throw new  SkipException("Skipping Test Case as runmode is set to NO");
        }
    }
    @BeforeTest
    void testData() {
        try {
            objData=suite_smoke.getTestCaseData("DataSheet", "Testxls1");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(objData);

    }
    @Test()
    void f() throws Exception {
        openBrowser();


    }
}

请找到测试用例和数据文件截图。

感谢任何帮助

谢谢 维平

【问题讨论】:

  • 代码不可读。请格式化。

标签: selenium-webdriver testng extentreports selenium-extent-report


【解决方案1】:

TestSuiteBase 中实现了什么?您很可能在所有测试中都在同一个驱动程序实例中使用,因此在一个测试中退出时出现异常并仍在另一个测试中使用。检查您是否使用静态网络驱动程序。

更好的方法是根据浏览器的要求创建返回 webdriver 实例的方法,并在测试开始时获取它,将其传递给该测试中的所有方法并最终退出。

【讨论】:

  • 嗨 Murali,在 TestSuiteBase 中,我们正在检查 suiteMode 是的,否 TestSuiteBase 还扩展了 Our Base 类,该类具有所有先决条件加载 xls、初始化方法日志打开浏览器登录等。对于 webdrive,我们创建了全局静态引用变量。调试后,我找到了发生此错误的实际原因。原因是 TestNg skipException 返回失败状态而不是 Skip,如果测试用例失败,我们截取了屏幕截图,但实例已经关闭 - 为什么它通过异常。来自 TestNg SkipException 的实际问题。
猜你喜欢
  • 1970-01-01
  • 2017-08-06
  • 2022-01-27
  • 2020-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
相关资源
最近更新 更多