1

I had started at this original post This has been very enlightening to read. I am in the same situation and have been trying to use this as a guide. Unfortunately, I am getting a java.lang.NullPointerException which I know why, its because the page isn't getting loaded but I am not sure why.

Here is my base test class:

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class IRIS_Firefox_Test_Base {
    static WebDriver driver;
    static String baseURL;
@Before
    public void setup() throws IOException{
        baseURL = "http://localhost:3006";
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(30,  TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get(baseURL);
    }
@After
    public void closeFireFox(){
        driver.quit();
    }
}

And my test:

import java.io.IOException;
import org.junit.Test;

import pageObjects.Login_Page;

public class POM_TC extends IRIS_Firefox_Test_Base {
    @Test
    public void login() throws IOException{ 
        super.setup();
        Login_Page.loginInput(driver).sendKeys("scornell");
        Login_Page.passwordInput(driver).sendKeys("password");
        Login_Page.loginBtn(driver).click();
    }
}

I'm not really a well versed java programmer, my background is more JavaScript and C#(not a lot there either though). Maybe I'm missing something simple.

Here is my stack trace:

FAILED: login
java.lang.NullPointerException
    at pageObjects.Login_Page.loginInput(Login_Page.java:13)
    at com.hiiq.qa.testing.gen2.Login_Tests.POM_TCTest.login(POM_TCTest.java:11)
    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:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

thanks to all for their input.

3
  • Why are you calling super.setUp() from your test? It is supposed to be called automatically. Commented Jul 15, 2015 at 16:55
  • Tried removing that, didn't seem to make any difference. Now though I don't know why, but I am not getting nullPointer errors but nothing happens when I run the test. I admit I am learning as I go.'code'=============================================== Default test Tests run: 0, Failures: 0, Skips: 0 =============================================== =============================================== Default suite Total tests run: 0, Failures: 0, Skips: 0 =============================================== [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@e580929: 0 ms Commented Jul 15, 2015 at 17:04
  • changed timeout, now opens baseURL page. Does not perform input though. Commented Jul 15, 2015 at 17:15

1 Answer 1

0

I would add a page load time out:

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

This allows the page to load, giving the program time to catch up and verify that certain elements are available on the page. I would make your setup look like:

@Before
    public void setup() throws IOException{
        baseURL = "http://localhost:3006";
        driver = new FirefoxDriver();
        driver.get(baseURL);
        driver.manage().window().maximize();
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    }

Remove the implicit wait, and add the pageLoadTimeout, also I moved the maximize portion until after the URL is called.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you BlackHatSamurai. I didn't think to try this approach. It unfortunately is still not running the test. It will open the page and wait but not enter any of the inputs from the test. Still hacking at it though
I figured it out. I was importing the incorrect test namespace. I set it to the testng one and it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.