尝试从Pagefactory框架中的测试类访问页面对象时,抛出java.util.objects.requirenonnull错误

时间:2019-04-06 09:25:52

标签: selenium-webdriver

尝试在pagefactory框架中从测试类访问页面对象时,会引发java.util.objects.requireNonNull错误。

这是我的考试课:

public class Bookingpage_testcases extends Base {
    Bookingpage bp;
    public Bookingpage_testcases() throws IOException {
        super();
    }
    @BeforeTest
    public void init() throws InterruptedException {
        browserinit();
    }
    @Test
    void search() throws IOException {
        System.out.println("search method starts");
        bp = new Bookingpage(driver);
        System.out.println("returned from page class");
        bp.departurecityname();
    }
}

这是我的网页课程:

public class Bookingpage extends Base {

    WebDriver driver;
    WebDriverWait wait = new WebDriverWait(driver, 100);
    @FindBy(xpath = "//input[contains(@placeholder,'Enter Departure City')]")
    WebElement departurecity;
    @FindBy(xpath = "//input[contains(@placeholder,'Enter Arrival City')]")
    WebElement arrivalcity;
    public Bookingpage(WebDriver driver) throws IOException {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }
    public void departurecityname() {
        System.out.println("entered in to departure cityname method");
        departurecity.sendKeys("kuala lumpur"); }
}

它抛出错误为:


FAILED: search
java.lang.NullPointerException
    at java.base/java.util.Objects.requireNonNull(Objects.java:221)
    at org.openqa.selenium.support.ui.FluentWait.<init>(FluentWait.java:106)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:85)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:45)
    at com.qa.ctb.objectpages.Bookingpage.<init>(Bookingpage.java:19)

预先感谢

0 个答案:

没有答案