Hybrid Framework

Hi Sir,

Thanks for this great site. It’s really helping me learning selenium webdriver.

I am facing one exception while running the frame work script.

It is showing  InvocationTargetException from  the below code

public static void execute_Actions() throws Exception {

for(int i=0;i<method.length;i++)
{
if(method[i].getName().equals(sActionKeyword))
{
method[i].invoke(actionKeywords,sPageObject);
break;
}
}
}

Can you please suggest me how to overcome this exception or what I am doing wrong?
Waiting for your reply. Again thanks for sharing the knowledge with us.

Thanks,
Nazir Hussain

Please add the complete code , what does the Method array contains.
Please elaborate a bit so that we can help you

on August 9, 2015.

this is my execution engine
——————————–

package familyportal;

import java.io.FileInputStream;
import java.util.Properties;
import java.lang.reflect.Method;

import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.WebDriver;

import fpconfig.Constants;
import fpconfig.FPActionKeywords;
import utility.FPExcelUtils;
import utility.Log;

public class FamilyLogin {

public static Properties OR;
public static Class actionKeywords;
public static String sActionKeyword;
public static String sPageObject;
public static Method method[];
public static Object obj;
public WebDriver driver;

public static int iTestStep;
public static int iTestLastStep;
public static String sTestCaseID;
public static String sRunMode;

public FamilyLogin() throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException
{

actionKeywords=Class.forName(“fpconfig.FPActionKeywords”);

obj=actionKeywords.newInstance();

method=actionKeywords.getDeclaredMethods();

}

public static void main(String[]args) throws Exception
{

FPExcelUtils.setExcelFile(Constants.path_TestData);

//This method is to start log4j in the Test Case
DOMConfigurator.configure(“log4j.xml”);

String Path_OR= Constants.Path_OR;
FileInputStream fs = new FileInputStream(Path_OR);
OR=new Properties(System.getProperties());
OR.load(fs);

FamilyLogin startEngine=new FamilyLogin();
startEngine.excute_TestCase();

}

public void excute_TestCase()throws Exception
{
//This Will return the total number of test cases mentioned in the Test Cases Sheet

int iTotalTestCases =FPExcelUtils.getRowCount(Constants.Sheet_TestCases);

System.out.println(“this is count”+iTotalTestCases);

//This loop will execute number of times equals to total number of test cases
for (int iTestCase=2;iTestCase<=iTotalTestCases;iTestCase++)
{

//This is to get Test Case name from the Test Case Sheet
sTestCaseID=FPExcelUtils.getCellData(iTestCase, Constants.Col_TestCaseID, Constants.Sheet_TestCases);

System.out.println(sTestCaseID);
//This is to get Value of the Run Mode Column from the current Test Case
sRunMode = FPExcelUtils.getCellData(iTestCase,Constants.Col_RunMode,Constants.Sheet_TestCases);

//This is the Condition statement on Run Mode Value
if(sRunMode.equals(“Yes”))
{
System.out.println(sRunMode);

//Only if the Run mode is yes this part of code will execute
iTestStep=FPExcelUtils.getRowContains(sTestCaseID, Constants.Col_TestCaseID, Constants.Sheet_TestSteps);

System.out.println(“test step”+iTestStep );

iTestLastStep=FPExcelUtils.getTestStepCount(Constants.Sheet_TestSteps,sTestCaseID,iTestStep);
Log.startTestCase(sTestCaseID);

System.out.println(“test step”+iTestLastStep );

//This loop will execute number of times equals to Total number of test Steps
for(;iTestStep<=iTestLastStep;iTestStep++)
{

sActionKeyword=FPExcelUtils.getCellData(iTestStep,Constants.Col_ActionKeyword,Constants.Sheet_TestSteps);

sPageObject=FPExcelUtils.getCellData(iTestStep, Constants.Col_PageObject, Constants.Sheet_TestSteps);
execute_Actions();
}
Log.endTestCase(sTestCaseID);
}
}

}

public static void execute_Actions() throws Exception {

try
{

for(int i=0;i<method.length;i++)
{

System.out.println(“Invoce please”);
System.out.println(method[i]);
method[i].invoke(obj,sPageObject);

System.out.println(“Invoced”);
break;
}

}

catch (Exception e)
{
e.printStackTrace();
}

}

}

and this is my action Class
———————————-

package fpconfig;

import java.util.concurrent.TimeUnit;

import static familyportal.FamilyLogin.OR;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import familyportal.FamilyLogin;
import utility.Log;

public class FPActionKeywords {

static WebDriver driver;

static void openBrowser(String object)
{

System.out.println(object);
driver=new FirefoxDriver();

}

static void navigate(String object)

{
System.out.println(object);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get(Constants.URL);

}

static void maxWindow(String object)
{
System.out.println(object);
driver.manage().window().maximize();

}
static void inputUsername(String object)
{

driver.findElement(By.id(OR.getProperty(object))).sendKeys(Constants.UserName);

}

static void inputPassword(String object)
{

driver.findElement(By.id(OR.getProperty(object))).sendKeys(Constants.Password);

}

static void clickLogin(String object)
{

driver.findElement(By.id(OR.getProperty(object))).click();

}

static void waitFor(String object) throws Exception
{
System.out.println(object);
Thread.sleep(5000);

}

static void clickLogout(String object)
{

driver.findElement(By.linkText(OR.getProperty(object)));

}

static void closeBrowser(String object)

{
System.out.println(object);
driver.quit();

}
}

this is the error that I am getting
————————————–

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at familyportal.FamilyLogin.execute_Actions(FamilyLogin.java:131)
at familyportal.FamilyLogin.excute_TestCase(FamilyLogin.java:110)
at familyportal.FamilyLogin.main(FamilyLogin.java:64)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/Logger
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
at org.apache.logging.log4j.jcl.LogAdapter.newLogger(LogAdapter.java:34)
at org.apache.logging.log4j.jcl.LogAdapter.newLogger(LogAdapter.java:30)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:40)
at org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(LogFactoryImpl.java:55)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:657)
at org.apache.http.conn.ssl.AbstractVerifier.<init>(AbstractVerifier.java:89)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.<init>(AllowAllHostnameVerifier.java:40)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:126)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:65)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:234)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:211)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:88)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:62)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:57)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:93)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at fpconfig.FPActionKeywords.openBrowser(FPActionKeywords.java:23)
… 7 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 32 more
Invoce please
public void fpconfig.FPActionKeywords.openBrowser(java.lang.String)
Nevigate to Web Site
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at familyportal.FamilyLogin.execute_Actions(FamilyLogin.java:131)
at familyportal.FamilyLogin.excute_TestCase(FamilyLogin.java:110)
at familyportal.FamilyLogin.main(FamilyLogin.java:64)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:65)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:234)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:211)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:88)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:62)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:57)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:93)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at fpconfig.FPActionKeywords.openBrowser(FPActionKeywords.java:23)
… 7 more

on August 24, 2015.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.