POM、BaseTest、およびTestクラスが添付されています。プロジェクトを右クリックしてTestNGテストとして実行しようとすると、下のコードのNullPointerExceptionが表示されます。どうか提案できますか?PageFactoryを使用してスクリプトを実行しようとすると「NullPointerException」が発生する
POMクラス:
package pom;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class Introduction
{
@FindBy(xpath="//a[text()='Hello. Sign In']")
WebElement signInLink;
public Introduction(WebDriver driver)
{
PageFactory.initElements(driver, this);
}
public void signIn()
{
signInLink.click();
}
}
BaseTestクラス:
package scripts;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.*;
public class BaseTest
{
public WebDriver driver;
@BeforeSuite
public void preCondition()
{
driver= new FirefoxDriver();
driver.get("https://www.walmart.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@AfterSuite
public void postCondition()
{
driver.close();
}
}
テストクラス:
package scripts;
import org.testng.annotations.Test;
import pom.Introduction;
public class SignIn extends BaseTest
{
@Test
public void validSignIn()
{
Introduction i= new Introduction(driver);
i.signIn();
}
}
タイムアウトを増やしてみますか?適切に読み込まれたページが表示されますか? – liquide
例外トレースを共有できますか? – Mahipal