Skip to content

Commit 967eb3e

Browse files
committed
Saving elements pictures also on conditions.
Fixed #2522 by adding After to Screenshot file descriptions. Fixed Execution and testcase script page display issue when condition value parameters were containing quote or double quote characters
1 parent a9a02bc commit 967eb3e

File tree

7 files changed

+84
-26
lines changed

7 files changed

+84
-26
lines changed

source/src/main/java/org/cerberus/core/crud/dao/impl/TestCaseStepActionExecutionDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public AnswerList<TestCaseStepActionExecution> readByVarious1(long executionId,
115115
List<TestCaseStepActionExecution> list = new ArrayList<>();
116116
StringBuilder query = new StringBuilder();
117117
query.append("SELECT * FROM testcasestepactionexecution exa ");
118-
query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? ");
118+
query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? order by `sort`");
119119
// Debug message on SQL.
120120
if (LOG.isDebugEnabled()) {
121121
LOG.debug("SQL : " + query.toString());

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
import java.util.ArrayList;
103103
import java.util.Date;
104104
import java.util.List;
105+
import org.cerberus.core.engine.entity.Identifier;
106+
import org.cerberus.core.engine.execution.IIdentifierService;
107+
import org.cerberus.core.service.robotextension.impl.SikuliService;
105108
import org.cerberus.core.service.xray.IXRayService;
106109
import org.cerberus.core.service.robotproxy.IRobotProxyService;
107110

@@ -153,6 +156,7 @@ public class ExecutionRunService implements IExecutionRunService {
153156
private IRobotProxyService executorService;
154157
private IEventService eventService;
155158
private IXRayService xRayService;
159+
private IIdentifierService identifierService;
156160

157161
@Override
158162
public TestCaseExecution executeTestCase(TestCaseExecution execution) throws CerberusException {
@@ -1076,6 +1080,18 @@ private TestCaseStepExecution executeStep(TestCaseStepExecution stepExecution, T
10761080

10771081
if (!(conditionDecodeError)) {
10781082

1083+
// Record picture= files at Condition action level.
1084+
Identifier identifier = identifierService.convertStringToIdentifier(actionExecution.getConditionVal1());
1085+
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
1086+
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
1087+
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "Condition1"));
1088+
}
1089+
identifier = identifierService.convertStringToIdentifier(actionExecution.getConditionVal2());
1090+
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
1091+
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
1092+
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "Condition2"));
1093+
}
1094+
10791095
ConditionOperatorEnum actionConditionOperatorEnum = ConditionOperatorEnum.getConditionOperatorEnumFromString(actionExecution.getConditionOperator());
10801096

10811097
conditionAnswer = this.conditionService.evaluateCondition(actionExecution.getConditionOperator(),
@@ -1342,6 +1358,18 @@ private TestCaseStepActionExecution executeAction(TestCaseStepActionExecution ac
13421358

13431359
if (!(conditionDecodeError)) {
13441360

1361+
// Record picture= files at Condition control level.
1362+
Identifier identifier = identifierService.convertStringToIdentifier(controlExecution.getConditionVal1());
1363+
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
1364+
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
1365+
controlExecution.addFileList(recorderService.recordPicture(actionExecution, controlExecution.getControlId(), identifier.getLocator(), "Condition1"));
1366+
}
1367+
identifier = identifierService.convertStringToIdentifier(controlExecution.getConditionVal2());
1368+
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
1369+
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
1370+
controlExecution.addFileList(recorderService.recordPicture(actionExecution, controlExecution.getControlId(), identifier.getLocator(), "Condition2"));
1371+
}
1372+
13451373
ConditionOperatorEnum controlConditionOperatorEnum = ConditionOperatorEnum.getConditionOperatorEnumFromString(controlExecution.getConditionOperator());
13461374

13471375
conditionAnswer = this.conditionService.evaluateCondition(controlExecution.getConditionOperator(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public List<TestCaseExecutionFile> recordExecutionInformationAfterStepActionAndC
140140
* connectivity with selenium.
141141
*/
142142
if (!returnCode.equals("CA")) {
143-
objectFileList.addAll(this.recordScreenshot(myExecution, actionExecution, controlNumber, "", "Screenshot", "screenshot"));
143+
objectFileList.addAll(this.recordScreenshot(myExecution, actionExecution, controlNumber, "", "Screenshot After", "screenshot-after"));
144144
} else {
145145
LOG.debug("{}Not Doing screenshot because connectivity with selenium server lost.", logPrefix);
146146
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,12 @@ public TestCaseStepActionExecution doAction(TestCaseStepActionExecution actionEx
292292
Identifier identifier = identifierService.convertStringToIdentifier(value1);
293293
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
294294
LOG.debug("Saving Image 1 on Action : " + identifier.getLocator());
295-
296-
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "1"));
295+
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "value1"));
297296
}
298297
identifier = identifierService.convertStringToIdentifier(value2);
299298
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
300299
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
301-
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "2"));
300+
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "value2"));
302301
}
303302

