-1

SignUpPageTest CLASS :

public class SignUpPageTest extends TestBase 
{
    TestUtil util;
    HomePage homePage;
    SignUpPage signUpPage;
    String sheetName="SignUp_Data";

    public SignUpPageTest()
    {
        super();
    }

    @BeforeMethod
    public void setUp()
    {
        initialization();
        util = new TestUtil();
        signUpPage = new SignUpPage();
        homePage = new HomePage();
        signUpPage.clickOnSignInMouseHover();
    }
    @DataProvider
    public Object[][] getSignUpTestData()
    {
        Object data[][]= TestUtil.getTestData(sheetName);
        return data;
    }


    @Test (dataProvider="getSignUpTestData")
    public void validateCreateNewUser(String email, String FName, String LName, String Password, String CPassword)
    {
        signUpPage.clickOnSignInMouseHover();

        signUpPage.createNewUser(email, FName , LName, Password , CPassword);

    }

    @AfterMethod 
    public void tearDown()
    {
        driver.quit();
    }


}

TestUtil CLASS :

public class TestUtil {

    public static long PAGE_LOAD_WAIT= 20;
    public static long IMPLICIT_WAIT =20;

    public static WebDriver driver;
    static Workbook book;
    static org.apache.poi.ss.usermodel.Sheet sheet1;
    static JavascriptExecutor js;

public static String sheetPath = "C:\\eclipse_workspace\\WalmartProject\\src\\main\\java\\com"+
                                "\\walmart\\qa\\testdata\\Walmart_TestData.xlsx";

    public static Object[][] getTestData(String sheetName)
    {
    FileInputStream file= null;
    try
    {
    file= new FileInputStream(sheetPath);   
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }
    try 
    {
        book = WorkbookFactory.create(file);
    }
    catch(InvalidFormatException e)
    {
        e.printStackTrace();
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
    sheet1 = book.getSheet(sheetName);
    int rowCount = sheet1.getLastRowNum();
    int colNo = sheet1.getRow(0).getLastCellNum();

    //Two-Dimentional Object Array
    Object[][] data= new Object[rowCount][colNo];

    for(int i=0;i<rowCount;i++)
    {       for (int j=0;j<colNo;j++)
            {
            data[i][j]  = sheet1.getRow(i+1).getCell(j).toString();
            System.out.println(data[i][j]);
            }
    }
return data;

    }

}

I got this error :

[Utils] [ERROR] [Error] java.lang.NullPointerException at com.walmart.qa.util.TestUtil.getTestData(TestUtil.java:72) at com.walmart.qa.testcases.SignUpPageTest.getSignUpTestData(SignUpPageTest.java:38) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:55) at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45) at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:115) at org.testng.internal.Parameters.handleParameters(Parameters.java:509) at org.testng.internal.Invoker.handleParameters(Invoker.java:1308) at org.testng.internal.Invoker.createParameters(Invoker.java:1036) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1126) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:744) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) 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) SKIPPED: validateCreateNewUser java.lang.RuntimeException: java.lang.NullPointerException at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:49) at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:115) at org.testng.internal.Parameters.handleParameters(Parameters.java:509) at org.testng.internal.Invoker.handleParameters(Invoker.java:1308) at org.testng.internal.Invoker.createParameters(Invoker.java:1036) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1126) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:744) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) 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 com.walmart.qa.util.TestUtil.getTestData(TestUtil.java:72) at com.walmart.qa.testcases.SignUpPageTest.getSignUpTestData(SignUpPageTest.java:38) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:55) at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)

... 22 more

Default test

Tests run: 1, Failures: 0, Skips: 1

=============================================== Default suite Total tests run: 1, Failures: 0, Skips: 1 ===============================================**

  • Try to debug your code that are you getting your file and sheet name – Upkar Singh Aug 14 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.