Skip to content

Commit 53a3d98

Browse files
committed
v0.0.2 complete
1 parent 81abdd5 commit 53a3d98

File tree

8 files changed

+54
-31
lines changed

8 files changed

+54
-31
lines changed

pom.xml

Lines changed: 1 addition & 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.1</version>
7+
<version>0.0.2</version>
88
<name>cucumber-parallel-xbrowser-testing</name>
99
<url>https://github.com/rsshekhawat/cucumber-parallel-xbrowser-testing</url>
1010

src/main/java/io/github/rsshekhawat/MyMojo.java

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import org.apache.commons.lang3.StringUtils;
2019
import org.apache.maven.plugin.AbstractMojo;
2120
import org.apache.maven.plugin.MojoExecution;
2221
import org.apache.maven.plugin.MojoExecutionException;
@@ -56,8 +55,13 @@ public class MyMojo extends AbstractMojo
5655
@Parameter( defaultValue = "${mojoExecution}", readonly = true )
5756
private MojoExecution mojo;
5857

59-
String runnersDirectoryPath = System.getProperty("user.dir")+ File.separator+"target"+File.separator+"parallel-xbrowser"+File.separator+"runners";
58+
String baseDirectory = System.getProperty("user.dir")+ File.separator+"target"+File.separator+"parallel-xbrowser";
59+
String runnersDirectoryPath = baseDirectory+File.separator+"runners";
60+
String propertiesDirectoryPath = baseDirectory+File.separator+"properties";
61+
String dataDirectoryPath = baseDirectory+File.separator+"data";
6062
Map<Integer, Map<String, String>> configMap;
63+
String fileNamePattern = "IT_Cucumber_Parallel_Cross_Browser_";
64+
int totalFiles = 0;
6165

