0

I am new in automation. Here is my simple TestNG login code , when I ran the code as TestNG it appears java.lang.NullPointerException and by double clicking it highlights the place where I navigate to the URL. here is my code.

enter code here
package Day5pkg;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Day5 {
    public WebDriver driver;
@BeforeTest
      public void beforeTest() {
          System.setProperty("webdriver.firefox.driver","C:\\Users\\Nabila\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");

          FirefoxOptions options = new FirefoxOptions();
            driver.navigate().to("http://www.demo.guru99.com/V4/");
            driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
            options.addArguments("test-type");
            options.addArguments("start-maximized");
            options.addArguments("--js-flags=--expose-gc");  
            options.addArguments("--enable-precise-memory-info"); 
            options.addArguments("--disable-popup-blocking");
            options.addArguments("--disable-default-apps");
            options.addArguments("test-type=browser");
            options.addArguments("disable-infobars");

      }
  @Test  (priority = 0)
    public void login(){
      driver = new FirefoxDriver();

         driver.findElement(By.name("uid")).sendKeys("mngr231");
         driver.findElement(By.name("password")).click();
         driver.findElement(By.name("password")).sendKeys("ehyjusu");
         driver.findElement(By.name("btnLogin")).click();
            System.out.println("Manger Id : mngr230");
      }
1
  • driver is not initialized. you have to create the driver, like driver = new FirefoxDriver(); before navigating to the url Commented Nov 1, 2019 at 14:42

1 Answer 1

1

You have only declared the WebDriver instance as:

public WebDriver driver;

You need to initialize it too as follows:

driver = new FirefoxDriver();

Along with the instance of FirefoxOptions() your effective code block will be:

System.setProperty("webdriver.firefox.driver","C:\\Users\\Nabila\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("--js-flags=--expose-gc");  
options.addArguments("--enable-precise-memory-info"); 
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-default-apps");
options.addArguments("test-type=browser");
options.addArguments("disable-infobars");
driver = new FirefoxDriver(options);
driver.navigate().to("http://www.demo.guru99.com/V4/");
driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
Sign up to request clarification or add additional context in comments.

4 Comments

After did this found number of issues.
@NabilaShakeel Update the question with your current code block and the error trace logs please
Updated. Please review
@NabilaShakeel That is a different issue altogether and you have to raise a new qestion for your new requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.