FAILED CONFIGURATION:@AfterMethod tearDown即使驱动程序在退出之前检查null

时间:2015-12-24 15:21:02

标签: java selenium testng

我的代码如下......

@BeforeClass(alwaysRun = true)
public void setup() throws InterruptedException {
    driver = DriverFactory.getDriverInstance();
    softwarepage = new SoftwarePage(driver);
    loginpage = new LoginPage(driver);
    projectpage = new ProjectPage(driver);
}

@Test(description="Create Software",dataProviderClass=AddSoftwareProvider.class,dataProvider="testCasesAddSoftware")
public void createSoftware(AddSoftwareBean softwareBean) throws InterruptedException
{
    softwareName = "AutoSoftware"+DataGenerator.randomNumber();
    log.info("Create Software test case Started...");
    assertEquals(true, loginpage.gotoSignPage());
    assertEquals(true,loginpage.logintoPortal(PropertyMap.getInstance().getmySSISSGName(), PropertyMap.getInstance().getmySSISSGPassword(), "myToday"));
    //assertEquals(true,softwarepage.createSoftware(softwareName));
    //assertEquals(true,softwarepage.AddSoftwareDefault(softwareName, "Low"));
    assertEquals(true,softwarepage.AddSoftware(softwareBean));

}

我在下面的拆解方法中退出驱动程序,但是在检查驱动程序是否为null之前......甚至,上面的测试用例没有执行......

@AfterClass(alwaysRun = true)
public void tearDown() {
    if (driver != null) {
        assertEquals(true,loginpage.logout());
        driver.quit();
        }
}

在softwarePage中,代码就是这样......

public SoftwarePage(WebDriver driver) {
        this.driver = driver;
    }
@Override
protected WebDriver getDriver() {
    return driver;
}

请帮助我...

编辑:

完整堆栈在这里......断言是我写的注销方法......

FAILED CONFIGURATION: @AfterClass tearDown
java.lang.AssertionError: expected [false[ but found ]true]
    at org.testng.Assert.fail(Assert.java:94)
    at org.testng.Assert.failNotEquals(Assert.java:494)
    at org.testng.Assert.assertEquals(Assert.java:123)
    at org.testng.Assert.assertEquals(Assert.java:286)
    at org.testng.Assert.assertEquals(Assert.java:296)
    at com.cigital.myssi.automation.commons.Verification.assertEquals(Verification.java:33)
    at com.cigital.myssi.automation.tests.SoftwareTest.tearDown(SoftwareTest.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:225)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

编辑:在tearDown方法中没有断言,这就是我得到的......

===============================================
    Default test
    Tests run: 0, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 0, Failures: 0, Skips: 0

4 个答案:

答案 0 :(得分:0)

您可能不想在拆卸时声明值:

public void tearDown() {
    if (driver != null) {
        loginpage.logout()); //You might want to debug this though
        driver.quit();
        }
}

修改:我更倾向于将@BeforeTest@AfterTest用于您的测试&&整个测试套件的@BeforeSuite@AfterSuite代替@BeforeClass@AfterClass

答案 1 :(得分:0)

@AfterClass(alwaysRun = true)
public void tearDown() {
        if (driver != null) {
          try {
              assertEquals(true,loginpage.logout()); 
          } finally {
              driver.quit(); 
          }
        }    
 }

答案 2 :(得分:0)

从例外看来它在这里失败了:

at com.cigital.myssi.automation.commons.Verification.assertEquals(Verification.java:33)
at com.cigital.myssi.automation.tests.SoftwareTest.tearDown(SoftwareTest.java:69)

那个代码是什么?我认为它以某种方式覆盖assertEquals,并且可能不是以与布尔兼容的方式。 无论如何,你可以使用assertTrue,即:

assertTrue(loginpage.logout());

答案 3 :(得分:0)

谢谢大家的帮助,我在调试后发现了我的错误。该错误在我的CSVReader文件中显示,它从标题后的第二行读取数据。它容易出错。