I get null point exception when it executes second(When) step, which means it does nt get proper page object handle
The Home page object created in Given step of Navigation needs to be passed to be when step of AddRecordStepdefs, so that
home page methods like homepage.getCurrentNoOfIteminHomePage and homepage.clickAddButton(): needs to be invoked
But for some the reason, the home page created is not passed and it gives nullpoint exception
How to pass the same home page created in Given Step of NavigationStepsStepdefs to When step of AddRecordStepdefs
Here is my code :
Navigation steps
public class NavigationStepsStepdefs {
private WebDriver driver;
private HomePage homepage;
public NavigationStepsStepdefs(SharedDriver driver){
this.driver=driver;
}
@Given("^I am on the Home page$")
public void i_am_on_the_Home_page() throws Throwable {
homepage = new HomePage(driver);
homepage.openURL("http://");
}
}
AddRecordStepdefs
public class AddRecordStepdefs {
private WebDriver driver;
private HomePage homepage;
private int count;
public AddRecordStepdefs(SharedDriver driver){
this.driver=driver;
}
@When("^I click the add items in the home page$")
public void i_click_the_add_tems_in_the_home_page(){
count = homepage.getCurrentNoOfIteminHomePage();
homepage.clickAddButton():
}
@Then("^the added item should be added to the list$")
public void the_added_item_should_be_added_to_the_list() {
assertTrue(count + 1 == homepage.getCurrentNoOfIteminHomePage());
}
}
This is Home Page class
public class HomePage extends AbstractPageObject {
private WebDriver driver;
public HomePage(WebDriver driver) {
super(driver);
this.driver = driver;
}
public void openURL(String url){
driver.get(url);
}
public void clickAddButton() {
WebElement addButton = getButtoninthePageBy(By.cssSelector(""));
addButton.click():
}
public int getCurrentNoOfIteminHomePage() {
int couunt =0
/// write the code to get current items in the home page
return count
}
}