Skip to content

Commit 4b35a18

Browse files
committed
Merge origin/master
Conflicts: source/src/main/java/org/cerberus/core/engine/gwt/impl/PropertyService.java
2 parents ae523e9 + 3626b15 commit 4b35a18

File tree

15 files changed

+187
-28
lines changed

15 files changed

+187
-28
lines changed

source/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<jackson-datatype-jsr310.version>2.13.2</jackson-datatype-jsr310.version>
4949
<!-- jsonpath -->
5050
<jsonxpath.version>2.9.0</jsonxpath.version>
51+
<minidev.version>2.5.1</minidev.version>
5152
<!-- Groovy Version -->
5253
<groovy.version>3.0.11</groovy.version>
5354
<!-- <groovy-dateutil.version>3.0.11</groovy-dateutil.version>-->
@@ -312,6 +313,11 @@
312313
<artifactId>json-path</artifactId>
313314
<version>${jsonxpath.version}</version>
314315
</dependency>
316+
<dependency>
317+
<groupId>net.minidev</groupId>
318+
<artifactId>json-smart</artifactId>
319+
<version>${minidev.version}</version>
320+
</dependency>
315321

316322
<!-- Kafka -->
317323
<dependency>

source/src/main/java/org/cerberus/core/crud/entity/TestCase.java

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class TestCase {
118118
public static final String TESTCASE_TYPE_PRIVATE = "PRIVATE";
119119

120120
public static final String TESTCASE_ORIGIN_SIDE = "SeleniumIDE";
121+
public static final String TESTCASE_ORIGIN_TESTLINK = "TestLink";
121122
public static final String TESTCASE_ORIGIN_JIRAXRAYCLOUD = "JiraXray-Cloud";
122123
public static final String TESTCASE_ORIGIN_JIRAXRAYDC = "JiraXray-DC";
123124
public static final String TESTCASE_ORIGIN_JIRACLOUD = "Jira-Cloud";

source/src/main/java/org/cerberus/core/crud/entity/TestCaseCountryProperties.java

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public class TestCaseCountryProperties {
140140
public static final String VALUE3_RAW = "raw";
141141
public static final String VALUE3_COORDINATE = "coordinate";
142142
public static final String VALUE3_COUNT = "count";
143+
public static final String VALUE3_VALUESUM = "valueSum";
143144
public static final String VALUE3_ATTRIBUTE = "attribute";
144145
public static final String VALUE3_VALUELIST = "valueList";
145146
public static final String VALUE3_RAWLIST = "rawList";

source/src/main/java/org/cerberus/core/engine/execution/impl/ConditionService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ private AnswerItem<Boolean> evaluateCondition_ifElementPresent(String conditionO
550550
LOG.debug("Checking if Element Present - JSON");
551551
}
552552
try {
553-
if (jsonService.getFromJson(responseBody, null, conditionValue1, false, 0, TestCaseCountryProperties.VALUE3_VALUELIST) != null) {
553+
if (jsonService.getFromJson(tCExecution, responseBody, null, conditionValue1, false, 0, TestCaseCountryProperties.VALUE3_VALUELIST) != null) {
554554
conditionResult = true;
555555
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);
556556
mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
@@ -703,7 +703,7 @@ private AnswerItem<Boolean> evaluateCondition_ifElementNotPresent(String conditi
703703

704704
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
705705
try {
706-
if (jsonService.getFromJson(responseBody, null, conditionValue1, false, 0, TestCaseCountryProperties.VALUE3_VALUELIST) == null) {
706+
if (jsonService.getFromJson(tCExecution, responseBody, null, conditionValue1, false, 0, TestCaseCountryProperties.VALUE3_VALUELIST) == null) {
707707
conditionResult = true;
708708
mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);
709709
mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));

source/src/main/java/org/cerberus/core/engine/gwt/impl/ControlService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ private MessageEvent verifyElementPresent(TestCaseExecution tCExecution, String
769769
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {
770770
try {
771771
//Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.
772-
if (!jsonService.getFromJson(responseBody, null, elementPath, false, 0, TestCaseCountryProperties.VALUE3_VALUELIST).equals("[]")) {
772+
if (!jsonService.getFromJson(tCExecution, responseBody, null, elementPath, false, 0, TestCaseCountryProperties.VALUE3_VALUELIST).equals("[]")) {
773773
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);
774774
mes.resolveDescription("STRING1", elementPath);
775775
return mes;
@@ -888,7 +888,7 @@ private MessageEvent verifyElementNotPresent(TestCaseExecution execution, String
888888
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {
889889
try {
890890
//Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.
891-
if (!jsonService.getFromJson(responseBody, null, elementPath,false, 0, TestCaseCountryProperties.VALUE3_VALUELIST).equals("[]")) {
891+
if (!jsonService.getFromJson(execution, responseBody, null, elementPath,false, 0, TestCaseCountryProperties.VALUE3_VALUELIST).equals("[]")) {
892892
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);
893893
mes.resolveDescription("STRING1", elementPath);
894894
return mes;
@@ -1259,7 +1259,7 @@ public MessageEvent verifyElementXXX(String control, TestCaseExecution tCExecuti
12591259

12601260
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {
12611261
try {
1262-
actual = jsonService.getFromJson(responseBody, null, path,false, 0, TestCaseCountryProperties.VALUE3_VALUELIST);
1262+
actual = jsonService.getFromJson(tCExecution, responseBody, null, path,false, 0, TestCaseCountryProperties.VALUE3_VALUELIST);
12631263
} catch (Exception ex) {
12641264
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
12651265
mes.resolveDescription("ERROR", ex.toString());
@@ -1473,7 +1473,7 @@ private MessageEvent verifyElementTextMatchRegex(TestCaseExecution tCExecution,
14731473

14741474
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
14751475
try {
1476-
pathContent = jsonService.getFromJson(responseBody, null, path,false, 0, TestCaseCountryProperties.VALUE3_VALUELIST);
1476+
pathContent = jsonService.getFromJson(tCExecution, responseBody, null, path,false, 0, TestCaseCountryProperties.VALUE3_VALUELIST);
14771477
} catch (Exception ex) {
14781478
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
14791479
mes.resolveDescription("ERROR", ex.toString());

source/src/main/java/org/cerberus/core/engine/gwt/impl/PropertyService.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@
2828
import java.nio.file.Files;
2929
import java.text.DateFormat;
3030
import java.text.SimpleDateFormat;
31-
import java.util.*;
31+
import java.util.ArrayList;
32+
import java.util.Base64;
33+
import java.util.Date;
34+
import java.util.HashMap;
35+
import java.util.Iterator;
36+
import java.util.List;
37+
import java.util.TreeMap;
3238
import java.util.regex.Matcher;
3339
import java.util.regex.Pattern;
3440
import org.apache.commons.lang3.StringUtils;
@@ -1143,7 +1149,7 @@ private TestCaseExecutionData property_getFromNetworkTraffic(TestCaseExecutionDa
11431149
//Record result in filessytem.
11441150
testCaseExecutionData.addFileList(recorderService.recordProperty(execution.getId(), testCaseExecutionData.getProperty(), 1, harRes.toString(1), execution.getSecrets()));
11451151

1146-
String valueFromJson = this.jsonService.getFromJson(harRes.toString(), null, jsonPath,
1152+
String valueFromJson = this.jsonService.getFromJson(execution, harRes.toString(), null, jsonPath,
11471153
testCaseExecutionData.getNature().equals(TestCaseCountryProperties.NATURE_RANDOM), testCaseExecutionData.getRank(), testCaseExecutionData.getValue3());
11481154

11491155
if (valueFromJson != null) {
@@ -1231,7 +1237,7 @@ private TestCaseExecutionData property_getFromExecutionObject(TestCaseExecutionD
12311237
recorderService.recordProperty(tCExecution.getId(), testCaseExecutionData.getProperty(), 1, executionObject, tCExecution.getSecrets());
12321238

12331239
String valueFromJson = this.jsonService
1234-
.getFromJson(executionObject, null, testCaseExecutionData.getValue1(),
1240+
.getFromJson(tCExecution, executionObject, null, testCaseExecutionData.getValue1(),
12351241
testCaseExecutionData.getNature().equals(TestCaseCountryProperties.NATURE_RANDOM), testCaseExecutionData.getRank(), testCaseExecutionData.getValue3());
12361242

12371243
if (valueFromJson == null) {
@@ -1348,7 +1354,10 @@ private TestCaseExecutionData property_getFromHtml(TestCaseExecutionData testCas
13481354
valueFromHTML = this.webdriverService.getElements(tCExecution.getSession(), identifier);
13491355
break;
13501356
case (TestCaseCountryProperties.VALUE3_VALUELIST):
1351-
valueFromHTML = this.webdriverService.getElements(tCExecution.getSession(), identifier);
1357+
valueFromHTML = this.webdriverService.getElementsValues(tCExecution.getSession(), identifier);
1358+
break;
1359+
case (TestCaseCountryProperties.VALUE3_VALUESUM):
1360+
valueFromHTML = this.webdriverService.getElementsValuesSum(tCExecution, identifier);
13521361
break;
13531362
case (TestCaseCountryProperties.VALUE3_ATTRIBUTE):
13541363
valueFromHTML = this.webdriverService.getAttributeFromHtml(tCExecution.getSession(), identifier, testCaseExecutionData.getValue2(), TestCaseCountryProperties.NATURE_RANDOM.equals(testCaseExecutionData.getNature()), testCaseExecutionData.getRank());
@@ -1752,7 +1761,7 @@ private TestCaseExecutionData property_getFromJson(TestCaseExecutionData testCas
17521761
recorderService.recordProperty(execution.getId(), testCaseExecutionData.getProperty(), 1, jsonResponse, execution.getSecrets());
17531762

17541763
String valueFromJSON = this.jsonService
1755-
.getFromJson(jsonResponse, null, testCaseExecutionData.getValue1(),
1764+
.getFromJson(execution, jsonResponse, null, testCaseExecutionData.getValue1(),
17561765
testCaseExecutionData.getNature().equals(TestCaseCountryProperties.NATURE_RANDOM), testCaseExecutionData.getRank(), testCaseExecutionData.getValue3());
17571766

17581767
if (valueFromJSON == null) {

source/src/main/java/org/cerberus/core/service/json/IJsonService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.fasterxml.jackson.core.JsonProcessingException;
2323
import com.jayway.jsonpath.InvalidPathException;
24+
import org.cerberus.core.crud.entity.TestCaseExecution;
2425

2526
import java.net.MalformedURLException;
2627
import java.util.List;
@@ -43,7 +44,7 @@ public interface IJsonService {
4344
* @return
4445
* @throws java.lang.Exception
4546
*/
46-
String getFromJson(String jsonMessage, String url, String attribute, boolean random, Integer rank, String output) throws InvalidPathException, JsonProcessingException;
47+
String getFromJson(TestCaseExecution testCaseExecution, String jsonMessage, String url, String attribute, boolean random, Integer rank, String output) throws InvalidPathException, JsonProcessingException;
4748

4849
/**
4950
* @param jsonMessage

source/src/main/java/org/cerberus/core/service/json/impl/JsonService.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@
2626
import com.jayway.jsonpath.InvalidPathException;
2727
import com.jayway.jsonpath.JsonPath;
2828
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
29+
import net.minidev.json.JSONStyle;
30+
import net.minidev.json.JSONArray;
2931
import org.cerberus.core.crud.entity.TestCaseCountryProperties;
32+
import org.cerberus.core.crud.entity.TestCaseExecution;
33+
import org.cerberus.core.engine.entity.ExecutionLog;
3034
import org.cerberus.core.service.json.IJsonService;
35+
import org.cerberus.core.util.StringUtil;
3136
import org.springframework.stereotype.Service;
3237

3338
import java.io.BufferedReader;
@@ -39,7 +44,6 @@
3944
import java.util.List;
4045
import java.util.Random;
4146
import java.util.stream.Collectors;
42-
import org.json.JSONArray;
4347

4448
/**
4549
* @author bcivel
@@ -83,7 +87,7 @@ public String callUrlAndGetJsonResponse(String url) throws MalformedURLException
8387
* not found.
8488
*/
8589
@Override
86-
public String getFromJson(String jsonMessage, String url, String attributeToFind, boolean random, Integer rank, String output) throws InvalidPathException, JsonProcessingException {
90+
public String getFromJson(TestCaseExecution testCaseExecution, String jsonMessage, String url, String attributeToFind, boolean random, Integer rank, String output) throws InvalidPathException, JsonProcessingException {
8791
if (attributeToFind == null) {
8892
LOG.warn("Null argument");
8993
return DEFAULT_GET_FROM_JSON_VALUE;
@@ -109,15 +113,29 @@ public String getFromJson(String jsonMessage, String url, String attributeToFind
109113

110114
switch (output) {
111115
case (TestCaseCountryProperties.VALUE3_COUNT):
112-
valueFromJSON = String.valueOf(((JSONArray) JsonPath.read(document, jsonPath)).length());
116+
valueFromJSON = String.valueOf(((JSONArray) JsonPath.read(document, jsonPath)).size());
117+
break;
118+
case (TestCaseCountryProperties.VALUE3_VALUESUM):
119+
JSONArray array = (JSONArray) JsonPath.read(document, jsonPath);
120+
Double result = 0.0;
121+
for (Object object : array){
122+
String preparedString = StringUtil.prepareToNumeric(object.toString());
123+
if (!StringUtil.isEmptyOrNull(preparedString)) {
124+
result += Double.valueOf(preparedString);
125+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Property:GetFromJSON] : Adding ["+preparedString+"] from init value ["+object.toString()+"] to previous sum ["+ result+"].");
126+
}else{
127+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Property:GetFromJSON] : Do not add empty value from init value ["+object.toString()+"] to previous sum ["+ result+"].");
128+
}
129+
}
130+
valueFromJSON = result.toString();
113131
break;
114132
case (TestCaseCountryProperties.VALUE3_VALUELIST):
115133
valueFromJSON = castObjectAccordingToJson(JsonPath.read(document, jsonPath));
116134
break;
117135
case (TestCaseCountryProperties.VALUE3_VALUE):
118136
if (random) {
119137
Random r = new Random();
120-
rank = r.nextInt(((JSONArray) JsonPath.read(document, jsonPath)).length());
138+
rank = r.nextInt(((JSONArray) JsonPath.read(document, jsonPath)).size());
121139
}
122140
valueFromJSON = ((JSONArray) JsonPath.read(document, jsonPath)).get(rank).toString();
123141
break;
@@ -220,7 +238,7 @@ private String castObjectAccordingToJson(Object value) {
220238
} else if (value instanceof Boolean) {
221239
return ((Boolean) value).toString();
222240
} else if (value instanceof JSONArray) {
223-
return ((JSONArray) value).toString(1);
241+
return ((JSONArray) value).toString(JSONStyle.LT_COMPRESS);
224242
} else if (value instanceof Double) {
225243
return ((Double) value).toString();
226244
} else {

source/src/main/java/org/cerberus/core/service/webdriver/IWebDriverService.java

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.io.File;
2424
import java.io.IOException;
2525
import java.util.List;
26+
27+
import org.cerberus.core.crud.entity.TestCaseExecution;
2628
import org.cerberus.core.engine.entity.Identifier;
2729
import org.cerberus.core.engine.entity.MessageEvent;
2830
import org.cerberus.core.engine.entity.Session;
@@ -49,6 +51,8 @@ public interface IWebDriverService {
4951

5052
String getElementsValues(Session session, Identifier identifier);
5153

54+
String getElementsValuesSum(TestCaseExecution testCaseExecution, Identifier identifier);
55+
5256
String getAlertText(Session session);
5357

5458
String getValueFromJS(Session session, String script);

source/src/main/java/org/cerberus/core/service/webdriver/impl/WebDriverService.java

+36
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import mantu.lab.treematching.TreeMatcherResponse;
2929
import org.apache.logging.log4j.LogManager;
3030
import org.apache.logging.log4j.Logger;
31+
import org.cerberus.core.crud.entity.TestCaseExecution;
3132
import org.cerberus.core.crud.service.impl.ParameterService;
33+
import org.cerberus.core.engine.entity.ExecutionLog;
3234
import org.cerberus.core.engine.entity.Identifier;
3335
import org.cerberus.core.engine.entity.MessageEvent;
3436
import org.cerberus.core.engine.entity.Session;
@@ -578,6 +580,40 @@ public String getElementsValues(Session session, Identifier identifier) {
578580
return result.toString();
579581
}
580582

583+
@Override
584+
public String getElementsValuesSum(TestCaseExecution testCaseExecution, Identifier identifier) {
585+
WebDriver driver = testCaseExecution.getSession().getDriver();
586+
Double resultSum = 0.0;
587+
588+
List<WebElement> elements = driver.findElements(this.getBy(identifier));
589+
for (WebElement webElement : elements) {
590+
String preparedString = "";
591+
if (webElement != null) {
592+
if (webElement.getTagName().equalsIgnoreCase("select")) {
593+
Select select = (Select) webElement;
594+
preparedString = StringUtil.prepareToNumeric(select.getFirstSelectedOption().getText());
595+
if (!StringUtil.isEmptyOrNull(preparedString)) {
596+
resultSum += Double.valueOf(preparedString);
597+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Property:GetFromHTML] : Adding ["+preparedString+"] from init value ["+select.getFirstSelectedOption().getText()+"] to previous sum ["+ resultSum+"].");
598+
}
599+
} else if (webElement.getTagName().equalsIgnoreCase("option") || webElement.getTagName().equalsIgnoreCase("input")) {
600+
preparedString = StringUtil.prepareToNumeric(webElement.getAttribute("value"));
601+
if (!StringUtil.isEmptyOrNull(preparedString)) {
602+
resultSum += Double.valueOf(preparedString);
603+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Property:GetFromHTML] : Adding ["+preparedString+"] from init value ["+webElement.getAttribute("value")+"] to previous sum ["+ resultSum+"].");
604+
}
605+
} else {
606+
preparedString = StringUtil.prepareToNumeric(webElement.getText());
607+
if (!StringUtil.isEmptyOrNull(preparedString)) {
608+
resultSum += Double.valueOf(preparedString);
609+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Property:GetFromHTML] : Adding ["+preparedString+"] from init value ["+webElement.getText()+"] to previous sum ["+ resultSum+"].");
610+
}
611+
}
612+
}
613+
}
614+
return resultSum.toString();
615+
}
616+
581617
@Override
582618
public String getValueFromHTML(Session session, Identifier identifier, boolean random, Integer rank) {
583619
AnswerItem answer = this.getWebElement(session, identifier, random, rank);

source/src/main/java/org/cerberus/core/servlet/crud/test/testcase/ImportTestCase.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.HashMap;
2828
import java.util.List;
2929
import java.util.Map;
30-
import java.util.logging.Level;
3130
import javax.servlet.ServletContext;
3231
import javax.servlet.ServletException;
3332
import javax.servlet.annotation.WebServlet;
@@ -252,7 +251,7 @@ private HashMap<String, String> getParams(HttpServletRequest httpServletRequest)
252251
}
253252
}
254253
} catch (FileUploadException ex) {
255-
java.util.logging.Logger.getLogger(ImportTestCaseFromSIDE.class.getName()).log(Level.SEVERE, null, ex);
254+
LOG.error(ex, ex);
256255
}
257256
LOG.debug("result Param : " + result.size());
258257
return result;

0 commit comments

Comments
 (0)