I'm Unable to get failed status if the script is stopped or element is not clickable getting all test pass how & what assert should I apply to get this resolved please help me package UsCheckoutUAT;

import static org.testng.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class EveMattressBaseUS{
  WebDriver driver;
  public static String result;
  StringBuffer verificationErrors = new StringBuffer();

   * @throws java.lang.Exception
@BeforeClass(alwaysRun = true)
  public void setUp() throws Exception {
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
 * @throws java.lang.Exception
  //Adding product to the cart
   public void AddToCart() throws InterruptedException  {
   try {
    System.out.println("Title of page:  "+driver.getTitle());

    Actions action = new Actions(driver);
    WebElement Mattress =(WebElement)new WebDriverWait(driver,160).until(ExpectedConditions.elementToBeClickable
    new Actions(driver).moveToElement(Mattress).click().perform();


    WebElement submit2 =(WebElement)new WebDriverWait(driver,160).until(ExpectedConditions.elementToBeClickable
    new Actions(driver).moveToElement(submit2).click().perform();


    }   catch (Exception E) {
         System.out.println("Exception in AddToCart: "+ E);

  @AfterClass(alwaysRun = true)
   public void tearDown() throws Exception {
      String verificationErrorString = verificationErrors.toString();
      if (!"".equals(verificationErrorString)) {

    private boolean isElementPresent(By by) {
      try {
        return true;
      } catch (NoSuchElementException e) {
        return false;

    private boolean isAlertPresent() {
      try {
        return true;
      } catch (NoAlertPresentException e) {
        return false;

    private String closeAlertAndGetItsText() {
      boolean acceptNextAlert = false;
    try {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        if (acceptNextAlert) {
        } else {
        return alertText;
      } finally {
        acceptNextAlert = true;

  • How and what are you currently asserting? – Alexey R. Sep 4 '18 at 7:42
  • Currently not asserting – Mahima soni Sep 4 '18 at 8:15
  • You have to give us some representative code. So that we are aware of what you have and what is missing. – Alexey R. Sep 4 '18 at 8:20
  • Currently not asserting recently tried some asserting but not getting the required solution, I want to do smoke testing in which I only want to navigate pages and clicks to button and links, i wrote simple script for this without using any assertion can you plz suggest me what assertion i have to use or any other required solution for the same – Mahima soni Sep 4 '18 at 8:21
  • Please refer code @AlexeyR. – Mahima soni Sep 4 '18 at 8:42

You're not able to get your tests failed because you catch the exceptions which are thrown within your tests.

enter image description here

This leads to the situation when all the exceptions which are thrown in your test code are caught and TestNG has just no idea about something wrong happened there.

You should:

  • either not wrap your test code in try-catch
  • or throw new exception in catch block.
  • or catch only exceptions which are irrelevant to your test result (Currently you catch all the possible exceptions which might occur)
| improve this answer | |
  • 1
    Thanks @Alexey it's working now thanx a lot for the quick reply – Mahima soni Sep 4 '18 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.