简体   繁体   中英

Failed tests are showing as pass in testng output

I have two different testng tests 1. Login 2. Date Picker . what i am doing here, in date picker i had given a past date, so i get a alert message as "Date cannot be past. In testng output i am getting the alert message, but why my result is showing as passedike 1.Book travel- passed 2. Date picker- passed. I want the date picker to be showed as failed in testng output. Some one please reframe this code. I am new to testng. TIA

Please reframe this code.I have two different testng tests 1. Login 2. Date Picker . what i am doing here, in date picker i had given a past date, so i get a alert message as "Date cannot be past. In testng output i am getting the alert message, but why my result is showing as passedike 1.Book travel- passed 2. Date picker- passed. I want the date picker to be show as failed in testng output. Some one please reframe this code. I am new to testng. TIA

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class travelapp {
    WebDriver driver;

    @BeforeClass
    public void setUp() {
        System.setProperty("webdriver.chrome.driver","D://Siva//Selenium//chromedriver//chromedriver.exe");
        driver = new ChromeDriver();        
    }

    @Test
    public void Logintravel() {
        driver.get("https://testsite.com");
        driver.findElement(By.xpath(".//*[@id='txtEmployeeId']")).sendKeys("abcd");    driver.findElement(By.xpath(".//*[@id='btnSubmit']")).click();
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.findElement(By.xpath(".//[@id='ctl00_mnuTraveln0']/table/tbody/tr/td/a")).click();
        WebElement radioBtn = driver.findElement(By.xpath(".//*[@id='ctl00_cphMain_TravelRequest1_chkCostCenter']"));
        radioBtn.click();
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);      
   }

   @Test(priority=1)
   public void Datepicker() {                     
       //Travel from date
       driver.findElement(By.xpath(".//[@id='ctl00_cphMain_TravelRequest1_txtTrStartDate']")).click();
       driver.findElement(By.xpath(".//[@id='ctl00_cphMain_TravelRequest1_txtTrStartDate_CalendarExtender_day_0_1']")).click();
       Alert alert = driver.switchTo().alert();
       String alertMessage = driver.switchTo().alert().getText();
       System.out.println(alertMessage);
  }
 }                                                                                           

Please reframe this code.. I have two different testng tests 1. Login 2. Date Picker . what i am doing here, in date picker i had given a past date, so i get a alert message as "Date cannot be past. In testng output i am getting the alert message, but why my result is showing as passedike 1.Book travel- passed 2. Date picker- passed. I want the date picker to be show as failed in testng output. Some one please reframe this code. I am new to testng.

TestNG doesn't care what is the content of the alert, if there weren't any exceptions the test will pass.

You need to assert it with other message which shows success. For example

String alertMessage = driver.switchTo().alert().getText();
Assert.assertEquals(alertMessage, "Data passed successfully"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM