如何使用io.cucumber运行黄瓜jvm报告

时间:2019-10-15 08:16:43

标签: selenium-webdriver cucumber

我在下面用io.cucumber .my Pom更新了我的POM.xml:

console.log('Post to ' + url + ' user:' + data.user + ' password:' + data.password); // both the URL and the data are correct
$.post(url, data, function(res) {
    // This code is not reached
    if (res.id !== undefined && res.token) {
        console.log('Login OK');
        // store user data...
        return;
    }
    if (res.error) {
        // alert the validation error
        return;
    }
    alert('Unexpected server error');
}).fail(function(jqXHR, textStatus, errorThrown) {
    console.log('Login error: ' + textStatus + ' ' + errorThrown);
    // show error in login form...
});

和我的跑步者班使用以下代码

    <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>ToolsQA</groupId>
        <artifactId>CucumberFramework</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>CucumberFramework</name>
        <url>http://maven.apache.org</url>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>

        <dependencies>
        <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.3.1</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.3.1</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/junit/junit
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>   -->
    <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.14.0</version>
            </dependency>

            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.8</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>4.2.0</version>
    </dependency>
     <dependency>
                    <groupId>io.cucumber</groupId>
                    <artifactId>cucumber-picocontainer</artifactId>
                    <version>4.3.1</version>
                    <scope>test</scope>
                </dependency>

            <dependency>
                    <groupId>io.cucumber</groupId>
                    <artifactId>cucumber-jvm-deps</artifactId>
                    <version>1.0.6</version>
                    <scope>provided</scope>
                </dependency>
        <!--    <dependency>
                <groupId>com.aventstack</groupId>
                <artifactId>extentreports</artifactId>
                <version>3.1.2</version>
            </dependency>  -->
            <dependency>
                <groupId>com.vimalselvam</groupId>
                <artifactId>cucumber-extentsreport</artifactId>
                <version>3.0.2</version>
            </dependency>
            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-io</artifactId>
                <version>1.3.2</version>
            </dependency>


    <!-- https://mvnrepository.com/artifact/io.cucumber/datatable-dependencies -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>datatable-dependencies</artifactId>
        <version>1.1.12</version>
    </dependency>

    <!--  https://mvnrepository.com/artifact/io.cucumber/datatable-->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>datatable</artifactId>
        <version>1.0.3</version>
    </dependency>

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

    <!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
    <!--<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>gherkin</artifactId>
        <version>5.1.0</version>
    </dependency>  -->
     <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-html</artifactId>
        <version>0.2.7</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.7.3</version>
    </dependency>
    <dependency>
      <groupId>com.aventstack</groupId>
    <artifactId>extentreports-cucumber4-adapter</artifactId>
    <version>1.0.7</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.1.5</version>
    </dependency> 
        </dependencies>

        <build>
        <plugins>
        <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <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>3.15.0</version>
                            <executions>
                                <execution>
                                    <id>execution</id>
                                    <phase>verify</phase>
                                    <goals>
                                        <goal>generate</goal>
                                    </goals>
                                    <configuration>
                                        <projectName>cucumber-jvm-example</projectName>
                                        <outputDirectory>${project.build.directory}/Cucumber-JVM-report</outputDirectory>
                                        <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                                         <!-- <inputDirectory>${project.build.directory}/cucumber-reports/cucumber-json</inputDirectory> -->
                                        <jsonFiles>
                        <!-- supports wildcard or name pattern -->
                        <param>**/*.json</param>
                    </jsonFiles>
                    <skippedFails>true</skippedFails>
                    <enableFlashCharts>true</enableFlashCharts>
                    <buildNumber>10.2.1</buildNumber>
                                        <checkBuildResult>true</checkBuildResult>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>

    </project>

出现以下控制台错误

package testRunner;

import org.junit.runner.RunWith;



import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import cucumber.api.CucumberOptions;
import cucumber.api.Scenario;
//import cucumber.api.java.Before;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.PickleEventWrapper;
//import cucumber.api.testng.PickleEventWrapper;
import cucumber.api.testng.TestNGCucumberRunner;
import com.aventstack.extentreports.ExtentTest;
import com.cucumber.listener.Reporter;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {
        "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:target/cucumber-reports/report.html","html:target/Cucumber-JVM-report","json:target/cucumber-reports/cucumber.json"}, features = "src/test/java/Features", monochrome = true, tags = {
                "@US_IEITF-6646_AttachDocAndPreviewandSubmit,@US_IEITF-6441_Exit" }, glue = "stepDef", strict = true)
public class TestRunner {
//extends AbstractTestNGCucumberTestsests 
    public static WebDriver driver;
    private TestNGCucumberRunner testRunner;
    public ExtentTest log = null;
    private Scenario scenario;

//  @BeforeClass
//  public void before(Scenario scenario) {
//        this.scenario = scenario;
//  }

    /*@BeforeClass
    public void setUP() {
        System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
        testRunner = new TestNGCucumberRunner(TestRunner.class);

    }
    */
    @BeforeClass(alwaysRun = true)
    public void precondition() {
        System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
        testRunner = new TestNGCucumberRunner(this.getClass());

    }


    /*@Test(description = "login", dataProvider = "features")
    public void login(CucumberFeatureWrapper cFeature) {
        testRunner.runCucumber(cFeature.getCucumberFeature());

    }
    */
    @Test(groups = "cucumber scenarios", description = "login", dataProvider = "scenarios")
            public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper 
            cucumberFeature) throws Throwable{
        testRunner.runScenario(pickleEvent.getPickleEvent());
            }
    /*@DataProvider(name = "features")
    public Object[][] getFeatures() {
        return testRunner.provideFeatures();
    }*/

    @DataProvider(name = "scenarios")
    public Object[][] scenarios() {
        return testRunner.provideScenarios();
    }


    /*@AfterClass
    public void tearDown() {

        testRunner.finish();

        Reporter.loadXMLConfig("./extent-config.xml");
        Reporter.setSystemInfo("User Name", System.getProperty("user.name"));
        Reporter.setSystemInfo("Time Zone", System.getProperty("user.timezone"));
        Reporter.setSystemInfo("Machine", "Windows 10" + "64 Bit");
        Reporter.setSystemInfo("Selenium", "3.7.0");
        Reporter.setSystemInfo("Maven", "3.5.2");
        Reporter.setSystemInfo("Java Version", "1.8.0_151");
    }*/
    @AfterClass(alwaysRun = true)
    public void tearDownClass() throws Exception {
        testRunner.finish();
        Reporter.loadXMLConfig("./extent-config.xml");
        Reporter.setSystemInfo("User Name", System.getProperty("user.name"));
        Reporter.setSystemInfo("Time Zone", System.getProperty("user.timezone"));
        Reporter.setSystemInfo("Machine", "Windows 10" + "64 Bit");
        Reporter.setSystemInfo("Selenium", "3.7.0");
        Reporter.setSystemInfo("Maven", "3.5.2");
        Reporter.setSystemInfo("Java Version", "1.8.0_151");
    }
}

