Cucumber 我试图在步骤定义文件中传递该值,但得到的错误为

Cucumber 我试图在步骤定义文件中传递该值,但得到的错误为,cucumber,Cucumber,我的页面文件 公共类LoginPageFile扩展了testBase{ JavascriptExecutor js; @FindBy(xpath = "//input[@type='text']") WebElement un; @FindBy(xpath = "//input[@type='password']") WebElement pwd; @FindBy(xpath = "//input[@name='btnLogin']&quo

我的页面文件

公共类LoginPageFile扩展了testBase{

JavascriptExecutor js;

@FindBy(xpath = "//input[@type='text']")
WebElement un;

@FindBy(xpath = "//input[@type='password']")
WebElement pwd;

@FindBy(xpath = "//input[@name='btnLogin']")
WebElement li;

@FindBy(xpath = "//td[text()='Manger Id : mngr319174']")
WebElement head;

public LoginPageFile() {
    
    PageFactory.initElements(driver,this);
}

public void enterUsername(String username) {

    un.sendKeys(username);
    
}
public void enterPassword(String password) {

    pwd.sendKeys(password);
}

public void ClicklogIn() {
    li.click();
}
我的页面定义文件。。 公共类LogInStepDefinition扩展了testBase {

错误是

功能:Guru99登录功能

场景:登录测试场景#/C:/Users/aziz-rahman/eclipse-workspace/SampleTest/src/main/java/Features/Login.feature:3 给定用户打开登录页面#LogInStepDefinition.user_open_login_page() 当登录页面的标题为Guru#LogInStepDefinition时,_login_页面的标题为_Guru() 然后输入用户名和密码#LogInStepDefinition。输入用户名和密码() java.lang.NullPointerException:无法调用“org.openqa.selenium.SearchContext.findElement(org.openqa.selenium.By)”,因为“this.SearchContext”为null 位于org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) 位于org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38) 位于jdk.proxy2/jdk.proxy2.$Proxy16.sendKeys(未知源) 位于pageFile.LoginPageFile.enterUsername(LoginPageFile.java:33) 在StepDefinition.LogInStepDefinition.输入用户名和密码(LogInStepDefinition.java:33) 在✽.输入用户名和密码(文件:/C:/Users/aziz%20rahman/eclipse workspace/SampleTest/src/main/java/Features/login.feature:7)

失败的场景: /C:/Users/aziz-rahman/eclipse-workspace/SampleTest/src/main/java/Features/login.feature:3#登录测试场景

1个场景(1个失败) 5个步骤(1个失败,2个跳过,2个通过) 0m2.846s

java.lang.NullPointerException:无法调用“org.openqa.selenium.SearchContext.findElement(org.openqa.selenium.By)”,因为“this.SearchContext”为null 位于org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) 位于org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38) 位于jdk.proxy2/jdk.proxy2.$Proxy16.sendKeys(未知源) 位于pageFile.LoginPageFile.enterUsername(LoginPageFile.java:33) 在StepDefinition.LogInStepDefinition.输入用户名和密码(LogInStepDefinition.java:33) 在✽.输入用户名和密码(文件:/C:/Users/aziz%20rahman/eclipse workspace/SampleTest/src/main/java/Features/login.feature:7)

LoginPageFile login=new LoginPageFile();


@Given("^user open login page$")
public void user_open_login_page()  {
    testBase.initialization();
}
@When("title of login page is Guru")
public void title_of_login_page_is_Guru() {
    driver.get(prop.getProperty("url"));
}


@Then("^enter the username and password$")
public void enter_the_username_and_password(){
  
    login.enterUsername(prop.getProperty("username"));
    login.enterPassword(prop.getProperty("password"));
}

@Then("^click on login button$")
public void click_on_login_button() {
   login.ClicklogIn();
}
Then click on login button           # LogInStepDefinition.click_on_login_button()
Then user is on home page            # LogInStepDefinition.user_is_on_home_page()