6266
@Override
6367
public void execute() throws MojoExecutionException {
@@ -69,35 +73,23 @@ public void execute() throws MojoExecutionException {
6973
getLog().info("------------------------------------------------------------------------");
7074
try {
7175
configMap = convertXMLToJSONAndReturnMap();
72-
prepareTemplateRunnerFile();
7376
createTestRunners();
77+
createPropertiesFilesForEachTestRunner();
7478
addSpecificsToTestRunners();
7579
printConfigurationsLogs();
80+
createDataPropertiesFile();
7681
} catch (Exception exc) {
7782
getLog().info("Exception : "+exc.getMessage());
7883
}
7984
}
8085

81-
public void prepareTemplateRunnerFile() throws IOException {
82-
83-
Map<String, String> map = new HashMap<>();
84-
map.put("FEATURE_FILES_PATH", featureFilesPath);
85-
map.put("FEATURE_FILES_TAGS",includedTags);
86-
87-
String filePath = templateRunnerPath;
88-
File file = new File(filePath);
89-
replaceTerms(file, map);
90-
}
91-
9286
public void createTestRunners() throws IOException {
9387

94-
int totalFiles = configMap.size();
9588
String content = new String(Files.readAllBytes(Paths.get(templateRunnerPath)));
96-
String fileName = "IT_Cucumber_Parallel_Cross_Browser_Test_Runner_";
9789
File dir = new File(runnersDirectoryPath);
9890

9991
for(int i=0;i<totalFiles;i++) {
100-
String filePath = runnersDirectoryPath + File.separator + fileName+i+".java";
92+
String filePath = runnersDirectoryPath + File.separator + fileNamePattern +i+".java";
10193
if (!dir.exists()) dir.mkdirs();
10294
File file = new File(filePath);
10395
boolean flag = file.createNewFile();
@@ -108,21 +100,31 @@ public void createTestRunners() throws IOException {
108100
getLog().info("Total Test Runners Created : "+totalFiles);
109101
}
110102

103+
public void createDataPropertiesFile() throws IOException {
104+
105+
File dir = new File(dataDirectoryPath);
106+
107+
for(int i=0;i<totalFiles;i++) {
108+
String filePath = dataDirectoryPath + File.separator + fileNamePattern +i+".properties";
109+
if (!dir.exists()) dir.mkdirs();
110+
File file = new File(filePath);
111+
file.createNewFile();
112+
}
113+
}
114+
111115
public void addSpecificsToTestRunners() throws IOException {
112116

113117
File folder = new File(runnersDirectoryPath);
114118
File[] listOfFiles = folder.listFiles();
115119
assert listOfFiles != null;
116120

117-
int index = 0;
118-
119121
for (File file : listOfFiles) {
120122
if (file.isFile()) {
121-
Map<String, String> m = configMap.get(index);
122-
m.put("TEST_RUNNER_CLASS_NAME",file.getName().split("\\.")[0]);
123-
replaceTerms(file, m);
124-
m.remove("TEST_RUNNER_CLASS_NAME");
125-
index+=1;
123+
Map<String, String> map = new HashMap<>();
124+
map.put("TEST_RUNNER_CLASS_NAME",file.getName().split("\\.")[0]);
125+
map.put("FEATURE_FILES_PATH", featureFilesPath);
126+
map.put("FEATURE_FILES_TAGS",includedTags);
127+
replaceTerms(file, map);
126128
}
127129
}
128130
}
@@ -152,12 +154,33 @@ public void replaceTerms(File file, Map<String, String> map) throws IOException
152154
}
153155
}
154156

157+
public void createPropertiesFilesForEachTestRunner() throws IOException {
158+
159+
Map<Integer, Map<String, String>> map = configMap;
160+
File dir = new File(propertiesDirectoryPath);
161+
162+
for(int i=0;i<totalFiles;i++) {
163+
String filePath = propertiesDirectoryPath + File.separator + fileNamePattern +i+ ".properties";
164+
if (!dir.exists()) dir.mkdirs();
165+
166+
File file = new File(filePath);
167+
BufferedWriter bf = new BufferedWriter(new FileWriter(file));
168+
169+
for (Map.Entry<String, String> entry : map.get(i).entrySet()) {
170+
bf.write(entry.getKey() + ":" + entry.getValue());
171+
bf.newLine();
172+
}
173+
bf.flush();
174+
}
175+
}
176+
155177
public Map<Integer, Map<String, String>> convertXMLToJSONAndReturnMap() throws IOException {
156178

157179
Map<Integer, Map<String, String>> map = new HashMap<>();
158180
String content = new String(Files.readAllBytes(Paths.get(configurationFilePath)));
159181
JSONObject obj = new JSONObject(XML.toJSONObject(content).toString()).getJSONObject("configurations");
160182
JSONArray arr = obj.getJSONArray("configuration");
183+
totalFiles = arr.length();
161184
for(int i=0;i<arr.length();i++){
162185
map.put(i, jsonToMap(arr.get(i).toString()));
163186
}
@@ -173,7 +196,7 @@ public Map<String, String> jsonToMap(String content) throws JSONException {
173196
while( keys.hasNext() ){
174197
String key = (String)keys.next();
175198
String value = jObject.get(key).toString();
176-
map.put(key+"Value", value);
199+
map.put(key, value);
177200
}
178201
return map;
179202
}
@@ -192,7 +215,7 @@ public void printConfigurationsLogs(){
192215
for (Map.Entry<Integer, Map<String, String>> mapElement : configMap.entrySet()) {
193216
Map<String, String> map = mapElement.getValue();
194217
for (Map.Entry<String, String> mapEle : map.entrySet()) {
195-
getLog().info(StringUtils.substringBefore(mapEle.getKey(),"Value") + " : " + mapEle.getValue());
218+
getLog().info(mapEle.getKey() + " : " + mapEle.getValue());
196219
}
197220
getLog().info("------------------------------------------------------------------------");
198221
}

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

Lines changed: 1 addition & 1 deletion
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.1</version>
10+
<version>0.0.2</version>
1111
<goalPrefix>cucumber-parallel-xbrowser-testing</goalPrefix>
1212
<mojos>
1313
<mojo>

target/classes/META-INF/maven/plugin.xml

Lines changed: 1 addition & 1 deletion
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.1</version>
10+
<version>0.0.2</version>
1111
<goalPrefix>cucumber-parallel-xbrowser-testing</goalPrefix>
1212
<isolatedRealm>false</isolatedRealm>
1313
<inheritedByDefault>true</inheritedByDefault>
857 Bytes
Binary file not shown.
-9.39 KB
Binary file not shown.
9.74 KB
Binary file not shown.

target/maven-archiver/pom.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven
2-
#Mon Feb 07 22:16:53 IST 2022
3-
version=0.0.1
2+
#Wed Feb 09 00:26:30 IST 2022
3+
version=0.0.2
44
groupId=io.github.rsshekhawat
55
artifactId=cucumber-parallel-xbrowser-testing

0 commit comments

Comments
 (0)