一些testng报告如何显示同一测试的通过和失败

时间:2018-01-11 09:38:27

标签: java selenium-webdriver testng

我认为问题在于我的断言。

代码:

package com.test.selenium.testscripts;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.test.selenium.pageobjects.CertificateValidationPageObject;
import com.test.selenium.utils.BasicUtils;

public class CertificateValidationTestScript extends BasicUtils {
    private static WebDriver driver;
    private static WebElement element = null;
    private static String browserName = null;
    private XSSFSheet sheet;

    //@SuppressWarnings("deprecation")
    @Parameters({"url","browser"})
    @BeforeMethod
    public void setUp(String url, String browser) throws IOException {
        System.out.println("Before starting the tests");
        browserName = browser;

        if(browser.equalsIgnoreCase("chrome")) {
              System.setProperty("webdriver.chrome.driver", "C:\\chromeDriver\\chromedriver.exe");
              driver = new ChromeDriver();
          }

          if(browser.equalsIgnoreCase("firefox")) {
              System.setProperty("webdriver.gecko.driver","C:\\firefoxDriver\\gecko_0160\\geckodriver.exe");
              driver = new FirefoxDriver();
          }
         //sheet = getExcelSheet("Sheet1");
          driver.get(url);
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     }


    @Test(dataProvider="getTableData")
    public void fillCertificateValidationWebPage(String certNumber, String certNumberExtn, String month, String year, String speciesName) throws Throwable {
        try {



             CertificateValidationPageObject.setCertificateNumberTextbox(driver,certNumber);

             CertificateValidationPageObject.selectCertificateNumberExtension_Pulldown(driver,certNumberExtn);
             CertificateValidationPageObject.select_Certificate_Month(driver,month);
             CertificateValidationPageObject.select_Certificate_Year(driver,year);
             CertificateValidationPageObject.select_Species(driver,speciesName);
             Thread.sleep(2000);

             CertificateValidationPageObject.select_Submit_Button(driver);

             String result = null;
             WebElement element = driver.findElement(By.xpath("//*[@id=\"center\"]/form/div/table/tbody/tr[1]/td"));
             if(element != null)
                 result = element.getText();

             Assert.assertTrue(result.equals("RED") || result.equals("BLUE"));

        } catch (Throwable e) {
            if(browserName.equals("chrome")) {
                BasicUtils.takeSnapShot_robotClass(driver, "C:\\Selenium\\screenshots", certNumber);
            }
            throw e;
        }
     }


     @AfterMethod
      public void afterTest() {
         System.out.println("After all the tests");
         try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {

            e.printStackTrace();
        }
         driver.quit();
      }

}

当Assert条件同时通过时报告似乎很好但是当它失败时报告有问题。

enter image description here

0 个答案:

没有答案