Ant RUn is throwing an erroe | Selenium Forum
M
Posted on 24/08/2016
While following steps under Selenium, Module 21 - 2016 video Session Video - 11, I was running Ant Clean and compile and both ran successfully. BUt while running ANT RUN, I am getting below error -

[testng] [TestNG] [ERROR]
[testng] Cannot instantiate class com.qtpselenium.core.hybride.testcases.GmailLogin
[testng] the tests failed

BUILD SUCCESSFUL

M
Replied on 24/08/2016

send me the testng code?


M
Replied on 25/08/2016

package com.tecttest.core.hybride.testcases;


import java.util.Hashtable;

import org.testng.SkipException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.techtest.core.hybride.util.*;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import com.techtest.core.hybride.Keywords;
import com.techtest.core.hybride.util.Constants;
import com.techtest.core.hybride.util.ExtentManager;
import com.techtest.core.hybride.util.Xls_Reader;


public class GmailLogin {
ExtentReports rep = ExtentManager.getInstance();
ExtentTest test ;
static String testName = "RateSetter";
static Xls_Reader xls = new Xls_Reader(Constants.SUITEA_XLS);

@Test(dataProvider="getData")
public void doLogin(Hashtable<String, String> data){


test = rep.startTest(testName);
test.log(LogStatus.INFO, data.toString());//getting the data in the report to see which data teh test case is running on

if(DataUtil.isSkip(xls, testName) || data.get("Runmode").equals("N")){
test.log(LogStatus.SKIP, "Skipping the test as the runmode is N");
throw new SkipException("Skipping the test as runmode is N");

}

test.log(LogStatus.INFO, "Starting rate setter test");

Keywords app = new Keywords(test);
test.log(LogStatus.INFO, "Executing Keywords");

app.executeKeywords(testName, xls, data);

//add screenshot
test.log(LogStatus.PASS, "Test Passed");
//app.getGenerickeywords().reportFailure("XXXX");
//app.getGenerickeywords().takeScreenshot(); this can be used if u need screenshot for each and every step

}



@AfterTest
public void quit(){
if(rep!=null){
rep.endTest(test);
rep.flush();
}

}

@DataProvider
public Object[][] getData(){
return DataUtil.getData(xls, testName);
}


}


NOTE: The code is running if I run from Testng.xml file. but the same is not running from build.xml file. I am also attaching the build.xml file for ur reference - Also CLEAN and COMPILE is running and also RUN is also building successful but above is getting displayed -

<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="suite1">
<xmlfileset dir="${ws.home}" includes="src/test/resources/testng.xml"/>
</testng>
</target>


M
Replied on 26/08/2016

Some times we get "Cannot instantiate class " TestNG Exception if the spread sheet format has some problem. So if you are getting data from spread sheet then check the format.

and

Try project -> clean

then execute mvn eclipse:clean and mvn eclipse:eclipse.


M
Replied on 30/08/2016

Tried all optioned above and also tried the same code base in mac and windows but getting the same error on both OS


M
Replied on 31/08/2016

ping me on skype.


M
Replied on 31/08/2016

Let me know a convenient time for a chat on skype.

Thanks
Vijay


M
Replied on 31/08/2016

4:30 PM IST today.


M
Replied on 31/08/2016

As suggested, attaching the project.


M
Replied on 01/09/2016

[attachment=0:2afxsnza]Screenshot (167).png[/attachment:2afxsnza]

add this to your testcase
[code:2afxsnza] @BeforeMethod
public void before() {
extentreport = ExtentManager.getInstance();
xls = new Xls_Reader(Constants.EXCEL_PATH);

}[/code:2afxsnza]

and replace this in your build.xml

[code:2afxsnza]<!-- compile -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*" />
</delete>
<echo message="making directory..." />
<mkdir dir="${test.dest}" />
<echo message="classpath---------: ${test.classpath}"/>
<echo message="compiling..." />
<javac includeantruntime="false" debug="true" destdir="${test.dest}" srcdir="${test.src}"
target="1.8" classpath="${test.classpath}">
</javac>
</target>
[/code:2afxsnza]

Responsive image

M
Replied on 01/09/2016

NoLUCK

Still getting the same error -

run:
[testng] [TestNG] [ERROR]
[testng] Cannot instantiate class com.tecttest.core.hybride.testcases.GmailLogin
[testng] The tests failed.

Below r the changes made -

<!-- compile -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*" />
</delete>
<echo message="making directory..." />
<mkdir dir="${test.dest}" />
<echo message="classpath---------: ${test.classpath}"/>
<echo message="compiling..." />
<javac includeantruntime="false" debug="true" destdir="${test.dest}" srcdir="${test.src}"
target="1.8" classpath="${test.classpath}">
</javac>
</target>


can u confirm what java version u were using and also what JRE System library?


M
Replied on 01/09/2016

JDK1.8 and JRE1.8

download it from here

http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-windows-x64.exe


did you add the [color=#FF0000:2dqaviob]@beforemethod[/color:2dqaviob] in testcases?


M
Replied on 01/09/2016

Yes I have implemented the before method but I am getting below error message -

Caused by: java.lang.NullPointerException
at com.confused.core.hybride.util.Data_Utility.getdata(Data_Utility.java:12)
at core.confused.hybride.testcases.Confused_Login.getData(Confused_Login.java:67)


M
Replied on 01/09/2016

Also can you share the project with the changes made so that I can compare how it worked for u on ur machine and not on mine?

Thanks
Vijay


M
Replied on 01/09/2016

here is the project.