0
我附加了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