-1

Hi I have three classes

  1. Drivermethod: In this class I created a method "initiate" to initialise driver

    public class Drivermethod {
        public WebDriver driver;
    
        public static WebDriver initiate(WebDriver driver){
            System.setProperty("webdriver.ie.driver","C:\\Automation\\IEDriverSeer_Win32_3.8.0\\IEDriverServer.exe");
            driver=new InternetExplorerDriver();
            driver.manage().window().maximize(); 
            return driver;
        }
    }
    
  2. Levelmanage: In this class I created a method "managelink" to find an element.

    public class Levelmanage {
        public static  WebElement element;
    
        public static WebElement managelink(WebDriver driver) {
            element=driver.findElement(By.linkText("Manager link"));
            return element;
        }
    }
    
  3. Test1

    public class Test1  {
    
    public WebDriver driver;
    
    @Test
    public void f() {
        Drivermethod.initiate(driver).get("url");
        Levelmanage.managelink(driver).click();
    }
    

In third class am calling the first 2 method...When I run this class(Test1),The first method execution is happening when it goes to the second one(Levelmanage.managelink(driver).click();) driver is getting NULL. Kindly help me on this....

StrikerVillain
  • 3,719
  • 2
  • 24
  • 41
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – JeffC Apr 19 '18 at 14:29

1 Answers1

0

That's because you're not initializing your driver field from the test class.

public class Test1 {

public WebDriver driver;

     @Test public void f() {
          driver = Drivermethod.initiate(driver).get("url");
          Levelmanage.managelink(driver).click();
     }
}

Also, for the initiate method, the WebDriver parameter is useless. That's the place where you're creating your driver, you're not receiving it from anywhere.

Besides this, in case you don't have any other methods in your Drivermethod class, the field WebDriver is useless as well. And I'm guessing this is the case, since it's not assigned anywhere.

Cosmin
  • 2,354
  • 2
  • 22
  • 39