I'm new to JAVA and Selenium and I really want to understand why my code doesn't work and the NullPointerException is thrown.
Basically, what I want to do is call a method that has WebDriver implementations from a different class to "Master Test" class that will be executed as a JUnit test.
But every time I execute my Master Test then NullPointerException is thrown.
Here's my Master Test that will be executed:
package common_methods;
import org.junit.*;
public class Master_Test extends Configurations {
@Before
public void setUp(){
try{
testConfiguration();
driver.get("http://only-testing-blog.blogspot.ro/");
} catch (Exception e){
System.out.println("setUp Exception: "+e);
}
}
@After
public void tearDown(){
driver.close();
}
@Test
public void masterTest(){
try{
TestCase1 testy1 = new TestCase1();
testy1.test1();
}catch (Exception master_e){
System.out.println("Test Exception: "+master_e);
}
}
}
Now for better understanding here is the Configurations Class that is being extended:
package common_methods;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class Configurations {
public WebDriver driver;
public void testConfiguration() throws Exception{
System.setProperty("webdriver.chrome.driver", "D:\\Browser_drivers\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
}
}
And here is the TestCase1 Class from which I get my method:
package common_methods;
import org.openqa.selenium.*;
public class TestCase1 extends Configurations{
public void test1() throws Exception{
driver.findElement(By.id("tooltip-1")).sendKeys("Test Case 1 action");
Thread.sleep(5000);
}
}
Why do I get the NullPointerException?