0

I am facing null pointer exception on driver.get(URL) while running the code.I am using Selenium 3 with TestNG.Here, I am trying to verify URL using Assert.Please help with some solutions.

import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import static org.testng.Assert.assertEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class WithTestNG 
{
WebDriver driver;

@BeforeClass
public void StartBrowser()
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\Test\\Downloads\\ch
romedriver_win32\\chromedriver.exe" );
driver.manage().window().maximize();
}

@Test
public void OpenStore()
{
String URL = "https://www.facebook.com";
driver.get(URL);

String Actual_URL = driver.getCurrentUrl();
String Expected_URL = "https://www.facebook.com/";
Assert.assertEquals(Actual_URL, Expected_URL, "URL doesn't match");
System.out.println("URL verified");

}
Preet
  • 57
  • 2
  • 10

1 Answers1

1

As per your code you forgot to initialize WebDriver.

just write this line

driver = new ChromeDriver();
driver.get(URL);
Mr. Go
  • 567
  • 1
  • 5
  • 20