/ *我正尝试使用junit执行一个测试用例,当我尝试从@beforeClass * /
执行设置步骤时,问题就来了错误:java.lang.NullPointerException。注意:我导入了库,只是没有在此处发布。
public class HistorialCompras {
WebDriver driver;
@BeforeClass
public void Generico() {
String absolutepath = new File ("drivers\\geckodriver.exe").getAbsolutePath();
System.setProperty("webdriver.gecko.driver", absolutepath );
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("amazon-sign-in-page.com - its too long");
}
@Test
public void Buscar_Historial_Compra() {
driver.findElement(By.id("ap_email")).sendKeys("***");
driver.findElement(By.id("ap_password")).sendKeys("****");
driver.findElement(By.id("signInSubmit")).click();
driver.findElement(By.xpath("(//span [@class='nav-line-2'])[4]")).click();
String currentTitulo = driver.findElement(By.xpath("(//h1[@class='a-spacing-medium'])[1]")).getText();
String ExpectedURL = "Your Orders";
Assert.assertEquals(ExpectedURL, currentTitulo);
}
}
踪迹
java.lang.NullPointerException
at prube.test.Buscar_Historial_Compra(test.java:36)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:389)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:167)
at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:163)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:110)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$3(HierarchicalTestExecutor.java:83)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$null$2(HierarchicalTestExecutor.java:92)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)