空手道中未为功能文件生成黄瓜报告 [英] Cucumber report is not getting generated for feature file in karate
问题描述
我已经按照空手道文档使用以下Java代码和pom来生成黄瓜报告,但是我无法按预期获取黄瓜报告:
I have used the following java code and pom for generating cucumber reports as per the Karate documents but i am not able to get cucumber reports as expected:
在Java类文件中:
package Mav_demo.RunnerFunction;
//import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
import com.intuit.karate.cucumber.CucumberRunner;
import com.intuit.karate.cucumber.KarateStats;
//import org.junit.runner.RunWith;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.apache.commons.io.FileUtils;
//import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
//@RunWith(Karate.class)
//@CucumberOptions(features =
"classpath:src/test/java/Mav_demo/RunnerFunction/gapi_mulscn.feature")
@CucumberOptions(tags = "~@ignore")
public class Looping{
@Test
public void testParallel() {
String karateOutputPath = "target/surefire-reports";
KarateStats stats = CucumberRunner.parallel(getClass(), 5, karateOutputPath);
generateReport(karateOutputPath);
assertTrue("there are scenario failures", stats.getFailCount() == 0);
}
private static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
List<String> jsonPaths = new ArrayList<String>(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "demo");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
在Pom.xml文件中
In Pom.xml file
<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>Mav_Demo.RunnerFunction</groupId>
<artifactId>RunnerFunction</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.version>3.6.0</maven.compiler.version>
<junit.version>4.12</junit.version>
<cucumber.version>1.2.5</cucumber.version>
<selenium.version>2.53.0</selenium.version>
<maven.compiler.version>3.3</maven.compiler.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>0.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<includes>
<include>Mav_demo.RunnerFunction/ExamplesTest.java</include>
</includes>
<argLine>-Dfile.encoding=UTF-8</argLine>
<systemProperties>
<cucumber.options>--tags ~@ignore</cucumber.options>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
在功能文件中:
Feature: to print results
Scenario: looping the post method
Given url 'https://www.googleapis.com/geolocation/v1/geolocate'
And param key = 'AIzaSyB2jt4BQ9McqBXAe8dYcp1CwKf0oGFlWuc'
And request 'payload'
When method post
And print response
Then status 200
我正确地获得了肯定的举报.但是,不是黄瓜报告.请对此提供帮助.
I am getting sure-fire reports correctly. But, not the Cucumber report. Kindly please help on this.
非常感谢...
推荐答案
抱歉,没有人会阅读所有这些内容并弄清楚,因为这似乎是黄瓜,硒和其他物质的可怕混合物.
Sorry no-one is going to read all this and figure out since this seems to be a horrible mix of Cucumber, Selenium and what not.
请参阅此文档: https://stackoverflow.com/help/mcve
无论如何,这是我的建议.使用Maven快速入门(或原型)创建一个新项目: https://github.com/intuit/karate #quickstart
Anyway, here is what I suggest. Create a fresh project using the Maven quickstart (or archetype): https://github.com/intuit/karate#quickstart
然后获取该项目中的并行报告.请参阅 https://github.com/intuit/karate/tree/master/karate-demo#example-report -请注意,您似乎正在使用黄瓜报告工件的其他版本.
Then get the parallel reports working in that project. Refer to https://github.com/intuit/karate/tree/master/karate-demo#example-report - and note that you seem to be using a different version of the cucumber-reporting artifact.
一旦完成工作,并清楚地知道该怎么做,然后尝试将所有这些都放入您现有的(旧)项目中.一切顺利.
Once you have that working and understand clearly what to do - then try to put all this into your existing (old) project. All the best.
这篇关于空手道中未为功能文件生成黄瓜报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!