Here i have pasted my driverscript and base code.
Base Code
package com.qtpselenium;
import java.io.FileInputStream;
import java.util.Properties;
import org.testng.annotations.BeforeTest;
import com.qtpselenium.driver.DriverScript;
import com.qtpselenium.util.XLS_Reader;
public class BaseTest {
public Properties prop;
public Properties envProp;
public XLS_Reader xlsx = null;
public DriverScript ds;
public String resourcesDirectory = “\src\\test\\resources\\";
public String projectPath = System.getProperty("user.dir");
@BeforeTest
public void beforeTest() throws Exception {
// initializing the path of production
String propFilePath = projectPath + resourcesDirectory
+ "project.propertiees";
FileInputStream iostream = new FileInputStream(propFilePath);
prop = new Properties();
prop.load(iostream);
// initializing the path of environment
String environment = prop.getProperty("env");
String envPropFilePath = projectPath + resourcesDirectory + environment
+ ".propertiees";
FileInputStream envIOStream = new FileInputStream(envPropFilePath);
envProp = new Properties();
envProp.load(envIOStream);
xlsx = new XLS_Reader(projectPath + resourcesDirectory
+ prop.getProperty("SuiteA"));
ds = new DriverScript();
}
}
DriverScript
package com.qtpselenium.driver;
import java.lang.reflect.Method;
import java.util.Properties;
import com.qtpselenium.keywords.ApplicationKeywords;
import com.qtpselenium.util.XLS_Reader;
public class DriverScript {
public Properties prop;
public Properties envProp;
ApplicationKeywords app = null;
public void executeKeywords(String testName, XLS_Reader xlsx)
throws Exception {
app = new ApplicationKeywords();
app.setEnvProp(envProp);
app.setProp(envProp);
int rowCount = xlsx.getRowCount("keywords");
for (int rowNum = 2; rowNum < rowCount; rowNum++) {
String tcid = xlsx.getCellData("Keywords", "TCID", rowNum);
String keyword = xlsx.getCellData("keywords", "Keyword", rowNum);
String objectKey = xlsx.getCellData("Keywords", "Objects", rowNum);
String dataKey = xlsx.getCellData("Keywords", "Data", rowNum);
app.setObjectKey(objectKey);
app.setDataKey(dataKey);
// Reflection API
if (tcid.equals(testName)) {
Method method;
method = app.getClass().getMethod(keyword);
method.invoke(app);
}
}
}
public void setprop(Properties prop) {
this.prop = prop;
}
public void setEnvProp(Properties envProp) {
this.envProp = envProp;
}
}
Instructor
Ashish Thakur Replied on 29/04/2020
Please make sure that the properties file path and name is correct.