Are other classes able to access the webdriver instance when extending test base class?



  • I am getting this error when running the below selenium scripts using TestNG with Selenium Grid. I'm extending the testbase class to access the WebDriver, but I'm not sure if each class is getting the WebDriver instance correctly since I'm getting a NullPointerException?

    The tests scrolls to the first item to click and doesn't click it. I'm new to Java, please advise. I am wondering if I'm understanding inheritance and initiation of objects correctly. Thanks for your help.

    java.lang.NullPointerException



  • Agree with @Dale Emery.

    Use this code:

    public class WatchTV {
    
        WebDriver driver;
        WebDriverWait wait;
        int waitseconds = 60;
    
        public WatchTV(WebDriver driver){
            this.driver = driver;
            wait = new WebDriverWait(driver, waitseconds);
        }
    
        By watchtvlink = By.linkText("Watch TV »");
    
        public WebElement WatchTVLink()
        {
            wait.until(ExpectedConditions.elementToBeClickable(watchtvlink));
            return driver.findElement(watchtvlink);
        }
    
    }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2