I get java.lang.NullPointerException when I try use method getClickOnHotelTab()
The method getClickOnHotelPage is on the page SearchHotelPage. When I try use this method on SearchHotelStep I got java.lang.NullPointerException.
This is my SearchHotelPage:
public class SearchHotelPage {
public WebDriver driver;
private By clickOnHotelTab = By.xpath("//*[@id='PageNavBarSectionList']//a[@title='Hotéis']");
private By destinyClick1 = By.xpath("(//div[@role='button']/span)[3]");
private By destinyClick2 = By.xpath("//input[@placeholder='Destino ou nome do hotel']");
public SearchHotelPage(WebDriver driver) {
this.driver = driver;
}
public WebElement getDestinyClick1() {
return driver.findElement(destinyClick1);
}
public WebElement getDestinyClick2() {
return driver.findElement(destinyClick2);
}
public WebElement getClickOnHotelTab() {
return driver.findElement(clickOnHotelTab);
}
This is my SearchHotelStep:
@RunWith(Cucumber.class)
public class SearchHotelStep extends BasePage {
public WebDriver driver;
@When("^Choose destiny or hotel name$")
public void choose_destiny_or_hotel_name() throws Throwable {
SearchHotelPage destinyClick = new SearchHotelPage(driver);
destinyClick.getClickOnHotelTab().click();
//destinyClick.getDestinyClick1();
//destinyClick.getDestinyClick2().sendKeys("cancun");
//destinyClick.getDestinyClick2().click();
}
This is the output:
Scenario: Search Hotel With Travel Insurance # SearchHotelWithTravelInsurance.feature:3
Given The browser is initialized #
SearchAirTicketsStep.the_browser_is_initialized()
When User go to "https://www.turismocity.com.br/" site # SearchAirTicketsStep.user_go_to_site(String)
And Choose destiny or hotel name #
SearchHotelStep.choose_destiny_or_hotel_name()
java.lang.NullPointerException
at pages.SearchHotelPage.getClickOnHotelTab(SearchHotelPage.java:28)
at steps.SearchHotelStep.choose_destiny_or_hotel_name(SearchHotelStep.java:22)
at ?.And Choose destiny or hotel name(SearchHotelWithTravelInsurance.feature:6)
And Choose round trip date #
SearchAirTicketsStep.choose_round_trip_date()
And Choose quantity of guests # SearchHotelStep.choose_quantity_of_guests()
When Click on search button from hotels search #
SearchHotelStep.click_on_search_button_from_hotels_search()
Then The options of hotel are shown #
SearchHotelStep.the_options_of_hotel_are_shown()
Then The page of travel insurance is open #
SearchHotelStep.the_page_of_travel_insurance_is_open()
Then The browser is closed # SearchAirTicketsStep.the_browser_is_closed()
Failed scenarios:
SearchHotelWithTravelInsurance.feature:3 # Scenario: Search Hotel With Travel Insurance
1 Scenarios (1 failed)
9 Steps (1 failed, 6 skipped, 2 passed)
0m9,057s
java.lang.NullPointerException
at pages.SearchHotelPage.getClickOnHotelTab(SearchHotelPage.java:28)
at steps.SearchHotelStep.choose_destiny_or_hotel_name(SearchHotelStep.java:22)
at ?.And Choose destiny or hotel name(SearchHotelWithTravelInsurance.feature:6)
Can you help me, please ?