我对任何类型的编程都是一个绝对的初学者,目前我正在为我参加的一门课程做期末项目.

然而,我被困在了我的一个台阶上.无论我做什么,我都会得到"未定义的步骤".现在,互联网将我指向黄瓜选项中的gulp ,但我确信我已经指定了包装,我所有的其他步骤都工作得很好,如果gulp 粘得不好,所有步骤都没有定义,就像我之前发现的那样.

所以,在我的情况下,这一个单一的步骤一直是不确定的,我就是想不出来.

以下是我的步骤定义

package Mystore;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.UndefinedDataTableTypeException;
import io.cucumber.java.en.And;
import io.cucumber.java.AfterAll;
import io.cucumber.java.BeforeAll;
import io.cucumber.java.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class StepDefinition {

    private static WebDriver driver;

    @Before
    public void setup() {
        driver = new ChromeDriver();
    }

    //@AfterAll
    //public static void teardown() {
       // driver.quit();
    //}

    @Given("User is logged in")
    public void user_is_logged_in() {
        driver.get("https://mystore-testlab.coderslab.pl/index.php");

        WebElement element;
        element = driver.findElement(By.className("user-info"));
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        element.click();
        WebElement email = driver.findElement(By.id("field-email"));
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        email.click();
        email.sendKeys("gkqvuzdwzxoltwlnij@ckptr.com");
        driver.findElement(By.id("field-password")).sendKeys("qwerty1");
        WebElement sign = driver.findElement(By.id("submit-login"));
        sign.click();

    }
    @When("add address is clicked")
    public void add_address_is_clicked() {

        WebElement address;
        address = driver.findElement(By.xpath("//*[@id=\"footer_account_list\"]/li[4]/a"));
        address.click();
        WebElement clkaddress;
        clkaddress = driver.findElement(By.xpath("//*[@id=\"content\"]/div[2]/a"));
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        clkaddress.click();
    }
    @Then("fill in credentials with <alias>")
    public void fill_in_credentials_with(String alias){

        driver.findElement(By.className("col-md-6")).sendKeys(alias);
        //alias.sendKeys(Userdata.cell(1,1));
    }
    @And("submit and close the page")
        public void ubmit_and_close_the_page() {
            driver.quit();
    }
}

我的特色

Feature: Create address on mystore

  Scenario Outline: Test filling in address
    Given User is logged in
    When add address is clicked
    Then fill in credentials with <alias>
    And submit and close the page

    Examples:
      | alias | address  | city     | zip    | country | phone     |
      | RWT   | Lubelska | Warszawa | 01-999 | Poland  | 498100234 |

我的 run 者

package Mystore;

import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

//glue = {"helpers", "src.test.java.steps"},
@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/Resources/Mystore/Userdata.feature",
        glue = {"Mystore"},
        snippets = CucumberOptions.SnippetType.CAMELCASE,
        plugin = {"pretty"}
)
        //format = {"pretty"})

public final class RunCucumberTest {

}

我的POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.zaliczenie</groupId>
    <artifactId>zaliczenie</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>20</maven.compiler.source>
        <maven.compiler.target>20</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.14.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>4.13.0</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>22.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.0.0</version>
        </dependency>

    </dependencies>

</project>

误差率

io.cucumber.junit.UndefinedStepException: The step 'fill in credentials with RWT' is undefined.
You can implement this step using the snippet(s) below:

@Then("fill in credentials with RWT")
public void fillInCredentialsWithRWT() {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

我已经看过gulp 了,应该没问题.我确实确保了我的依赖项不会过时或彼此不兼容.我try 了几种不同的方法.

文件 struct 如下所示

enter image description here

推荐答案

在您的场景中,您有一个步骤:

Then fill in credentials with <alias>

因为这是场景大纲中的一个步骤,所以<alias>将替换为您的示例的值.

Examples:
      | alias | address  | city     | zip    | country | phone     |
      | RWT   | Lubelska | Warszawa | 01-999 | Poland  | 498100234 |

所以你的脚步就是现在

Then fill in credentials with RWT

这与您的步骤定义不匹配.在这里,鱼括号被视为常规文本.

@Then("fill in credentials with <alias>")

这就是为什么黄瓜建议:

@Then("fill in credentials with RWT")

您可以将您的步长更改为

Then fill in credentials with "<alias>"

以及您的步骤定义为

@Then("fill in credentials with {string}")

那么两个人都会匹配.

此外,通过在步骤中添加引号,Cucumber将建议参数化的步骤定义.

顺便说一句,您不需要gherkin依赖项.它是一种可传递的依赖关系,并自动包括在内.

Java相关问答推荐

那么比较似乎不是词典学的,尽管doctor 这么说

为什么我的画布没有显示在PFA应用程序中?

Java事件系统通用转换为有界通配符

同时运行JUnit测试和Selenium/Cucumber测试时出现问题

使用标记时,场景大纲不在多个线程上运行

Com.example.service.QuestionService中的构造函数的参数0需要找不到的类型为';com.example.Dao.QuestionDao;的Bean

GSON期间的Java类型擦除

如何从JNI方法正确调用NSOpenPanel以在正确的线程上运行?

Mac上的全屏截图在使用JavaFX时不能正常工作吗?

内存和硬盘中的Zip不同,这会导致下载后的Zip损坏

Java.lang.invke.LambdaConversionException:实例方法InvokeVirtual的参数数量不正确

根本不显示JavaFX阿拉伯字母

try 使用类来包含JSON响应

在Oracle db中,当我们提供字符串而不是数字时,比较是如何工作的?

本机方法(JNI)总是编译的吗?

如何设置默认序列生成器分配大小

如何使用外部函数从Java中获取C++ struct 的返回值&;内存API

如何通过gradle命令行从build.gradle获得Java targetCompatibility

java21预览未命名的符号用于try-with-resources

具有 DayOfWeek 列表的 JPA 实体