I want to pass Selenium webDriver to another class but no success. The program should open the browser ("Google") and type some word in the main class and in the 2nd one should press the "Google" button.
Here is my main class:
public class MainClass {
public WebDriver driver;
@Test
public void main()
{
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.google.co.il/");
driver.findElement(By.name("q")).sendKeys("walla");
}
And here is the class I want to use the driver from the main.
public class FirstClass extends MainClass{
@Test
public void printOnScreen()
{
driver.findElement(By.name("btnK")).click();
}
When I run it its say to me:
PASSED: main
FAILED: printOnScreen
java.lang.NullPointerException
What I am doing wrong?