1 year ago
#367818
Dinu Donoaga
Cannot invoke because "this." is null
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 :)
spring
automation
nullpointerexception
0 Answers
Your Answer