-1

I am using POM with having some common operations like, click, checkText, etc declared in my TestBase class. I have the problem while transition from one step to another. To overcome this issue i want to add explicit wait, and i want to put it in my common operations in TestBase class. i am writing the code as,

For test base class,

public WebDriverWait wait = new WebDriverWait(webDriver,10);

And on the specific page;

landingPage.wait.until(ExpectedConditions.visibilityOf(WebElement)

I am getting the error java.lang.NullPointerException because of TestBase class. May be i am using WebDriver multiple times? I am not sure about that as i have tried many possibilities but still failed. please help me out.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
faheem
  • 11
  • 2
  • 8
  • Please post your `TestBase` class. – jsheeran May 31 '17 at 11:53
  • 1
    What is your project structure ? can you add some code about test base class and calling class – NarendraR May 31 '17 at 12:02
  • public void testPausePageUntilDocumentIsReady() throws Exception { ((JavascriptExecutor) getWebDriver()).executeScript("return document.readyState").equals("complete"); testPausePage(); } public WebDriver getWebDriver() { return webDriver; } public WebDriverWait wait= new WebDriverWait(webDriver,10); public void testPausePage() throws Exception { Thread.sleep(1500); } – faheem May 31 '17 at 12:30
  • 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 May 31 '17 at 13:12

2 Answers2

0

I am able to guess your issue. You are initializing your wait variable in the base. The problem here is webDriver is not initialized at the time of wait initialization. So don't initialize the wait until webdriver variable is initialized. You can declare it in the base class but don't initialize like,
public WebDriverWait wait;

You can initaize it after WebDriver initialization like,
WebDriver webDriver=new FirefoxDriver();
wait =new WebDriverWait(webDriver, 60);

Murthi
  • 5,299
  • 1
  • 10
  • 15
-1

I think u can use thread.sleep in your base class as below. It will also wait for the given time specified in milli seconds in argument.

import yourPOMPage;

public class TestBaseClass{

public WebDriver driver ;

// Define obj variable

yourPOMPage obj;

public void methodName()throws InterruptedException{

        obj = new yourPOMPage(driver);//initialized the obj
        Thread.sleep(5000);
        obj.MethodofPOMPage();  // MethodofPOMPage u must have to create in POM Page

}

}

Ajay
  • 1
  • 1