次のプログラムを実行しようとしましたが、NULLポインタエラーが発生しました。 @testはオブジェクトドライバにアクセスできません。私が作っている可能性のあるエラーである可能性があります。エラー:Selenium TestNGフレームワークで複数のテストでドライバオブジェクトを呼び出すことができません
JavaScript警告:https://www.google.com/xjs/_/js/k=xjs.s.en_US.MHBUsB8Me90.O/m=sx,c,sb,cdos,cr,elog,hsm,jsa,r,qsm,d,csi/am=wCJGjhccAPk_IRQStxAWyAImDiA/rt=j/d=1/t=zcms/rs=ACT90oGwMPBWhsFBKoM1svJAFUVoVQRQug、行7:オブジェクトの[Prototype]を変更すると、コードの実行が非常に遅くなります。 websiteTitle
java.lang.NullPointerException
at myPackage.TestNGforHDFC.websiteTitle(TestNGforHDFC.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TestNGforHDFC {
public WebDriver driver;
public String urlUnderTest = "http://www.google.com";
public String projLocation = "C:\\Users\\Nikita Agrawal\\Selenium\\geckodriver.exe";
@BeforeTest
public void login()
{
System.setProperty("webdriver.gecko.driver", projLocation);
WebDriver driver = new FirefoxDriver();
driver.get(urlUnderTest);
System.out.println(driver.getCurrentUrl());
}
@Test
public void websiteTitle()
{
System.out.println(driver.getTitle());
}
}
ありがとうございました。それは働いた –
@NileshKhoriya私は私が助けることができてうれしいです。これで問題が解決した場合は、その答えに印を付けることを忘れないでください。 – Titus