我在运行代码时面对driver.get(URL)上的空指针异常。我正在使用Selenium 3和TestNG.Here,我正在尝试使用Assert验证URL。请帮助解决一些问题。
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");
}
答案 0 :(得分:1)
根据您的代码,您忘记初始化WebDriver。
只需写下这一行
driver = new ChromeDriver();
driver.get(URL);