Skip to content

Commit 57158f9

Browse files
author
rshekhawat
committed
v0.0.5 complete
1 parent 1f57f10 commit 57158f9

File tree

13 files changed

+356
-13
lines changed

13 files changed

+356
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ import org.testng.annotations.AfterClass;
133133
import org.testng.annotations.BeforeClass;
134134
import java.io.File;
135135
import java.io.IOException;
136-
import io.github.rsshekhawat.MyMojo;
136+
import io.github.rsshekhawat.CreateTestRunners;
137137
138138
@CucumberOptions(
139139
features = {"FEATURE_FILES_PATH"},
@@ -155,7 +155,7 @@ public class TEST_RUNNER_CLASS_NAME extends AbstractTestNGCucumberTests {
155155
// ------------------------------------------------------------------------------------------------------------------------------------
156156
157157
// below function will set system properties to run this test runner on given configuration in config.xml
158-
new MyMojo().setSystemVariables("TEST_RUNNER_CLASS_NAME.properties");
158+
new CreateTestRunners().setSystemVariables("TEST_RUNNER_CLASS_NAME.properties");
159159
}
160160
161161
@AfterClass

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>io.github.rsshekhawat</groupId>
55
<artifactId>cucumber-parallel-xbrowser-testing</artifactId>
66
<packaging>maven-plugin</packaging>
7-
<version>0.0.4</version>
7+
<version>0.0.5</version>
88
<name>cucumber-parallel-xbrowser-testing</name>
99
<url>https://github.com/rsshekhawat/cucumber-parallel-xbrowser-testing</url>
1010

@@ -16,34 +16,46 @@
1616
</properties>
1717

1818
<dependencies>
19+
1920
<dependency>
2021
<groupId>org.apache.maven</groupId>
2122
<artifactId>maven-plugin-api</artifactId>
2223
<version>3.8.1</version>
2324
<scope>provided</scope>
2425
</dependency>
26+
2527
<dependency>
2628
<groupId>org.apache.maven.plugin-tools</groupId>
2729
<artifactId>maven-plugin-annotations</artifactId>
2830
<version>3.6.4</version>
2931
<scope>provided</scope>
3032
</dependency>
33+
3134
<dependency>
3235
<groupId>org.apache.maven</groupId>
3336
<artifactId>maven-core</artifactId>
3437
<version>3.8.4</version>
3538
<scope>provided</scope>
3639
</dependency>
40+
3741
<dependency>
3842
<groupId>org.json</groupId>
3943
<artifactId>json</artifactId>
4044
<version>20211205</version>
4145
</dependency>
46+
4247
<dependency>
4348
<groupId>org.apache.commons</groupId>
4449
<artifactId>commons-lang3</artifactId>
4550
<version>3.12.0</version>
4651
</dependency>
52+
53+
<dependency>
54+
<groupId>net.masterthought</groupId>
55+
<artifactId>cucumber-reporting</artifactId>
56+
<version>5.6.1</version>
57+
</dependency>
58+
4759
</dependencies>
4860

4961
<build>

src/main/java/io/github/rsshekhawat/MyMojo.java renamed to src/main/java/io/github/rsshekhawat/CreateTestRunners.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
import java.util.Iterator;
3535
import java.util.Map;
3636
import java.util.Properties;
37-
3837
import org.json.XML;
3938

4039
@Mojo(name="xbrowser", defaultPhase = LifecyclePhase.INITIALIZE)
41-
public class MyMojo extends AbstractMojo
40+
public class CreateTestRunners extends AbstractMojo
4241
{
4342
@Parameter(property = "project", readonly = true)
4443
private MavenProject mavenProject;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package io.github.rsshekhawat;
2+
3+
import org.apache.maven.plugin.AbstractMojo;
4+
import org.apache.maven.plugin.MojoExecutionException;
5+
import org.apache.maven.plugin.MojoExecution;
6+
import org.apache.maven.plugins.annotations.LifecyclePhase;
7+
import org.apache.maven.plugins.annotations.Mojo;
8+
import java.io.File;
9+
import java.io.FileInputStream;
10+
import java.io.InputStream;
11+
import java.util.*;
12+
import net.masterthought.cucumber.Configuration;
13+
import net.masterthought.cucumber.ReportBuilder;
14+
import net.masterthought.cucumber.Reportable;
15+
import net.masterthought.cucumber.json.support.Status;
16+
import net.masterthought.cucumber.presentation.PresentationMode;
17+
import org.apache.maven.plugins.annotations.Parameter;
18+
19+
@Mojo(name="xbrowser-reports", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
20+
public class CustomCucumberReports extends AbstractMojo {
21+
22+
@Parameter( defaultValue = "${mojoExecution}", readonly = true )
23+
private MojoExecution mojo;
24+
25+
@Parameter( property = "Qualifiers", required = true)
26+
private String Qualifiers;
27+
28+
String propertiesDirectoryPath = System.getProperty("user.dir")+ File.separator+"target"+File.separator+"parallel-xbrowser"+File.separator+"properties";
29+
30+
@Override
31+
public void execute() throws MojoExecutionException {
32+
getLog().info("------------------------------------------------------------------------");
33+
getLog().info("Plugin Name : "+mojo.getPlugin().getArtifactId());
34+
getLog().info("Plugin Version : "+mojo.getPlugin().getVersion());
35+
getLog().info("Developer : Rahul Shekhawat");
36+
getLog().info("------------------------------------------------------------------------");
37+
getLog().info("Creating customized cucumber reports...");
38+
getLog().info("------------------------------------------------------------------------");
39+
createCucumberReports();
40+
getLog().info("------------------------------------------------------------------------");
41+
getLog().info("Successfully generated customized cucumber reports. Good Bye !!!");
42+
getLog().info("------------------------------------------------------------------------");
43+
}
44+
45+
public void createCucumberReports() {
46+
47+
File reportOutputDirectory = new File("target");
48+
List<String> jsonFiles = new ArrayList<>();
49+
String cucumberReportDirectory = System.getProperty("user.dir")+File.separator+"target"+File.separator+"parallel-xbrowser"+File.separator+"cucumber-report";
50+
File folder = new File(cucumberReportDirectory);
51+
File[] listOfFiles = folder.listFiles();
52+
assert listOfFiles != null;
53+
for (File file : listOfFiles) {
54+
if (file.isFile()) {
55+
jsonFiles.add(file.getAbsolutePath());
56+
}
57+
}
58+
59+
String buildNumber = System.getenv("BUILD_NUMBER");
60+
String projectName = System.getenv("JOB_BASE_NAME");
61+
62+
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
63+
64+
// optional configuration - check javadoc for details
65+
configuration.addPresentationModes(PresentationMode.RUN_WITH_JENKINS);
66+
67+
// do not make scenario failed when step has status SKIPPED
68+
configuration.setNotFailingStatuses(Collections.singleton(Status.SKIPPED));
69+
configuration.setBuildNumber(buildNumber);
70+
71+
// optionally specify qualifiers for each of the report json files
72+
configuration.addPresentationModes(PresentationMode.PARALLEL_TESTING);
73+
74+
int count = 0;
75+
for (Map.Entry<String, String> mapElement : getQualifierMap(Qualifiers).entrySet()) {
76+
count+=1;
77+
configuration.addClassifications("Target "+count, mapElement.getValue());
78+
configuration.setQualifier(mapElement.getKey(), mapElement.getValue());
79+
}
80+
81+
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
82+
Reportable result = reportBuilder.generateReports();
83+
84+
// and here validate 'result' to decide what to do if report has failed
85+
}
86+
87+
public Map<String, String> getQualifierMap(String list){
88+
89+
Map<String, String> map = new HashMap<>();
90+
File folder = new File(propertiesDirectoryPath);
91+
File[] listOfFiles = folder.listFiles();
92+
assert listOfFiles != null;
93+
for (File file : listOfFiles) {
94+
if (file.isFile()) {
95+
String key = file.getName().split("\\.")[0];
96+
String value = getQualifierValue(file.getName(),list);
97+
map.put(key, value);
98+
}
99+
}
100+
return map;
101+
}
102+
103+
public String getQualifierValue(String fileName, String list){
104+
105+
List<String> res = new ArrayList<>();
106+
Map<String, String> map = new HashMap<>();
107+
try {
108+
File file = new File(propertiesDirectoryPath+File.separator+fileName);
109+
Properties prop = new Properties();
110+
InputStream is = new FileInputStream(file);
111+
prop.load(is);
112+
for (String key : prop.stringPropertyNames()){
113+
String value = prop.getProperty(key);
114+
map.put(key, value);
115+
}
116+
is.close();
117+
String[] arr = list.split("\\s+");
118+
119+
for(String item: arr){
120+
if(map.get(item)==null)
121+
continue;
122+
res.add(map.get(item));
123+
}
124+
125+
}catch (Exception exc){
126+
getLog().info("Exception : "+exc.getMessage());
127+
}
128+
return String.join(", ", res);
129+
}
130+
}

target/classes/META-INF/maven/io.github.rsshekhawat/cucumber-parallel-xbrowser-testing/plugin-help.xml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<description>xbrowser parallel testing</description>
88
<groupId>io.github.rsshekhawat</groupId>
99
<artifactId>cucumber-parallel-xbrowser-testing</artifactId>
10-
<version>0.0.4</version>
10+
<version>0.0.5</version>
1111
<goalPrefix>cucumber-parallel-xbrowser-testing</goalPrefix>
1212
<mojos>
1313
<mojo>
@@ -19,7 +19,7 @@
1919
<requiresOnline>false</requiresOnline>
2020
<inheritedByDefault>true</inheritedByDefault>
2121
<phase>initialize</phase>
22-
<implementation>io.github.rsshekhawat.MyMojo</implementation>
22+
<implementation>io.github.rsshekhawat.CreateTestRunners</implementation>
2323
<language>java</language>
2424
<instantiationStrategy>per-lookup</instantiationStrategy>
2525
<executionStrategy>once-per-session</executionStrategy>
@@ -61,5 +61,32 @@
6161
<templateRunnerPath implementation="java.lang.String">${templateRunnerPath}</templateRunnerPath>
6262
</configuration>
6363
</mojo>
64+
<mojo>
65+
<goal>xbrowser-reports</goal>
66+
<requiresDirectInvocation>false</requiresDirectInvocation>
67+
<requiresProject>true</requiresProject>
68+
<requiresReports>false</requiresReports>
69+
<aggregator>false</aggregator>
70+
<requiresOnline>false</requiresOnline>
71+
<inheritedByDefault>true</inheritedByDefault>
72+
<phase>post-integration-test</phase>
73+
<implementation>io.github.rsshekhawat.CustomCucumberReports</implementation>
74+
<language>java</language>
75+
<instantiationStrategy>per-lookup</instantiationStrategy>
76+
<executionStrategy>once-per-session</executionStrategy>
77+
<threadSafe>false</threadSafe>
78+
<parameters>
79+
<parameter>
80+
<name>Qualifiers</name>
81+
<type>java.lang.String</type>
82+
<required>true</required>
83+
<editable>true</editable>
84+
<description></description>
85+
</parameter>
86+
</parameters>
87+
<configuration>
88+
<Qualifiers implementation="java.lang.String">${Qualifiers}</Qualifiers>
89+
</configuration>
90+
</mojo>
6491
</mojos>
6592
</plugin>

0 commit comments

Comments
 (0)