maven junit 5,不运行测试

7tofc5zh  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(330)

在执行我的runner或运行我的.feature文件时,不会通过cucumber运行任何测试(与mvn clean install、mvn clean test等相同)。我的程序的其余部分完全按照预期运行,这是一个我已经为之苦恼了一段时间的问题。
运行runner类时intellij ide的结果:

文件夹结构:

我的完整pom如下所示:

<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>IE2ETest</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <junit-jupiter.version>5.7.2</junit-jupiter.version>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <cucumber.version>6.10.4</cucumber.version>
    <selenium-jupiter.version>3.4.0</selenium-jupiter.version>

    <java.version>1.8</java.version>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <maven.compiler.source>${java.version}</maven.compiler.source>

    <project.enconding>UTF-8</project.enconding>
    <project.build.sourceEncoding>${project.enconding}</project.build.sourceEncoding>
    <project.reporting.outputEncoding>${project.enconding}</project.reporting.outputEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit-jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit-platform-engine</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>selenium-jupiter</artifactId>
        <version>${selenium-jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
            <configuration>
                <properties>
                    <configurationParameters>
                        cucumber.plugin=pretty,html:target/site/cucumber-pretty.html
                        cucumber.publish.quiet=true
                        cucumber.publish.enabled=false
                    </configurationParameters>
                </properties>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>
    </plugins>
</build>

runnertest.java:

package cucumberTests;

import io.cucumber.junit.platform.engine.Cucumber;

@Cucumber
public class RunnerTest {

}

stepdefinitions.java:

package cucumberTests.steps;

import helperpackage.Car;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pomPages.CarTaxHomePage;
import pomPages.FreeCheckPage;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class StepDefinitions {
        String drivePath = "./src/test/drivers/chromedriver.exe";
        String currentUrl;
        WebDriver driver;
        CarTaxHomePage homePage;
        FreeCheckPage freePage;

        @Given("Valid Registration value of {string}")
        public void checkReg(String reg){
            assertTrue(Car.isValid(reg));
        }

        @When("the website {string} is live")
        public void openSite(String url) throws IOException {
            System.setProperty("webdriver.chrome.driver", drivePath);
            driver = new ChromeDriver();
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
            driver.get("https://"+url+"/");
        }

        @And("user enters value of {string}")
        public void enterText(String reg) throws InterruptedException {
            homePage = new CarTaxHomePage(driver);
            Thread.sleep(500);
            homePage.editText(reg);
        }

        @And("user clicks on the free option")
        public void clickSubmit(){
            homePage.clickFreeCheck();
        }

        @Then("user should be taken to the {string} page")
        public void checkPage(String url){
            freePage = new FreeCheckPage(driver);
            String currentUrl = driver.getCurrentUrl();
            String regex = "^(https:\\/\\/"+url +"\\/)";
            String x  = "^(https:\\/\\/" + url +  "?\\S+)";
            if (!currentUrl.matches(regex)){
                throw new IllegalArgumentException("Bad link");
            };
        }

        @And("Number plate {string} Should appear")
        public void checkResults(String plate, String make){
            String plateReturned = freePage.getRegReturned();
            String makeReturned = freePage.getMakeReturned();
            if (plateReturned.equals(plateReturned) && makeReturned.equals(make)){
                //
            }else{
                throw new IllegalArgumentException("Wrongfully returned");
            }
        }

    }

我的ide显示这些步骤是在另一个类中引用的,因为cucumber并不抱怨找到特性的路径,我现在不知所措。step.feature

Feature: Check tax on car
  Scenario : User enters a valid Reg number and clicks the free check option
    Given Valid Registration value of "LT09YJJ"
    When the website "check.co.uk" is live
    And user enters value of "9YJJ"
    And user clicks on the free option
    Then user should be taken to the "taxcheck.co.uk/hello" page
    And Number plate "9YJJ" Should appear

我的 cucumber

cucumber.publish.enabled=true

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题