Skip to content

Commit

Permalink
Merge pull request #131 from qase-tms/3.2.0
Browse files Browse the repository at this point in the history
3.2.0
  • Loading branch information
savkk committed Dec 6, 2023
2 parents ee4a980 + 9f50bd7 commit b80f172
Show file tree
Hide file tree
Showing 34 changed files with 569 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -7,7 +7,7 @@
<groupId>io.qase</groupId>
<artifactId>qase-java</artifactId>
<packaging>pom</packaging>
<version>3.1.1</version>
<version>3.2.0</version>
<modules>
<module>qase-api</module>
<module>qase-testng</module>
Expand Down
2 changes: 1 addition & 1 deletion qase-api/README.md
Expand Up @@ -8,7 +8,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-api</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>

```
Expand Down
2 changes: 1 addition & 1 deletion qase-api/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.1.1</version>
<version>3.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
7 changes: 4 additions & 3 deletions qase-api/src/main/java/io/qase/api/QaseClient.java
Expand Up @@ -48,13 +48,14 @@ private static ApiClient initApiClient() {
.description(getConfig().runDescription())
.isAutotest(true))
.getResult().getId();
getConfig().setProperty(RUN_ID_KEY, String.valueOf(id));
logger.info("Qase run id - {}", getConfig().runId());
} catch (QaseException e) {
throw new IllegalStateException(e);
isEnabled = false;
logger.error(e.getMessage());
}
getConfig().setProperty(RUN_ID_KEY, String.valueOf(id));
}
}
logger.info("Qase run id - {}", getConfig().runId());
return client;
}

Expand Down
5 changes: 5 additions & 0 deletions qase-api/src/main/java/io/qase/api/utils/CucumberUtils.java
@@ -1,5 +1,6 @@
package io.qase.api.utils;

import java.net.URI;
import java.util.List;

import static io.qase.api.utils.IntegrationUtils.CASE_TAGS;
Expand All @@ -20,4 +21,8 @@ public static Long getCaseId(List<String> tags) {
}
return null;
}

public static int getHash(URI uri, Long line) {
return (uri.toString() + line).hashCode();
}
}
2 changes: 1 addition & 1 deletion qase-cucumber3-jvm/README.md
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber3-jvm</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber3-jvm/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.1.1</version>
<version>3.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber4-jvm/README.md
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber4-jvm</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber4-jvm/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.1.1</version>
<version>3.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber5-jvm/README.md
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber5-jvm</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
Expand Down
7 changes: 6 additions & 1 deletion qase-cucumber5-jvm/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.1.1</version>
<version>3.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -34,6 +34,11 @@
<artifactId>cucumber-java</artifactId>
<version>${cucumber5-java.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
@@ -1,5 +1,8 @@
package io.qase.cucumber5;

import gherkin.AstBuilder;
import gherkin.Parser;
import gherkin.ast.*;
import io.cucumber.plugin.ConcurrentEventListener;
import io.cucumber.plugin.event.*;
import io.qase.api.QaseClient;
Expand All @@ -15,17 +18,23 @@
import io.qase.cucumber5.guice.module.Cucumber5Module;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

import static io.qase.api.utils.CucumberUtils.getHash;
import static io.qase.api.utils.IntegrationUtils.getStacktrace;

@Slf4j
public class QaseEventListener implements ConcurrentEventListener {

private static final Map<Integer, Map<String, String>> EXAMPLES = new HashMap<>();
private static final String REPORTER_NAME = "Cucumber 5-JVM";

@Getter(lazy = true, value = AccessLevel.PRIVATE)
private final QaseTestCaseListener qaseTestCaseListener = createQaseListener();

Expand All @@ -44,12 +53,48 @@ public void setEventPublisher(EventPublisher publisher) {
}
}

private void testCaseStarted(TestStepStarted testStepStarted) {
if (testStepStarted.getTestStep() instanceof PickleStepTestStep) {
private void testCaseStarted(TestStepStarted event) {
if (EXAMPLES.get(getHash(event.getTestCase().getUri(), (long) event.getTestCase().getLine())) == null) {
TestCase testCase = event.getTestCase();
URI uri = testCase.getUri();
Parser<GherkinDocument> gherkinParser = new Parser<>(new AstBuilder());
try {
GherkinDocument gherkinDocument = gherkinParser.parse(new String(Files.readAllBytes(Paths.get(this.getClass().getClassLoader()
.getResource(uri.toString().replace("classpath:", "")).toURI()))));
parseExamples(uri, gherkinDocument);
} catch (URISyntaxException | IOException e) {
log.error(e.getMessage());
}
}
if (event.getTestStep() instanceof PickleStepTestStep) {
StepStorage.startStep();
}
}

private void parseExamples(URI uri, GherkinDocument gherkinDocument) {
Feature feature = gherkinDocument.getFeature();
List<ScenarioDefinition> children = feature.getChildren();
for (ScenarioDefinition child : children) {
if (child instanceof ScenarioOutline) {
ScenarioOutline scenario = (ScenarioOutline) child;
for (Examples exampleItem : scenario.getExamples()) {
List<String> headers = new ArrayList<>();
exampleItem.getTableHeader().getCells().forEach(h -> headers.add(h.getValue()));
List<TableRow> tableBody = exampleItem.getTableBody();
for (TableRow tableRow : tableBody) {
List<TableCell> cells = tableRow.getCells();
HashMap<String, String> example = new HashMap<>();
for (int k = 0; k < cells.size(); k++) {
String value = cells.get(k).getValue();
example.put(headers.get(k), value);
}
EXAMPLES.put(getHash(uri, (long) tableRow.getLocation().getLine()), example);
}
}
}
}
}

private void testStepFinished(TestStepFinished testStepFinished) {
if (testStepFinished.getTestStep() instanceof PickleStepTestStep) {
PickleStepTestStep step = (PickleStepTestStep) testStepFinished.getTestStep();
Expand Down Expand Up @@ -96,12 +141,13 @@ private void testCaseFinished(TestCaseFinished event) {
}

private void setupResultItem(ResultCreate resultCreate, TestCaseFinished event) {
List<String> tags = event.getTestCase().getTags();
TestCase testCase = event.getTestCase();
List<String> tags = testCase.getTags();
Long caseId = CucumberUtils.getCaseId(tags);

String caseTitle = null;
if (caseId == null) {
caseTitle = event.getTestCase().getName();
caseTitle = testCase.getName();
}

StatusEnum status = convertStatus(event.getResult().getStatus());
Expand All @@ -122,6 +168,8 @@ private void setupResultItem(ResultCreate resultCreate, TestCaseFinished event)
.stacktrace(stacktrace)
.steps(steps.isEmpty() ? null : steps)
.defect(isDefect);
Map<String, String> params = EXAMPLES.get(getHash(testCase.getUri(), (long) testCase.getLine()));
resultCreate.param(params);
}

private StatusEnum convertStatus(Status status) {
Expand Down
Expand Up @@ -73,7 +73,8 @@ void bulk() {
String[] args = new String[]{
"-g", "io.qase.cucumber5",
"--add-plugin", "io.qase.cucumber5.QaseEventListener",
"classpath:features/"
"classpath:features/",
"--threads", "4"
};
Main.run(args, Thread.currentThread().getContextClassLoader());

Expand Down Expand Up @@ -154,8 +155,100 @@ void bulk() {
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step\"\n" +
" } ]\n" +
" }, {\n" +
" \"case\" : {\n" +
" \"title\" : \"success with Positive Examples\"\n" +
" },\n" +
" \"status\" : \"passed\",\n" +
" \"time_ms\" : \"${json-unit.ignore}\",\n" +
" \"defect\" : false,\n" +
" \"param\" : {\n" +
" \"a\" : \"\\\"1\\\"\",\n" +
" \"b\" : \"\\\"2\\\"\"\n" +
" },\n" +
" \"steps\" : [ {\n" +
" \"position\" : 1,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"1\\\"\"\n" +
" }, {\n" +
" \"position\" : 2,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"2\\\"\"\n" +
" } ]\n" +
" }, {\n" +
" \"case\" : {\n" +
" \"title\" : \"success with Positive Examples\"\n" +
" },\n" +
" \"status\" : \"passed\",\n" +
" \"time_ms\" : \"${json-unit.ignore}\",\n" +
" \"defect\" : false,\n" +
" \"param\" : {\n" +
" \"a\" : \"\\\"3\\\"\",\n" +
" \"b\" : \"\\\"4\\\"\"\n" +
" },\n" +
" \"steps\" : [ {\n" +
" \"position\" : 1,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"3\\\"\"\n" +
" }, {\n" +
" \"position\" : 2,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"4\\\"\"\n" +
" } ]\n" +
" }, {\n" +
" \"case\" : {\n" +
" \"title\" : \"success with Positive Examples\"\n" +
" },\n" +
" \"status\" : \"passed\",\n" +
" \"time_ms\" : \"${json-unit.ignore}\",\n" +
" \"defect\" : false,\n" +
" \"param\" : {\n" +
" \"a\" : \"\\\"5\\\"\",\n" +
" \"b\" : \"\\\"6\\\"\"\n" +
" },\n" +
" \"steps\" : [ {\n" +
" \"position\" : 1,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"5\\\"\"\n" +
" }, {\n" +
" \"position\" : 2,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"6\\\"\"\n" +
" } ]\n" +
" }, {\n" +
" \"case\" : {\n" +
" \"title\" : \"success with Positive Examples\"\n" +
" },\n" +
" \"status\" : \"passed\",\n" +
" \"time_ms\" : \"${json-unit.ignore}\",\n" +
" \"defect\" : false,\n" +
" \"param\" : {\n" +
" \"a\" : \"\\\"7\\\"\",\n" +
" \"b\" : \"\\\"8\\\"\"\n" +
" },\n" +
" \"steps\" : [ {\n" +
" \"position\" : 1,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"7\\\"\"\n" +
" }, {\n" +
" \"position\" : 2,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step with parameter \\\"8\\\"\"\n" +
" } ]\n" +
" }, {\n" +
" \"case\" : {\n" +
" \"title\" : \"Success scenario\"\n" +
" },\n" +
" \"status\" : \"passed\",\n" +
" \"time_ms\" : \"${json-unit.ignore}\",\n" +
" \"defect\" : false,\n" +
" \"steps\" : [ {\n" +
" \"position\" : 1,\n" +
" \"status\" : \"passed\",\n" +
" \"action\" : \"Given success step\"\n" +
" } ]\n" +
" } ]\n" +
"}")));
"}", true, false)));
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions qase-cucumber5-jvm/src/test/java/io/qase/cucumber5/Steps.java
Expand Up @@ -10,6 +10,10 @@ public class Steps {
public void success() {
}

@Given("success step with parameter {string}")
public void success_step_with_parameter(String string) {
}

@Given("timeout {int} seconds")
public void success(int integer) throws InterruptedException {
TimeUnit.SECONDS.sleep(integer);
Expand Down
@@ -0,0 +1,15 @@
Feature: New case with examples

Scenario Outline: success with Positive Examples
Given success step with parameter <a>
Given success step with parameter <b>

Examples:
| a | b |
| "1" | "2" |
| "3" | "4" |
| "5" | "6" |
| "7" | "8" |

Scenario: Success scenario
Given success step
2 changes: 1 addition & 1 deletion qase-cucumber6-jvm/README.md
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber6-jvm</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
Expand Down

0 comments on commit b80f172

Please sign in to comment.