Maven没有运行测试,但显示了BUILD SUCCESS

时间:2019-11-24 06:45:27

标签: maven selenium

我尝试使用Maven运行测试,但未运行测试。

该测试在TestNG中成功运行,并且没有错误。我试图将Maven surefire更新到2.22.0,但无济于事。

感谢任何提示!

POM.xml:

<?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>groupId</groupId>
    <artifactId>Cucumber</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
            <plugin>
                <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>2.8.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>ExecuteAutomation</projectName>
                            <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
                            <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.7.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>4.7.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.5</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.0.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>

行家:

C:\Users\Test\Documents\GitHub\Expedia>mvn clean verify
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< groupId:Cucumber >--------------------------
[INFO] Building Cucumber 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Cucumber ---
[INFO] Deleting C:\Users\Test\Documents\GitHub\Expedia\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Cucumber ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Cucumber ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Test\Documents\GitHub\Expedia\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Cucumber ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Test\Documents\GitHub\Expedia\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ Cucumber ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to C:\Users\Test\Documents\GitHub\Expedia\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ Cucumber ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ Cucumber ---
[INFO] Building jar: C:\Users\Izuan\Documents\GitHub\Expedia\target\Cucumber-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-cucumber-reporting:2.8.0:generate (execution) @ Cucumber ---
[WARNING] C:\Users\Test\Documents\GitHub\Expedia\target\cucumber.json does not exist.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.159 s
[INFO] Finished at: 2019-11-24T14:22:41+08:00
[INFO] ------------------------------------------------------------------------

我有另一个项目,代码几乎相同,并且可以从Maven运行。我不确定这里出了什么问题。

searchStep.class


import cucumber.api.DataTable;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

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

public class searchStep {
    public static WebDriver driver;

    @Given("I navigate to Expedia website")
    public void iNavigateToExpediaWebsite() {
        System.out.println("Opening the Expedia website");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://www.expedia.com.my/");
    }

    @And("I enter the destination")
    public void iEnterTheDestination(DataTable destination) {
        System.out.println("Input the destination");
        List<List<String>> data = destination.raw();
        driver.findElement(By.xpath("/html//input[@id='hotel-destination-hp-hotel']")).sendKeys(data.get(1).get(0));
    }

    @And("I input the checkin date")
    public void iInputTheCheckinDate() {
        System.out.println("Input the check-in date");
        WebElement checkindate = driver.findElement(By.xpath("/html//input[@id='hotel-checkin-hp-hotel']"));
        checkindate.sendKeys("19/01/2020");
    }

    @And("I input the check out date")
    public void iInputTheCheckOutDate() {
        System.out.println("Input the check-out date");
        WebElement checkoutdate = driver.findElement(By.xpath("/html//input[@id='hotel-checkout-hp-hotel']"));
        checkoutdate.sendKeys("26/01/2020");
    }

    @And("I click on the Search button")
    public void iClickOnTheSearchButton() {
        System.out.println("Click on the Search button");
        WebElement clickSearch = driver.findElement(By.xpath("/html//form[@id='gcw-hotel-form-hp-hotel']//button[@type='submit']"));
        clickSearch.click();
    }

    @Then("I should see the search result")
    public void iShouldSeeTheSearchResult() {
        System.out.println("The search result is shown");
    }
}

运行程序文件:


import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(features = {"src/test/java/Search"},
        plugin = {"pretty","json:target/cucumber.json","html:target/site/cucumber-pretty"},
        glue = "Step")

public class RunnerOne extends AbstractTestNGCucumberTests {

}

1 个答案:

答案 0 :(得分:0)

在配置中将Runnerclass包含在surefire插件中

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                            <includes>
                                <include>**/RunnerOne.java</include>
                            </includes> 
                            <testFailureIgnore>true</testFailureIgnore>
                        </configuration>
        </plugin>