当我运行代码时,我会得到java.lang.NullPointerException如何修复它

时间:2018-12-04 17:40:54

标签: java cucumber

这是代码

public WebDriver driver;
@FindBy(xpath="//*[@class='btn btn-primary m-t-15 waves-efassociatesave']")
public WebElement addEmployee;
public Employee(WebDriver x)
{
    this.driver=x;
    PageFactory.initElements(driver, this);
}
public void fillEmployeeName(String x)
{
    ExplicitWaitMethods.waitForVisibility(employeeName);
    inputObj.enterText(employeeName, x);
}

我叫这种方法

public class TestImpl implements Test{

WebDriver driver;
Employee e=new Employee(driver);

public TestImpl(WebDriver x)
{
    this.driver=x;
    PageFactory.initElements(driver, this);
}
@Override
public void addEmployee() {
    // TODO Auto-generated method stub
    e.addEmployee.click();
    e.fillEmployeeName("vishal");
}

}

在逐步定义中调用此方法

@Then("^get data$")
public void getData()
{
    //employee.getEmployeeName();
    t.addEmployee();

}

错误消息:     java.lang.NullPointerException     在  org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)     在org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:37)     在com.sun.proxy。$ Proxy12.click(未知来源)     在pages.TestImpl.addEmployee(TestImpl.java:19)     在stepDefintions.PredefinedStepDefinitions.getData(PredefinedStepDefinitions.java:315)     在✽。然后获取数据(E:/eclipse/erp/src/test/resources/features/login.feature:48)

然后出现nullpointer异常。 谁能帮我解决这个问题

0 个答案:

没有答案