还让我如何从Runner运行此Run as- TestNG套件或通过POM.xml以Maven安装运行 我想用io.cucumber更新我的项目,然后运行测试运行器来生成表格表格报告 我不想在运行报告时使用POM.xml,而是希望使用TestNG 请帮助

1 个答案:

答案 0 :(得分:0)

此错误通常是由于黄瓜依赖项冲突而导致的。

  1. 使用相同版本的Cucumber依赖项。 这意味着更新以下内容:

        黄瓜     黄瓜test      4.2.0

要在其他地方使用的4.3.1版本。

  1. 此外,您正在导入几个应作为那些Cucumber依赖项的传递依赖项进行管理的依赖项。

请删除以下内容:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>provided</scope>
</dependency>

             黄瓜         数据表依赖性         1.1.12     

<!--  https://mvnrepository.com/artifact/io.cucumber/datatable-->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>datatable</artifactId>
    <version>1.0.3</version>
</dependency>

        黄瓜         黄瓜芯         4.3.1     

<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<!--<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>gherkin</artifactId>
    <version>5.1.0</version>
</dependency>  -->
 <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-html</artifactId>
    <version>0.2.7</version>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>gherkin</artifactId>
    <version>2.7.3</version>
</dependency>

一些其他提示: *为了确保在升级时也使用相同版本的Cucumber,请添加以下内容:              4.3.1     

,并对所有Cucumber依赖项使用<version>${cucumber.version}</version>。 *版本4.3.1不再是最新的;我认为最新的是4.8.0(如果要升级) *使用TestNg或JUnit(并删除另一个)。 *通常,不要在项目中保留注释掉的代码/配置。那就是版本控制的目的:)