Not able to report error in Test NG Report | Selenium Forum
M
Posted on 20/12/2015
Hello everyone,

I am working on module 20, here i am not able to report error in TestNg.

here i am verifying page title

Actual title: Welcome to VirtueMart 3 Sample store

Expected Title: Welcome to VirtueMart 3 Sample store1212

While title mismatch below code reports failures in Excel file but its getting pass in TestNg Report


===========================================================================================
Below code for CheckProductDisplay.java


package com.qtpselenium.suite.shop;


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.qtpselenium.util.TestUtil;

@Test
public class CheckProductDisplay extends TestSuiteBase{
String runmodes[]=null;
static int count=-1;
static boolean Fail=false;
static boolean Skip=false;
static boolean Pass=false;
static boolean isTestPass=true;
//runmode of test case in suite
@BeforeTest
public void checkTestcaseSkipped() throws Exception {
//Initialize();
APP_LOGS.debug("Checking runmode of Chack product display");
//if(!TestUtil.isTestcaseRunnable(suiteAxls, "TestCase_A1")){
if(!TestUtil.isTestcaseRunnable(suite_shop_xls, this.getClass().getSimpleName())){
APP_LOGS.debug(this.getClass().getSimpleName()+"skipped as runmode set to No");//logs
throw new SkipException("Chack product display skipped as runmode set to No");//reports
}
//load runmode of test data
// runmodes=TestUtil.getDatasetRunmode(suite_shop_xls, this.getClass().getSimpleName());

}

public void checkproduct(){

APP_LOGS.debug("Checking runmode of TestData--"+this.getClass().getSimpleName());
count++;
// if(!runmodes[count].equalsIgnoreCase("Y")){
// Skip=true;
// throw new SkipException("Runmode set to No for TestData Set "+(count+1));
// }

System.out.println("testcaseA1");
//selenium code

openBrowser();
driver.get("http://demo.virtuemart.net/");

//verify page title

if(!compareTitle("Welcome to VirtueMart 3 Sample store1212")) {
Fail=true;

//APP_LOGS.debug("Title do not match");
return;//conditional

}

WebElement featuredView = driver.findElement(By.className("featured-view"));
List<WebElement> Product_details = featuredView.findElements(By.className("product-details"));
System.out.println("Total products are : "+Product_details.size());


closeBrowser();
}

@AfterMethod
public void reportDatasetresult(){
if(Skip){
TestUtil.reportDataSetResult(suite_shop_xls, this.getClass().getSimpleName(), count+2, "Skip");
}else if(Fail){
isTestPass=false;
TestUtil.reportDataSetResult(suite_shop_xls, this.getClass().getSimpleName(), count+2, "Fail");
}else{
TestUtil.reportDataSetResult(suite_shop_xls, this.getClass().getSimpleName(), count+2, "Pass");
}
Skip=false;
Fail=false;


}


@AfterTest
public void reportTestcaseResult(){
if(isTestPass)
TestUtil.reportDataSetResult(suite_shop_xls, "Test Cases", TestUtil.getRowno(suite_shop_xls, this.getClass().getSimpleName()), "Pass");
else
TestUtil.reportDataSetResult(suite_shop_xls, "Test Cases", TestUtil.getRowno(suite_shop_xls, this.getClass().getSimpleName()), "Fail");


}



}


========================================================================================
Below code for TestBase.java

package com.qtpselenium.base;

import java.io.FileInputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;

import com.qtpselenium.util.ErrorUtil;
import com.qtpselenium.util.Xls_Reader;

public class TestBase {
public static Logger APP_LOGS=null;
public static Properties CONFIG=null;
public static Properties OR=null;

public static Xls_Reader suiteXls=null;
public static Xls_Reader suite_shop_xls=null;
public static Xls_Reader suite_cart_xls=null;
public static Xls_Reader suite_product_display_xls=null;
public static boolean isInitialized=false;
public static WebDriver driver=null;


public void Initialize() throws Exception{
//logs
if(!isInitialized){
APP_LOGS = Logger.getLogger("devpinoyLogger");

//config
APP_LOGS.debug("Loading Properties File");
CONFIG = new Properties();
FileInputStream ip = new FileInputStream(System.getProperty("user.dir")+"//src//com//qtpselenium//config//config.properties");
CONFIG.load(ip);
System.out.println(CONFIG.getProperty("browserType"));


OR = new Properties();
ip = new FileInputStream(System.getProperty("user.dir")+"//src//com//qtpselenium//config//OR.properties");
OR.load(ip);
System.out.println(OR.getProperty("test"));
APP_LOGS.debug("Loaded Properties File successfully");

//xls file
APP_LOGS.debug("Loading xls File");
suite_shop_xls= new Xls_Reader(System.getProperty("user.dir")+"//src//com//qtpselenium//xls//Shop Suite.xlsx");
suite_product_display_xls=new Xls_Reader(System.getProperty("user.dir")+"//src//com//qtpselenium//xls//Product Display Suite.xlsx");
suite_cart_xls=new Xls_Reader(System.getProperty("user.dir")+"//src//com//qtpselenium//xls//Cart Suite.xlsx");
suiteXls=new Xls_Reader(System.getProperty("user.dir")+"//src//com//qtpselenium//xls//Suite.xlsx");
APP_LOGS.debug("Loaded xls File successfully");
isInitialized=true;
}

}

//Open Browser
public void openBrowser(){
if(CONFIG.getProperty("browserType").equals("Firefox")){
driver = new FirefoxDriver();
}else if(CONFIG.getProperty("browserType").equals("IE")){
driver=new InternetExplorerDriver();
}else if(CONFIG.getProperty("browserType").equals("Chrome")){
driver=new ChromeDriver();
}
}

//Close Browser

public void closeBrowser(){
driver.quit();
}

public boolean compareTitle(String expectedTitle){
try{
Assert.assertEquals(driver.getTitle(),expectedTitle);
}catch(Throwable t){
ErrorUtil.addvarificationFailure(t);
APP_LOGS.debug("Title do not match");
return false;
}
return true;

}

}
==================================================================================

M
Replied on 21/12/2015

zip the project and upload.


M
Replied on 26/12/2015

Dear Ashish,

please check attached project.


M
Replied on 27/12/2015

runmode should be Y

Responsive image