I’m to get if the is or is not getting all 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 {
    System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
  }     
/**
 * @throws java.lang.Exception
 */
  //Adding product to the cart
  @Test(priority=0)
   public void AddToCart() throws InterruptedException  {
   try {
    driver.get("https://uat.sleepeve.com/");
    System.out.println("Title of page:  "+driver.getTitle());
    System.out.println("-----------------------------------------------------------------------------------");

    Actions action = new Actions(driver);
    WebElement Mattress =(WebElement)new WebDriverWait(driver,160).until(ExpectedConditions.elementToBeClickable
            (By.xpath("/html[1]/body[1]/header[1]/nav[1]/div[1]/a[2]/span[1]")));
    new Actions(driver).moveToElement(Mattress).click().perform();

    Thread.sleep(3000);

    WebElement submit2 =(WebElement)new WebDriverWait(driver,160).until(ExpectedConditions.elementToBeClickable
              (By.xpath("/html[1]/body[1]/div[8]/div[1]/div[2]/form[1]/div[2]/div[1]/button[1]")));
    new Actions(driver).moveToElement(submit2).click().perform();

    Thread.sleep(3000);

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


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

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

    private boolean isAlertPresent() {
      try {
        driver.switchTo().alert();
        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) {
          alert.accept();
        } else {
          alert.dismiss();
        }
        return alertText;
      } finally {
        acceptNextAlert = true;
      }

  }
}`



Source link https://sqa.stackexchange.com/questions/35474/unable-to-get-failed-status-if-script-is-stopped-or-element-is-not-clickable-get

LEAVE A REPLY

Please enter your comment!
Please enter your name here