Plz find below small snippets of 3 classes I am talking about, I have not included Class B here rather, Class A, B and D are present. Let me know if this helps
<-------------------- Class A --------------------------->
public class BaseTest
{
protected WebDriver driver;
protected Selenium selenium;
protected long timeout = 90;
protected WebElement webElement;
protected Properties adjustment;
protected Properties commercialinvoice;
protected Properties bankaccount;
protected Properties bankpayment;
protected Properties paymentsettings;
protected Properties config;
protected Properties common;
protected int flg;
protected boolean isFirefox = false;
private boolean isParallel = Boolean.FALSE;
protected String platform = null;
public static String testCaseName= null;
protected LinkedHashMap<String, String> testCaseMap = new LinkedHashMap<>();
protected Map<String, List<ParamDataObject>> keywordMap = new HashMap<>();
protected List<String> usrRoles = new ArrayList<>();
public BaseTest() throws Exception
{
initiaLize();
}
public void initiaLize() throws Exception
{
common = new Properties();
common.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/common/common.properties")));
config = new Properties();
config.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/common/config.properties")));
adjustment = new Properties();
adjustment.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/commercialinvoice/adjustment/adjustment.properties")));
commercialinvoice = new Properties();
commercialinvoice.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/commercialinvoice/commercialinvoice.properties")));
bankpayment = new Properties();
bankpayment.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/bankpayment/bankpayment.properties")));
bankaccount = new Properties();
bankaccount.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/bankaccount/bankaccount.properties")));
paymentsettings = new Properties();
paymentsettings.load(new FileInputStream(System.getProperty("user.dir").concat("/src/resources/org/gtn/p2p/paymentsettings/paymentsettings.properties")));
}
@BeforeClass
@Parameters({ "browser", "URL"})
public void instantiateWebDriver(String browser, String url) throws Exception
{
try
{
if (browser.equalsIgnoreCase(Constants.FIREFOX_BROWSER))
{
FirefoxProfile profile = new FirefoxProfile();//new File("C:/WebProfile"));
driver = new FirefoxDriver(profile);
}
else if (browser.equalsIgnoreCase(Constants.IE_BROWSER))
{
driver = new InternetExplorerDriver();
}
else if (browser.equalsIgnoreCase("*chrome"))
driver = new ChromeDriver();
selenium = new WebDriverBackedSelenium(driver, url);
driver.get(url);
maximiseWindow();
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterClass(alwaysRun = true)
public void stopWebDriver()
{
driver.manage().deleteAllCookies();
driver.close();
}
public boolean appLogin(List<String> param) throws Exception{
driver.findElement(By.xpath(common.getProperty("Username"))).sendKeys(userName);
driver.findElement(By.xpath(common.getProperty("Username"))).sendKeys(pwd);
driver.findElement(By.xpath(common.getProperty("LoginButton"))).click();
waitForElementPresent(By.xpath(common.getProperty("SearchButton")));
}
}
<----------- Class B ---------------------------->
public class AddChargesandDiscountPOI extends BaseTest {
public AddChargesandDiscountPOI() throws Exception {
super();
// TODO Auto-generated constructor stub
}
private void fetchKeywordAndData() throws Exception
{
List<ParamDataObject> objList = new ArrayList<>();
List<String> paramList = new ArrayList<>();
Set<String> keySet = testCaseMap.keySet();
Iterator<String> iterator = keySet.iterator();
while (iterator.hasNext())
{
String tcid = (String) iterator.next();
objList = keywordMap.get(tcid);
for (ParamDataObject paraObj : objList)
{
Reporter.log("Keyword executed : " + paraObj.getKeywordName());
paramList = paraObj.getParamList();
if(Controller.mainController(paraObj.getKeywordName(), paramList))
continue;
else
break;
}
}
}
@Test
public void mainAddChargesandDiscountPOI() throws Exception {
String filepath = System.getProperty("user.dir").concat(adjustment.getProperty("Adj_DataFilePath"));
int sheetnum = 0;
try {
readFromExcel(filepath, sheetnum);
System.out.println("Driver=========>" + driver);
fetchKeywordAndData();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
<------------------- Class D --------------------------->
public class Controller {
public static boolean mainController (String Keyword, List<String> param_array) throws Exception{
switch (Keyword) {
case "Login":
BaseTest baseLogin = new BaseTest();
if (baseLogin.appLogin(param_array))
return Boolean.TRUE;
else
return Boolean.FALSE;
}
}