0

Error ScreenshotGetting Null pointer exception after login....need to click on a button after login.
I created a login class and passed it's driver to this class in before test method. Now when it goes to @Test method ...It throws an exception of Null Pointer.

Previously when I was using extend method it was working fine.

      @Test(priority =1)
  public void clickaddbutton2() {

          WebDriverWait wait=new WebDriverWait(driver, 20);
          WebElement addprojectbutton;
          addprojectbutton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath( "html/body/app-root/app-home/div/div/main/div[3]/div[1]/a/button")));
          addprojectbutton.click();

          String project_infurl = driver.getCurrentUrl();
          System.out.println("This is the url : " +  project_infurl);
          Assert.assertEquals(project_infurl, "http://192.168.1.82:8787/project-information");

  }
 @BeforeTest
  public void beforeClass() throws Throwable {

     LoginPage obj_login = new LoginPage(driver);
     obj_login.setUp();
     obj_login.verifyHomePageTitle();  
  }
JeffC
  • 22,180
  • 5
  • 32
  • 55
Abhishek
  • 1
  • 2

1 Answers1

0

You need to define driver in your testClass and then initialize the driver with the driver creation method. The driver might not have passed to the @Test. Something like this:

 public class testLogin {

        static WebDriver driver;

        @BeforeTest
        public void setUp() throws Exception{
            driver= BrowserFactory.launchApp("chrome","https://www.google.com");
        //Verification code afterlogin


}

        @Test
        public void testSearchSelenium() {


            System.out.println("search test");
            driver.findElement(By.id("lst-ib")).sendKeys("Selenium");


            driver.findElement(By.name("btnK")).click();

        }

    }
PJAutomator
  • 344
  • 3
  • 12