Skip to content

Commit 0b5dced

Browse files
Merge pull request #10 from abhishekkadavil/dev
Added @author and @category tag support and done refactoring
2 parents 8e496c7 + 1acf7e1 commit 0b5dced

File tree

18 files changed

+106
-49
lines changed

18 files changed

+106
-49
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# RestAssured-Cucumber-Hybrid-Framework
22
RestAssured cucumber hybrid framework template
33

4+
## Features
5+
* Cucumber test case
6+
* Parallel/sequential execution
7+
* Execute through maven and java class [TestSuitRunner.java](src/test/java/testSuit/runners/TestSuitRunner.java)
8+
* Auto/customisable reporting
9+
* Scenario context
10+
* Added `@Author` and `@Category` tags in reporting so that we can
11+
412
# Test execution
513

614
* Test application: `https://gorest.co.in/`
@@ -342,7 +350,7 @@ Note: the file name sorting is case-sensitive, so uppercase A is executed before
342350
* Added functionality of ScenarioContext to accommodate all the common function in a scenario perspective eg: contextValues
343351
* The output of the test execution like response body, status, DB values etc. can be logged in report for the later use, so
344352
didn't create any other mechanism for that.
345-
**RestAssuredLoggingFilter:** Adding rest assured logs to console including all the details of request and response.
353+
**[RALoggerUtil.java](src/test/java/testSuit/utils/RALoggerUtil.java):** Adding rest assured logs to console including all the details of request and response.
346354
**Configuration:** Configurations for the test suits are done through `com.utils.ConfigUtil` interface which extends `org.aeonbits.owner.Config`. Suit level configuration are done in `ScenarioContext` class.
347355

348356
# Why and why not

src/test/java/testSuit/utils/ScenarioContext.java renamed to src/test/java/testSuit/contexts/ScenarioContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package testSuit.utils;
1+
package testSuit.contexts;
22

33
import com.github.tomakehurst.wiremock.client.MappingBuilder;
44
import io.cucumber.guice.ScenarioScoped;

src/test/java/testSuit/utils/TestContext.java renamed to src/test/java/testSuit/contexts/TestContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
package testSuit.utils;
1+
package testSuit.contexts;
22

33
import com.github.tomakehurst.wiremock.WireMockServer;
44
import com.google.gson.Gson;
55
import com.google.gson.reflect.TypeToken;
66
import net.datafaker.Faker;
77
import org.aeonbits.owner.ConfigFactory;
88
import testSuit.pojos.User;
9+
import testSuit.utils.ConfigUtil;
910

1011
import java.io.FileReader;
1112
import java.io.IOException;

src/test/java/testSuit/utils/DataSourceFactory.java renamed to src/test/java/testSuit/factories/DataSourceFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package testSuit.utils;
1+
package testSuit.factories;
22

33
import lombok.SneakyThrows;
44
import org.postgresql.ds.PGSimpleDataSource;
5+
import testSuit.contexts.TestContext;
56

67
import javax.sql.DataSource;
78

src/test/java/testSuit/utils/ReporterFactory.java renamed to src/test/java/testSuit/factories/ReporterFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package testSuit.utils;
1+
package testSuit.factories;
22

33
import com.aventstack.extentreports.ExtentTest;
44

src/test/java/testSuit/runners/RunnerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.aventstack.extentreports.ExtentReports;
44
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
55
import com.github.tomakehurst.wiremock.WireMockServer;
6-
import testSuit.utils.TestContext;
6+
import testSuit.contexts.TestContext;
77

88
import java.io.IOException;
99
import java.text.SimpleDateFormat;

src/test/java/testSuit/stepDef/CommonAssertions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import org.skyscreamer.jsonassert.JSONCompareMode;
1313
import org.skyscreamer.jsonassert.comparator.CustomComparator;
1414
import org.testng.Assert;
15-
import testSuit.utils.ReporterFactory;
16-
import testSuit.utils.ScenarioContext;
15+
import testSuit.factories.ReporterFactory;
16+
import testSuit.contexts.ScenarioContext;
1717

1818
import java.nio.file.Files;
1919
import java.nio.file.Paths;

src/test/java/testSuit/stepDef/CommonStepDef.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import io.restassured.specification.RequestSpecification;
1717
import lombok.SneakyThrows;
1818
import lombok.extern.slf4j.Slf4j;
19+
import testSuit.contexts.ScenarioContext;
20+
import testSuit.contexts.TestContext;
21+
import testSuit.factories.ReporterFactory;
1922
import testSuit.utils.*;
2023

2124
import java.io.File;

src/test/java/testSuit/stepDef/DBOpsStepDef.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import org.dbunit.dataset.CachedDataSet;
1212
import org.dbunit.dataset.IDataSet;
1313
import org.dbunit.dataset.ITable;
14-
import testSuit.utils.DataSourceFactory;
14+
import testSuit.factories.DataSourceFactory;
1515
import testSuit.utils.DbOpsUtil;
16-
import testSuit.utils.ReporterFactory;
17-
import testSuit.utils.ScenarioContext;
16+
import testSuit.factories.ReporterFactory;
17+
import testSuit.contexts.ScenarioContext;
1818

1919
import javax.sql.DataSource;
2020
import java.net.URL;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package testSuit.stepDef;
2+
3+
import io.cucumber.java.After;
4+
import io.cucumber.java.Before;
5+
import io.cucumber.java.Scenario;
6+
import lombok.extern.slf4j.Slf4j;
7+
import testSuit.factories.ReporterFactory;
8+
9+
import java.util.Collection;
10+
import java.util.HashSet;
11+
import java.util.Set;
12+
import java.util.regex.Matcher;
13+
import java.util.regex.Pattern;
14+
15+
/**
16+
* @author Abhishek Kadavil
17+
*/
18+
@Slf4j
19+
public class Hooks {
20+
21+
@Before
22+
public void beforeScenario(Scenario scenario) {
23+
log.info("beforeScenario {}", scenario.getName());
24+
}
25+
26+
@After
27+
public void afterScenario(Scenario scenario) {
28+
log.info("afterScenario {}", scenario.getName());
29+
30+
/* Code to manage @Author and @Category tags */
31+
Collection<String> tagsCollection = scenario.getSourceTagNames();
32+
Set<String> tags = new HashSet<>(tagsCollection);
33+
34+
tags.forEach(tag -> {
35+
if (tag.startsWith("@Author")) {
36+
ReporterFactory.getInstance().getExtentTest().assignAuthor(extractedTagValue(tag));
37+
} else if (tag.startsWith("@Category")) {
38+
ReporterFactory.getInstance().getExtentTest().assignCategory(extractedTagValue(tag));
39+
}
40+
});
41+
}
42+
43+
private String extractedTagValue(String tag) {
44+
45+
Pattern pattern;
46+
Matcher matcher = null;
47+
if (tag.startsWith("@Author")) {
48+
pattern = Pattern.compile("@Author\\(\"([^\"]+)\"\\)");
49+
matcher = pattern.matcher(tag);
50+
}
51+
if (tag.startsWith("@Category")) {
52+
pattern = Pattern.compile("@Category\\(\"([^\"]+)\"\\)");
53+
matcher = pattern.matcher(tag);
54+
}
55+
56+
if(matcher != null)
57+
{
58+
if (matcher.find()) {
59+
return matcher.group(1); // Return the author's name
60+
}
61+
}
62+
return "Unknown";
63+
}
64+
}

0 commit comments

Comments
 (0)