gpt4 book ai didi

java - Pagefactory 在页面对象结构中抛出 null

转载 作者:行者123 更新时间:2023-12-02 12:40:18 26 4
gpt4 key购买 nike

我正在我的页面对象模型自动化框架中实现 pagefactory。我现有的框架在没有 pagefactory 的情况下工作正常。现在我正在实现 pagefactory 来调用元素。我面临一个问题,即 Pagefactory 元素抛出空值。我怀疑这可能是因为构造函数不确定。

我已经构建了一个基于页面对象模型的框架有以下套餐:-com.automationframeworkcom.配置com.pageObjectcom.testcasescom.testsuites

我的测试套件类调用测试用例包中存在的测试用例,并调用自动化框架中的驱动程序和其他基于框架的类。我知道仅仅阅读一些内容很难捕获错误,但可能有人遇到同样的问题并可以帮助我。

我的页面类如下所示:-

public class SynchronizationPage extends Page {

ExcelLib xl = new ExcelLib();

private WebElement element = null;

public SynchronizationPage(WebDriver driver) {
super(driver);
}

protected boolean isSecured() {
return true;
}

@FindBy(how = How.XPATH, using = "//a[@class='header-font']/span[@class='icon-cog']")
@CacheLookup
public WebElement HoverOnSettings;
}

我的测试用例类:-

public class SyncTest extends AutomationTestCaseVerification {

// SynchronizationPage sync = new SynchronizationPage(Page.driver);
SignOutPage signout = new SignOutPage(Page.driver);
ExcelLib xl = new ExcelLib();
SynchronizationPage synccc = PageFactory.initElements(Page.driver, SynchronizationPage.class);

private WebElement element = null;
private WebDriver driver;

public SyncTest() {
super();
}


@Override
protected void verifyTestCases() throws Exception {
syncFeature();
}

public void syncFeature() throws Exception {

try {
WebDriverWait waits = new WebDriverWait(Page.driver, 60);
// waits.until(ExpectedConditions.elementToBeClickable(synccc.clickOnOffButton)).click();
synccc.clickOnOffButton.click();
System.out.println("Yes I clicked");
}
catch(Exception ex)
{
System.out.println("error ="+ex.getMessage());
}

}
}

enter image description here

enter image description here

我收到如下错误:-

java.lang.NullPointerException at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38) at com.sun.proxy.$Proxy5.click(Unknown Source) at com.cc.automation.testcases.SyncTest.syncFeature(SyncTest.java:130) at com.cc.automation.testcases.SyncTest.verifyTestCases(SyncTest.java:60) at com.cc.automation.automationframework.AutomationTestCaseVerification.Execute(AutomationTestCaseVerification.java:58) at com.cc.automation.testsuites.SynchronizationTest.testSync(SynchronizationTest.java:22) 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) at org.testng.internal.Invoker.invokeMethod(Invoker.java:661) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:744) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

我也尝试过在下面申请,但仍然不起作用:-

PageFactory.initElements(this.driver, this);

enter image description here

enter image description here

最佳答案

您可以通过在 SynchronizationPage 类的构造函数中调用 PageFactory.initElements(driver, this); 来尝试一次吗?

关于java - Pagefactory 在页面对象结构中抛出 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44965532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com