Module 20 [Zoho.com] -- Getting error in @AfterMethod | Selenium Forum
M
Posted on 04/10/2016
Hi Ashish,
i am getting below error during executing the code.It is come from @AfterMethod i debug it. so please solve this where i am wrong.
Error come on below code :-
if(rep!=null){
[b:9yy1c0jj]rep.endTest(test);[/b:9yy1c0jj]
rep.flush();
}


[b:9yy1c0jj]Note:- Project attached[/b:9yy1c0jj]

[b:9yy1c0jj]Stack Trace :-[/b:9yy1c0jj]


Oct 04, 2016 8:40:47 PM com.relevantcodes.extentreports.ExtentReports loadConfig
WARNING: Unable to perform report configuration. The file D:\zohoProject\zohoDDF\ReportsConfig.xml was not found.
[TestNG] Running:
C:\Users\user\AppData\Local\Temp\testng-eclipse-711387312\testng-customsuite.xml

FAILED CONFIGURATION: @AfterMethod quit
java.lang.NullPointerException
at com.relevantcodes.extentreports.ExtentReports.endTest(ExtentReports.java:618)
at Zoho.TestCases.LeadTest.quit(LeadTest.java:102)
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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:708)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)

PASSED: deleteLeadTest
SKIPPED: createLeadTest
java.lang.RuntimeException: java.lang.NullPointerException
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:162)
at org.testng.internal.Parameters.handleParameters(Parameters.java:430)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1276)
at org.testng.internal.Invoker.createParameters(Invoker.java:992)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1082)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
Caused by: java.lang.NullPointerException
at Zoho.TestCases.LeadTest.getData(LeadTest.java:85)
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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:136)
... 20 more

SKIPPED: convertLeadTest
java.lang.RuntimeException: java.lang.NullPointerException
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:162)
at org.testng.internal.Parameters.handleParameters(Parameters.java:430)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1276)
at org.testng.internal.Invoker.createParameters(Invoker.java:992)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1082)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
Caused by: java.lang.NullPointerException
at Zoho.TestCases.LeadTest.getData(LeadTest.java:85)
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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:136)
... 20 more


===============================================
Default test
Tests run: 3, Failures: 0, Skips: 2
Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 3, Failures: 0, Skips: 2
Configuration Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.XMLReporter@79698539: 17 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4e04a765: 8 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@5f2050f6: 12 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@13969fbe: 220 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 7 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1554909b: 53 ms

M
Replied on 05/10/2016

where are you starting the extent report. are these global properties?

