Getting Null pointer Exception while running cucumber test with selenium webdriver in java

تعرفه تبلیغات در سایت

آرشیو مطالب

امکانات وب

Vote count: 0

This is Class with cucumber annotations

public class EndtoEndTest {

WebDriver driver;
//private ConfigFileReader cnffilered;
//private CartPage cartpage;
//private Checkoutpage checkoutpage;
//private ProductListingPage productlistingpage;


@Given("^User is on Homepage$")
public void user_is_on_Homepage() throws Throwable {


    ConfigFileReader cnffilered= new ConfigFileReader();
    cnffilered.getBrowserType();
    cnffilered.getUrl();
    cnffilered.Implicitwait();
    cnffilered.MaxmimizeWindow();

}

@When("^he searches for "([^"]*)"$")
public void he_searches_for(String arg1) throws Throwable 
{

        HomePage homepage = new HomePage(driver);
        homepage.perform_Search(arg1);

}
}

This is the class with FageFactory Initialization

public class HomePage {

 WebDriver driver;

public HomePage(WebDriver driver) {
    this.driver = driver;
    PageFactory.initElements(driver, this);
}

@FindBy(how=How.XPATH, using="//a[@class='noo-search icon_search']")
private WebElement click_on_search_icon;

@FindBy(how = How.XPATH, using="//input[@class='form-control']")
private WebElement enter_data_for_search;

public void perform_Search(String search) {

    click_on_search_icon.click();
    enter_data_for_search.sendKeys(search);
    enter_data_for_search.sendKeys(Keys.ENTER);

}

public void navigateTo_HomePage() {

    driver.get("http://www.shop.demoqa.com");
}

}

While executing i am getting Null Pointer Exception

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.$Proxy13.click(Unknown Source)
at pageObjects.HomePage.perform_Search(HomePage.java:27)
at stepDefinations.EndtoEndTest.he_searches_for(EndtoEndTest.java:42)
at ✽.When he searches for "dress"(src/test/resources/functionalTest/EndtoEndTest.feature:9)

I have understand one thing that may be driver instance is getting null, but what may be the solution for that, Any help?? thanks in Advance.

asked 37 secs ago
Ab123

نویسنده : استخدام کار بازدید : 0 تاريخ : پنجشنبه 23 فروردين 1397 ساعت: 1:14
برچسب‌ها :

خبرنامه

عضویت

نام کاربري :
رمز عبور :