• Post Reply Bookmark Topic Watch Topic
  • New Topic

Selenium+TestNG+JAVA Test fails on the TearDown method  RSS feed

Alister Ernest
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am getting deep into automation with Selenium+TestNG with the base test code in Java, but I am a newb in Java, and not very good at debugging issues in the code itself. Eclipse Intellisense helps a lot, but I am stuck here.

Below is my test class, and though the "Assertions" in the "try-catch" block pass, the test case fails in the @AfterClass method. I have included the Stack Trace below.
Weird thing is, with the TearDown class I have (exactly as below), the test passes if the Assertions fail. Its behaving in an awkwardly reverse manner.

I have deduced that the issue has to do something with the way I am appending the errors to the "verificationErrorsString" and in the way I have my final "IF" block setup in the TearDown class. But I am not able to put a finger on it and say "Eureka".
Please help a fellow tester out.


package com.test.example;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.*;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ExampleTest {

public WebDriver driver;
public StringBuffer verificationErrors = new StringBuffer();

public void setup(String browser) throws MalformedURLException, InterruptedException {
DesiredCapabilities capability=null;

capability= DesiredCapabilities.firefox();

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);


public void testExampleTest() throws Exception {

//driver login

try {
} catch (Error e) {

//driver logout


public void tearDown() throws Exception{


String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString); //This is the line that my Stack Trace refers to.


java.lang.AssertionError: java.lang.AssertionError: expected [true] but found [false] //This is where I have been pounding my head & racking my brains to no avail.
at org.testng.Assert.fail(Assert.java:89)
at com.cntntmgmt.content.ExampleTest.tearDown(ExampleTest.java:119)
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.TestRunner.afterRun(TestRunner.java:1021)
at org.testng.TestRunner.run(TestRunner.java:621)
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)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!