304303
/**

source/src/main/java/org/cerberus/core/service/pdf/impl/PDFService.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -767,30 +767,41 @@ private Table getImageTable(List<TestCaseExecutionFile> fileList, String mediaPa
767767
}
768768
}
769769

770+
Collections.sort(fileList, new SortExecutionFile());
771+
770772
// If there is at least 1 image in the list
771773
if (nbImages > 0) {
772774
tableTmp = new Table(new float[]{150, 500});
773775

774776
imageInserted = false;
775-
for (TestCaseExecutionFile controlFile : fileList) {
777+
for (TestCaseExecutionFile exeFile : fileList) {
776778

777-
if (controlFile.isImage() && !imageInserted) {
779+
if (exeFile.isImage()) {
778780
// Load screenshots to pdf.
779781
ImageData imageData;
780782
try {
781-
File f = new File(mediaPath + controlFile.getFileName());
782-
imageInserted = true;
783-
if (f.exists()) {
784-
imageData = ImageDataFactory.create(mediaPath + controlFile.getFileName());
785-
Image image = new Image(imageData).scaleToFit(500, 200);
786-
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
787-
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
788-
.addCell(new Cell().add(image.setBorder(Border.NO_BORDER).setHorizontalAlignment(HorizontalAlignment.RIGHT)).setBorder(Border.NO_BORDER));
783+
File f = new File(mediaPath + exeFile.getFileName());
784+
if (exeFile.getFileDesc().contains("Picture") || !imageInserted) {
785+
if (f.exists()) {
786+
imageData = ImageDataFactory.create(mediaPath + exeFile.getFileName());
787+
Image image;
788+
if (!exeFile.getFileDesc().contains("Picture")) {
789+
image = new Image(imageData).scaleToFit(500, 200);
790+
} else {
791+
image = new Image(imageData).scaleToFit(500, 50);
792+
}
793+
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(exeFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
794+
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
795+
.addCell(new Cell().add(image.setBorder(Border.NO_BORDER).setHorizontalAlignment(HorizontalAlignment.RIGHT)).setBorder(Border.NO_BORDER));
789796

790-
} else {
791-
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
792-
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
793-
.addCell(new Cell().add(new Paragraph().add(getTextFromString("File no longuer exist !!!", 7, false)).setTextAlignment(TextAlignment.RIGHT)).setBorder(Border.NO_BORDER));
797+
} else {
798+
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(exeFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
799+
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
800+
.addCell(new Cell().add(new Paragraph().add(getTextFromString("File no longuer exist !!!", 7, false)).setTextAlignment(TextAlignment.RIGHT)).setBorder(Border.NO_BORDER));
801+
}
802+
}
803+
if (!exeFile.getFileDesc().contains("Picture")) {
804+
imageInserted = true;
794805
}
795806
} catch (MalformedURLException ex) {
796807
LOG.error(ex, ex);
@@ -849,6 +860,20 @@ public int compare(TestCaseExecution a, TestCaseExecution b) {
849860
}
850861
}
851862

863+
class SortExecutionFile implements Comparator<TestCaseExecutionFile> {
864+
// Used for sorting in ascending order of
865+
// Label name.
866+
867+
@Override
868+
public int compare(TestCaseExecutionFile a, TestCaseExecutionFile b) {
869+
if (a != null && b != null) {
870+
return (int) (b.getId() - a.getId());
871+
} else {
872+
return 1;
873+
}
874+
}
875+
}
876+
852877
private Cell getHeaderCell(String text) {
853878
return new Cell().add(new Paragraph(text)).setBackgroundColor(ColorConstants.LIGHT_GRAY).setFontSize(8).setTextAlignment(TextAlignment.CENTER);
854879
}

source/src/main/webapp/js/pages/TestCaseExecution.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,10 +2149,13 @@ function Step(json, steps, id) {
21492149

21502150
var stepLabelContainer = $("<div class='col-sm-12 stepLabelContainer' style='padding-left: 0px;margin-top:10px'></div>");
21512151

2152-
var conditionTooltip = "<b>Condition : </b>" + this.conditionOperator + "</br>"
2153-
conditionTooltip += "<b>Val1 : </b>" + this.conditionVal1 + "</br>"
2154-
conditionTooltip += "<b>Val2 : </b>" + this.conditionVal2 + "</br>"
2155-
conditionTooltip += "<b>Val3 : </b>" + this.conditionVal3 + "</br>"
2152+
var conditionTooltip = "<b>Condition : </b>" + this.conditionOperator + "</br>";
2153+
if (conditionVal1 !== undefined)
2154+
conditionTooltip += "<b>Val1 : </b>" + this.conditionVal1.replaceAll("'", '').replaceAll('"', '') + "</br>";
2155+
if (conditionVal2 !== undefined)
2156+
conditionTooltip += "<b>Val2 : </b>" + this.conditionVal2.replaceAll("'", '').replaceAll('"', '') + "</br>";
2157+
if (conditionVal3 !== undefined)
2158+
conditionTooltip += "<b>Val3 : </b>" + this.conditionVal3.replaceAll("'", '').replaceAll('"', '') + "</br>";
21562159

21572160
if (this.loop !== "onceIfConditionTrue" && this.loop !== "onceIfConditionFalse") {
21582161
var labelOptions = $('<span class="label label-primary optionLabel labelLightGreen">Loop</span>');

source/src/main/webapp/js/pages/TestCaseScript.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,9 +2851,12 @@ function printLabelForCondition(element, conditionOperator, conditionValue1, con
28512851
} else if (conditionOperator !== 'always') {
28522852
var title = "<div><b>Execution Condition : </b></div>";
28532853
title += "<div>'Condition' : '" + conditionOperator + "'</div>";
2854-
title += "<div>'val1' : '" + conditionValue1 + "'</div>";
2855-
title += "<div>'val2' : '" + conditionValue2 + "'</div>";
2856-
title += "<div>'val3' : '" + conditionValue3 + "'</div>";
2854+
if (conditionValue1 !== undefined)
2855+
title += "<div>'val1' : '" + conditionValue1.replaceAll("'", '').replaceAll('"', '') + "'</div>";
2856+
if (conditionValue2 !== undefined)
2857+
title += "<div>'val2' : '" + conditionValue2.replaceAll("'", '').replaceAll('"', '') + "'</div>";
2858+
if (conditionValue3 !== undefined)
2859+
title += "<div>'val3' : '" + conditionValue3.replaceAll("'", '').replaceAll('"', '') + "'</div>";
28572860
var labelOptions = $('<span data-toggle="tooltip" data-html="true" data-original-title="' + title + '" class="label label-primary labelGreen pull-right optionLabel conditionLabel"><span class="glyphicon glyphicon-cog"></span> Conditional Execution</span>');
28582861
$(element).append(labelOptions[0]);
28592862
}

0 commit comments

Comments
 (0)