Getting Java Null Pointer Exception on running the test case in Seleniumn Can someone pls let me know where i need to fix in order to progress

0 votes

Below is the Error:

java.lang.RuntimeException: java.lang.NullPointerException

at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:49)

at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:131)

at org.testng.internal.Parameters.handleParameters(Parameters.java:706)

at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:49)

at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:37)

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:924)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)

at org.testng.TestRunner.privateRun(TestRunner.java:648)

at org.testng.TestRunner.run(TestRunner.java:505)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)

at org.testng.SuiteRunner.run(SuiteRunner.java:364)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)

at org.testng.TestNG.runSuites(TestNG.java:1049)

at org.testng.TestNG.run(TestNG.java:1017)

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Caused by: java.lang.NullPointerException

at com.qa.FreeCRMPRO.Utils.ExcelUtil.getTestData(ExcelUtil.java:38)

at com.qa.FreeCRMPRO.test.DealsPageTest.getEventInfo(DealsPageTest.java:96)

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:124)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)

at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)

... 22 more

Excel Util:

public class ExcelUtil {

public static Workbook book;

public static Sheet sheet;


public static String TESTDATA_SHEET_PATH = "D:\\Excel\\FreeCRMPROCompanies.xlsx";


public static Object [][] getTestData(String sheetName) 

{

try {

FileInputStream ip = new FileInputStream(TESTDATA_SHEET_PATH);

try {

book= WorkbookFactory.create(ip);

} catch (InvalidFormatException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

sheet= book.getSheet(sheetName);

Object data[][] = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];

for(int i=0;i<sheet.getLastRowNum();i++)

{

for(int k =0;k<sheet.getRow(0).getLastCellNum();k++)

{

data[i][k] = sheet.getRow(i+1).getCell(k).toString();

}

}

return data;

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

System.out.println("Not able to fetch the values from the Excel");

}

Page :

public void EditEvent(String newtitle,String calender,String addnewcalender,String calender1,

String startdates,String enddates,String catvalue,String desc,

String loca,String dealsselection,String alertbefore,

String alertviadrop,String remindtime,String assignedtoselect,String intervalvalue,String dayvalue,

String seldate)

{

try {

elementutils.waitforElementPresent(AddEventbutton);

elementutils.doclick(AddEventbutton);

elementutils.waitforElementPresent(eventtitle);

elementutils.doSendKeys(eventtitle, newtitle);

elementutils.waitforElementPresent(Calenderdropdownclick);

elementutils.doclick(Calenderdropdownclick);

elementutils.selectvaluefromdropdown(calendervalueselection, calender);

elementutils.waitforElementPresent(addnewCalenderName);

elementutils.doSendKeys(addnewCalenderName, addnewcalender);

elementutils.waitforclickingElement(savecalendername);

elementutils.doclick(savecalendername);

elementutils.selectvaluefromdropdown(calendervalueselection, calender1);

elementutils.waitforclickingElement(Startdateclick);

elementutils.clickonCalender(startdatecolumselection, startdates);

elementutils.waitforElementPresent(enddateclick);

elementutils.doclick(enddateclick);

elementutils.waitforclickingElement(enddatecolumnselection);

elementutils.clickonCalender(enddatecolumnselection, enddates);

elementutils.waitforclickingElement(categoryEvent);

elementutils.doclick(categoryEvent);

elementutils.selectvaluefromdropdown(categoryEventvalue, catvalue);

elementutils.waitforElementPresent(description);

elementutils.doSendKeys(description, desc);

elementutils.waitforElementPresent(location);

elementutils.doSendKeys(location, loca);

elementutils.waitforElementPresent(alldaytoggle);

elementutils.doclick(alldaytoggle);

elementutils.waitforclickingElement(DealSearchicon);

elementutils.doclick(DealSearchicon);

elementutils.selectvaluefromdropdown(dealsdropdownselection, dealsselection);

elementutils.waitforElementPresent(Alertbefore);

elementutils.doclick(Alertbefore);

elementutils.selectvaluefromdropdown(Alertbeforevalue, alertbefore);

elementutils.waitforElementPresent(Alertviadropdown);

elementutils.doclick(Alertviadropdown);

elementutils.selectvaluefromdropdown(Alertviadropdownvalue, alertviadrop);

elementutils.waitforElementPresent(remindertime);

elementutils.doSendKeys(remindertime, remindtime);

elementutils.waitforElementPresent(Assignedto);

elementutils.doclick(Assignedto);

elementutils.selectvaluefromdropdown(Assignedtovalueselection, assignedtoselect);

elementutils.waitforclickingElement(Recurrenceset);

elementutils.doclick(Recurrenceset);

elementutils.waitforElementPresent(intervaldropdownlick);

elementutils.doclick(intervaldropdownlick);

elementutils.selectvaluefromdropdown(intervalvalueselect, intervalvalue);

elementutils.waitforElementPresent(days);

elementutils.doclick(days);

elementutils.selectvaluefromdropdown(daysvalueselect, dayvalue);

elementutils.waitforElementPresent(Endat);

elementutils.doclick(Endat);

elementutils.waitforElementPresent(selectdate);

elementutils.clickonCalender(selectdate, seldate);

elementutils.waitforElementPresent(setbutton);

elementutils.doclick(setbutton);

elementutils.waitforElementPresent(saveevent);

elementutils.doclick(saveevent);

}catch(Exception e)

{

System.out.println("Element is not clickable");

}

}

Test Page:

@DataProvider

public Object[][] EditDealsInfo()

{

Object data[][] = ExcelUtil.getTestData(AppConstants.Edit_Deals_Sheet_Name);

return data;

}

@Test(priority=4,dataProvider="EditDealsInfo",enabled=true)

public void editdetails(String title)

{

dealspage.EditDealsInfo(title);

}

Site: ui.cogmento.com

Excel :

eventstitle calendervalues calendername selectcalendersvalues startdates enddates categorys descriptions locations deals alertbefores alertvias remindertimes assignedtos intervals days finalenddates
newevent New Calendar test test 20/09/2020 20/09/2020 Critical new us sam 1 Hour SMS 12 Sandhyaseleniumn s Monthly Friday 20/09/2020

 
Sep 11, 2020 in Selenium by sandhya
• 180 points
12,172 views
Have you instantiated the web driver in your test case class?

Hello @sandhya ,

Java.lang.RuntimeException: java.lang.NullPointerException is thrown when an application attempts to use null in a case where an object is required. These include:

  • Calling the instance method of a null object.
  • Accessing or modifying the field of a null object.
  • Taking the length of null as if it were an array.
  • Accessing or modifying the slots of null as if it were an array.
  • Throwing null as if it were a Throwable value.
Take above steps into consideration .
Yes this is done in the test class

public class DealsPageTest {

BasePage basepage;

WebDriver driver;

LoginPage loginpage;

Properties prop;

ContactsPage contactspage;

DealsPage dealspage;
Hey @Sandhya, Your data provider probably returns null, so you are getting a null pointer exception, It should return Object[][].

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
0 answers
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13, 2020 in Selenium by Karan
• 19,610 points
7,804 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,616 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,571 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,629 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,517 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP