TestBase main test case function it doesn’t open IE/Firefox/Chrome
Please help
TestBase.java
package com.qtpselenium.base;
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Properties;
import org.apache.log4j.Logger; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; 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; import com.thoughtworks.selenium.Selenium;
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_productDisplay_xls=null;
public static boolean isInitalized=false;
public static WebDriver driver = null;
public static Selenium selenium=null;
public static boolean isBrowserOpened=false;
public void initialize () throws Exception
{// logs
if(!isInitalized)
APP_LOGS = Logger.getLogger(“devpinoyLogger”);
APP_LOGS.debug(“Loading Property files”);
Properties 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(“screenshotPath”));
OR = new Properties();
ip = new FileInputStream(System.getProperty(“user.dir”)+"//src//com//qtpselenium//config/OR.properties");
OR.load(ip);
APP_LOGS.debug(“Loaded Property files successfully”);
//System.out.println(OR.getProperty(“login_link”));
APP_LOGS.debug(“Loading Property files”);
// xls file
suite_shop_xls = new Xls_Reader(System.getProperty(“user.dir”)+"//src//com//qtpselenium//xls//Shop Suite.xlsx");
suite_cart_xls = new Xls_Reader(System.getProperty(“user.dir”)+"//src//com//qtpselenium//xls//Cart Suite.xlsx");
suite_productDisplay_xls = new Xls_Reader(System.getProperty(“user.dir”)+"//src//com//qtpselenium//xls//Product Display Suite.xlsx");
suiteXls = new Xls_Reader(System.getProperty(“user.dir”)+"\src\com\qtpselenium\xls\Suite.xlsx");
APP_LOGS.debug(“Loaded Property files Successfully”);
isInitalized=true;
}
public void openBrowser()
{
if(CONFIG.getProperty(“browserType”).equals(“MOZILLA”))
driver = new FirefoxDriver();
else if (CONFIG.getProperty(“browserType”).equals(“IE”))
driver = new InternetExplorerDriver();
else if (CONFIG.getProperty(“browserType”).equals(“Chrome”))
driver = new ChromeDriver();
}
public void closeBrowser()
{
driver.quit();
}
public boolean compareTitle(String expectedVal)
{
try{
Assert.assertEquals(driver.getTitle(), expectedVal);
}catch(Throwable t) {
ErrorUtil.addVerificationFailure(t);
APP_LOGS.debug(“Titles do not match”);
return false;
}
return true;
}
public boolean compareNumbers(int actualValue, int expectedVal)
{
try{
Assert.assertEquals(expectedVal, actualValue);
}catch(Throwable t) {
ErrorUtil.addVerificationFailure(t);
APP_LOGS.debug(“values do not match”);
return false;
}
return true; }
public boolean checkElementPresence(String xpathKey) { int count = driver.findElements(By.xpath(CONFIG.getProperty(xpathKey))).size(); try{ Assert.assertTrue(count>0, “No element present”);
}catch(Throwable t) {
ErrorUtil.addVerificationFailure(t);
APP_LOGS.debug(“No element present”);
return false; } return true; }
public WebElement getObject (String xpathKey) { try{ return driver.findElement(By.xpath(OR.getProperty(xpathKey))); }catch(Throwable t) { APP_LOGS.debug(“Cannot find object with key–”+ xpathKey); return null;
} }} &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7 AddProductTest.java
package com.qtpselenium.suite.shop;
import org.testng.annotations.Test; import org.openqa.selenium.By; import org.testng.SkipException; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;
import com.qtpselenium.util.TestUtil;
public class AddProductTest extends TestSuiteBase {
String runmodes[]=null;
static int count=-1;
static boolean fail=false;
static boolean skip=false;
static boolean isTestPass=true;
@BeforeTest
public void checkTestSkip(){
if(!TestUtil.isTestCaseRunnable(suite_shop_xls, this.getClass().getSimpleName())){
// APP_LOGS.debug(“Skipping Test Case as runmode set to NO”); //logs
//throw new SkipException(“Skipping Test Case as runmode set to NO”); //reports
}
runmodes=TestUtil.getDataRunmodes(suite_shop_xls, this.getClass().getSimpleName());
}
@Test(dataProvider=“getTestData”)
public void testCaseA2(
String Mobile_Type,
String color,
String memory,
String Engraving,
String quantity
)
{
count++;
if(!runmodes[count].equalsIgnoreCase(“Y”)){
skip=true;
throw new SkipException(“Runmode for test set data set to no” +count);
}
APP_LOGS.debug(“Executing TestCase_A2”);
APP_LOGS.debug(Mobile_Type +" – “+color +” – "+memory );
openBrowser();
driver.get(CONFIG.getProperty(“testSiteName”));
getObject(“shopLink”).click();
getObject(“mobile_phone_link”).click();
}
@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 reportTestResult(){
if(isTestPass)
//TestUtil.reportDataSetResult(suiteAxls, “Test Cases”, count+2, “PASS”);
TestUtil.reportDataSetResult(suite_shop_xls, “Test Cases”, TestUtil.getRowNum(suite_shop_xls,this.getClass().getSimpleName()), “PASS”);
else
//TestUtil.reportDataSetResult(suiteAxls, “Test Cases”, count+2, “FAIL”);
TestUtil.reportDataSetResult(suite_shop_xls, “Test Cases”, TestUtil.getRowNum(suite_shop_xls,this.getClass().getSimpleName()), “FAIL”); }
@DataProvider
public Object[][] getTestData(){
return TestUtil.getData(suite_shop_xls, this.getClass().getSimpleName());
}
}