首页 > 解决方案 > 即使在实施之后,您也可以使用控制台中显示的以下片段来实施缺少的步骤

问题描述

我创建了三个文件 .feature 文件,stepDefinition.java 和 testRunner.java。当我尝试运行 testRunner 类时,它会继续在控制台中显示建议,例如您可以使用以下代码片段实现缺少的步骤:使用功能文件中的步骤。具有讽刺意味的是,我已经在 stepDefinition 中实现了所有步骤。谁能帮我这个?

登录功能

Feature: Amazon login feature
Scenario: Valid and invalid test cases
Given user already in login page
When user enters username 
Then user enters password
Then user click login page

步骤定义.java

package stepDefinition;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class stepdefinitions {
    WebDriver driver=new ChromeDriver();
    @Given("^user already in login page$")
    public void user_already_in_login_page() throws Exception {
        System.setProperty("webdriver.chrome.driver","D:\\MuthuKumar\\Documents\\chromedriver.exe");
        driver.get("https://www.amazon.in/");       
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.id("nav-link-accountList"))).click(driver.findElement(By.xpath("//span[text()='Sign in']"))).build().perform();

    }
    @When("^user enters username$")
    public void user_enters_username() throws Exception {
        driver.findElement(By.id("ap_email")).sendKeys("8526606990");
        driver.findElement(By.id("continue")).click();
    }

    @Then("^user enters password$")
    public void user_enters_password() throws Exception {
        driver.findElement(By.id("ap_password")).sendKeys("sample");
    }

    @Then("^user click login page$")
    public void user_click_login_page() throws Exception {
        driver.findElement(By.id("signInSubmit")).click();
    }
}

testRunners.java

package testRunner;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\feature"},glue= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\stepDefinition"})
public class testRunners {

}

控制台消息

You can implement missing steps with the snippets below:

@Given("^user already in login page$")
public void user_already_in_login_page() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^user enters username$")
public void user_enters_username() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^user enters password$")
public void user_enters_password() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^user click login page$")
public void user_click_login_page() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

标签: javaseleniumcucumber

解决方案


与其给出胶水路径,不如给出你的包名。它工作正常

testRunners.java

package testRunner;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\feature"}
,glue= {"stepDefinition"})
public class testRunners {

}

推荐阅读