无法调用,因为“这个”。是无效的
我正在尝试创建一个简单的自动化测试来打开 Chrome 中的某个链接,但我遇到了这个问题。我之前读过,我应该用 @Component 注释我的类,我这样做了,但仍然无法访问我的链接。 Webdriver 打开正常,但在我收到此问题后不久:
Message: java.lang.NullPointerException: Cannot invoke
"com.automation_practice.pom.pages.homepage.HomePage.open()" because "this.homePage" is null
Stack Trace:
com.automation_practice.gauge.steps.TestSteps.openMyAccountPage(TestSteps.java:40)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:568)
com.thoughtworks.gauge.execution.MethodExecutor.execute(MethodExecutor.java:28)
com.thoughtworks.gauge.execution.StepExecutionStage.executeStepMethod(StepExecutionStage.java:66)
com.thoughtworks.gauge.execution.StepExecutionStage.executeStep(StepExecutionStage.java:59)
com.thoughtworks.gauge.execution.StepExecutionStage.execute(StepExecutionStage.java:41)
com.thoughtworks.gauge.execution.AbstractExecutionStage.executeNext(AbstractExecutionStage.java:14)
com.thoughtworks.gauge.execution.HookExecutionStage.execute(HookExecutionStage.java:33)
com.thoughtworks.gauge.execution.ExecutionPipeline.start(ExecutionPipeline.java:19)
com.thoughtworks.gauge.processor.ExecuteStepProcessor.process(ExecuteStepProcessor.java:41)
com.thoughtworks.gauge.RunnerServiceHandler.lambda$executeStep$7(RunnerServiceHandler.java:166)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base/java.lang.Thread.run(Thread.java:833)
测试只有一步:
@Component
public class TestSteps {
private static final Configuration CONFIG = ConfigCache.getOrCreate(Configuration.class, System.getenv());
@Autowired
private HomePage homePage;
@Step("Open home page")
public void openHomePage() {
DriverManager.getInstance().deleteDriverCookies();
homePage = homePage.open();
assertThatPageIsOpened(homePage);
}
}
主页:
@Getter
@Component
public class HomePage extends BasePage implements Page {
private static final Configuration CONFIG = ConfigCache.getOrCreate(Configuration.class, System.getenv());
@FindBy(xpath = "//div[@id='layout']")
private HtmlElement homeLayout;
@Override
public boolean isAt() {
return awaitForElements(getTopHeaderBar(),
getLogoImage(),
getHomeLayout(),
getFooter()
);
}
@Override
public String getUrl() {
return "/";
}
public HomePage() {
HtmlElementLoader.populatePageObject(this, DriverManager.getInstance().getDriver());
}
public HomePage open() {
DriverManager.getInstance().navigateTo(CONFIG.getApplicationBaseUrl());
return new HomePage();
}
}
任何帮助将不胜感激 谢谢 :)
am trying to create a simple automated test to open a certain link in chrome, but I get this issue. I read previusly that I should annotate my clases with @Component, which I did but still can not access my link. Webdriver opens fine, but shortly after I recieve this issue:
Message: java.lang.NullPointerException: Cannot invoke
"com.automation_practice.pom.pages.homepage.HomePage.open()" because "this.homePage" is null
Stack Trace:
com.automation_practice.gauge.steps.TestSteps.openMyAccountPage(TestSteps.java:40)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:568)
com.thoughtworks.gauge.execution.MethodExecutor.execute(MethodExecutor.java:28)
com.thoughtworks.gauge.execution.StepExecutionStage.executeStepMethod(StepExecutionStage.java:66)
com.thoughtworks.gauge.execution.StepExecutionStage.executeStep(StepExecutionStage.java:59)
com.thoughtworks.gauge.execution.StepExecutionStage.execute(StepExecutionStage.java:41)
com.thoughtworks.gauge.execution.AbstractExecutionStage.executeNext(AbstractExecutionStage.java:14)
com.thoughtworks.gauge.execution.HookExecutionStage.execute(HookExecutionStage.java:33)
com.thoughtworks.gauge.execution.ExecutionPipeline.start(ExecutionPipeline.java:19)
com.thoughtworks.gauge.processor.ExecuteStepProcessor.process(ExecuteStepProcessor.java:41)
com.thoughtworks.gauge.RunnerServiceHandler.lambda$executeStep$7(RunnerServiceHandler.java:166)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base/java.lang.Thread.run(Thread.java:833)
The test has only one step:
@Component
public class TestSteps {
private static final Configuration CONFIG = ConfigCache.getOrCreate(Configuration.class, System.getenv());
@Autowired
private HomePage homePage;
@Step("Open home page")
public void openHomePage() {
DriverManager.getInstance().deleteDriverCookies();
homePage = homePage.open();
assertThatPageIsOpened(homePage);
}
}
HomePage:
@Getter
@Component
public class HomePage extends BasePage implements Page {
private static final Configuration CONFIG = ConfigCache.getOrCreate(Configuration.class, System.getenv());
@FindBy(xpath = "//div[@id='layout']")
private HtmlElement homeLayout;
@Override
public boolean isAt() {
return awaitForElements(getTopHeaderBar(),
getLogoImage(),
getHomeLayout(),
getFooter()
);
}
@Override
public String getUrl() {
return "/";
}
public HomePage() {
HtmlElementLoader.populatePageObject(this, DriverManager.getInstance().getDriver());
}
public HomePage open() {
DriverManager.getInstance().navigateTo(CONFIG.getApplicationBaseUrl());
return new HomePage();
}
}
Any help would be appreciated
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论