Error in project | Selenium Forum
R
Rupa Posted on 25/04/2020
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();
	}
}

R
Rupa Replied on 25/04/2020

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;
	}

}


R
Rupa Replied on 26/04/2020

no reply for my project.


A
Ashish Thakur Replied on 29/04/2020

Did you try debugging the code?


A
Ashish Thakur Replied on 29/04/2020

As i noticed in the code. You have made a typo error

	public void beforeTest() throws Exception {
		// initializing the path of production
		String propFilePath = projectPath + resourcesDirectory
				+ "project.propertiees";

should be

	public void beforeTest() throws Exception {
		// initializing the path of production
		String propFilePath = projectPath + resourcesDirectory
				+ "project.properties";


Related Posts