[color=#FF0000:1of8dubv]rep [/color:1of8dubv]and [color=#FF0000:1of8dubv]test[/color:1of8dubv]


M
Replied on 05/10/2016

Yes. These are the global properties. I am using it in the "BaseTest" class.

[b:2hm6our4]Screen Shot attached.[/b:2hm6our4]

Responsive image

M
Replied on 06/10/2016

please send the highlighted code of where you're initializing.


M
Replied on 06/10/2016

Hi Ahish,
I am sending you the attachment of my "BaseTest.java" & "LeadTest.java". so please have a look and suggest.


M
Replied on 07/10/2016

Any Update?


M
Replied on 08/10/2016

where are you initializing this [color=#FF0000:21cmeaf7]public ExtentTest test;[/color:21cmeaf7]??


M
Replied on 08/10/2016

[b:34foi6pl]In My BaseTest.java class Code :- [/b:34foi6pl]

package zohoDDF.Base;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

import zohoDDF.Util.ExtentManager;
import zohoDDF.Util.Xls_Reader;

public class BaseTest {

public WebDriver driver=null;
public Properties prop=null;
public ExtentReports rep = ExtentManager.getInstance();
[b:34foi6pl]public ExtentTest test;[/b:34foi6pl]
//public Xls_Reader xl=null;



public void Init() {

if(prop==null){
prop= new Properties();
try{
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"//src//test//resources//projectconfig.properties");
prop.load(fs);
}
catch(Exception ex){
ex.getStackTrace();
}
}

}


public void openBrowser(String bType) throws IOException{
test.log(LogStatus.INFO, "Opening the Browser" + bType);
if(bType.equals("Mozilla"))
driver=new FirefoxDriver();
else if(bType.equals("Chrome")){
System.setProperty("webdriver.chrome.driver", prop.getProperty("chromedriver_exe"));
driver= new ChromeDriver();
}
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
test.log(LogStatus.INFO, "Browser Opened Sucessfully" +bType);


}

public void navigate(String locatorKey){
test.log(LogStatus.INFO, "Navigate to -- " +prop.getProperty(locatorKey));
driver.get(prop.getProperty(locatorKey));

}

public void click(String XpathKey){
driver.findElement(By.xpath(prop.getProperty(XpathKey))).click();
}

public void type(String XpatKey,String ValueKey){
getElement(XpatKey).sendKeys(ValueKey);


}

public WebElement getElement(String XpathKey){
WebElement e = null;
try{
if(XpathKey.endsWith("_xpath"))
e= driver.findElement(By.xpath(prop.getProperty(XpathKey)));
else if(XpathKey.endsWith("_id"))
e= driver.findElement(By.id(prop.getProperty(XpathKey)));
else if(XpathKey.endsWith("_name"))
e= driver.findElement(By.name(prop.getProperty(XpathKey)));
else{reportFailure("Xpath not correct --" +XpathKey);
Assert.fail("Xpath not correct --" +XpathKey);
}
}catch(Exception ex){
reportFailure(ex.getMessage());
ex.printStackTrace();
Assert.fail("Failed the Test -- " +ex.getMessage());
}
return e;
}


public void wait(int timetoWait) {
try {
Thread.sleep(timetoWait * 1000);
} catch (InterruptedException e) {

e.printStackTrace();
}
}


public int getLeadRowCount(String leadName){
test.log(LogStatus.INFO, "Finding the lead" + leadName);
List<WebElement> leadNames = driver.findElements(By.xpath(prop.getProperty("leadnames_xpath")));

for(int i=0;i<leadNames.size();i++){

if(leadNames.get(i).getText().equals(leadName))
test.log(LogStatus.INFO, "Lead found on the row" + i);
return (i+1);

}
return -1;
}


public void clickonLead(String leadName){
test.log(LogStatus.INFO, "Clicking of Lead" + leadName);
int rNum= getLeadRowCount(leadName);
driver.findElement(By.xpath(prop.getProperty("leadPart1_xpath")+rNum+prop.getProperty("leadPart2_xpath"))).click();

}



/************************************App Functions *************************************/

public void waitforPageload(){

JavascriptExecutor js = (JavascriptExecutor)driver;
String state = (String)js.executeScript("return document.readyState");
while(!state.equals("complete"));
wait(2);
state = (String)js.executeScript("return document.readyState");

}


public boolean doLogin(String username,String pwd){

click("loginButton_xpath");
wait(1);
//waitforPageload();
driver.switchTo().frame(0);
type("username_xpath", username);
type("pwd_xpath", pwd);
click("SignIn_button_xpath");

if(isElementPresent("crm_xpath")){
test.log(LogStatus.INFO, "Login Sucessfull");
return true;}
else {
test.log(LogStatus.INFO, "Login UnSucessfull");
return false;}

}


/************************Validation Function************************************/


public boolean verifyTitle(String locatorKey,String expectedResult){
String actualText=getElement(locatorKey).getText().trim();
String expectedTest=prop.getProperty("signinText");
if(actualText.equals(expectedTest))
return true;
else
return false;

}

public boolean isElementPresent(String locatorKey){
List<WebElement> elementList=null;

if(locatorKey.endsWith("_xpath"))
elementList = driver.findElements(By.xpath(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_id"))
elementList = driver.findElements(By.id(prop.getProperty(locatorKey)));
else if(locatorKey.endsWith("_name"))
elementList= driver.findElements(By.name(prop.getProperty(locatorKey)));


else{
reportFailure("Locaor is not correct --- "+locatorKey);
Assert.fail("Locaor is not correct --- "+locatorKey);
}

if(elementList.size()==0){
return false;
}

return true;

}





/************************Reporting Function************************************/

public void Reportpass(String msg){
test.log(LogStatus.INFO, msg);

}

public void reportFailure(String msg){
test.log(LogStatus.FAIL, msg);
takeScreenShot();
Assert.fail(msg);
}

public void takeScreenShot(){
// fileName of the screenshot
Date d=new Date();
String screenshotFile=d.toString().replace(":", "_").replace(" ", "_")+".png";
// store screenshot in that file
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"//TakeScreenShots//"+screenshotFile));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//put screenshot file in reports
test.log(LogStatus.INFO,"Screenshot-> "+ test.addScreenCapture(System.getProperty("user.dir")+"//TakeScreenShots//"+screenshotFile));

}


}


M
Replied on 10/10/2016

Any Update?


M
Replied on 10/10/2016

i'm not able to run the project please send me xlsx file.


M
Replied on 11/10/2016

Xlsx file is attached.Plz look into this.


M
Replied on 12/10/2016

you project is not running @Test

so it is not initializing the test, driver etc hence null pointer exception.

initialize test here

[code:18lzh881]@Test(priority = 2, dataProvider = "getData")
public void convertLeadTest() {

}

@Test(priority = 3)
public void deleteLeadTest() {

}[/code:18lzh881]