Skip to content

Commit

Permalink
Saving elements pictures also on conditions.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vertigo17 committed Mar 22, 2024
1 parent a9a02bc commit 967eb3e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public AnswerList<TestCaseStepActionExecution> readByVarious1(long executionId,
List<TestCaseStepActionExecution> list = new ArrayList<>();
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcasestepactionexecution exa ");
query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? ");
query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? order by `sort`");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.cerberus.core.engine.entity.Identifier;
import org.cerberus.core.engine.execution.IIdentifierService;
import org.cerberus.core.service.robotextension.impl.SikuliService;
import org.cerberus.core.service.xray.IXRayService;
import org.cerberus.core.service.robotproxy.IRobotProxyService;

Expand Down Expand Up @@ -153,6 +156,7 @@ public class ExecutionRunService implements IExecutionRunService {
private IRobotProxyService executorService;
private IEventService eventService;
private IXRayService xRayService;
private IIdentifierService identifierService;

@Override
public TestCaseExecution executeTestCase(TestCaseExecution execution) throws CerberusException {
Expand Down Expand Up @@ -1076,6 +1080,18 @@ private TestCaseStepExecution executeStep(TestCaseStepExecution stepExecution, T

if (!(conditionDecodeError)) {

// Record picture= files at Condition action level.
Identifier identifier = identifierService.convertStringToIdentifier(actionExecution.getConditionVal1());
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "Condition1"));
}
identifier = identifierService.convertStringToIdentifier(actionExecution.getConditionVal2());
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "Condition2"));
}

ConditionOperatorEnum actionConditionOperatorEnum = ConditionOperatorEnum.getConditionOperatorEnumFromString(actionExecution.getConditionOperator());

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

if (!(conditionDecodeError)) {

// Record picture= files at Condition control level.
Identifier identifier = identifierService.convertStringToIdentifier(controlExecution.getConditionVal1());
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
controlExecution.addFileList(recorderService.recordPicture(actionExecution, controlExecution.getControlId(), identifier.getLocator(), "Condition1"));
}
identifier = identifierService.convertStringToIdentifier(controlExecution.getConditionVal2());
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
controlExecution.addFileList(recorderService.recordPicture(actionExecution, controlExecution.getControlId(), identifier.getLocator(), "Condition2"));
}

ConditionOperatorEnum controlConditionOperatorEnum = ConditionOperatorEnum.getConditionOperatorEnumFromString(controlExecution.getConditionOperator());

conditionAnswer = this.conditionService.evaluateCondition(controlExecution.getConditionOperator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public List<TestCaseExecutionFile> recordExecutionInformationAfterStepActionAndC
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFileList.addAll(this.recordScreenshot(myExecution, actionExecution, controlNumber, "", "Screenshot", "screenshot"));
objectFileList.addAll(this.recordScreenshot(myExecution, actionExecution, controlNumber, "", "Screenshot After", "screenshot-after"));
} else {
LOG.debug("{}Not Doing screenshot because connectivity with selenium server lost.", logPrefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,12 @@ public TestCaseStepActionExecution doAction(TestCaseStepActionExecution actionEx
Identifier identifier = identifierService.convertStringToIdentifier(value1);
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
LOG.debug("Saving Image 1 on Action : " + identifier.getLocator());

actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "1"));
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "value1"));
}
identifier = identifierService.convertStringToIdentifier(value2);
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isEmpty(identifier.getLocator())) {
LOG.debug("Saving Image 2 on Action : " + identifier.getLocator());
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "2"));
actionExecution.addFileList(recorderService.recordPicture(actionExecution, -1, identifier.getLocator(), "value2"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,30 +767,41 @@ private Table getImageTable(List<TestCaseExecutionFile> fileList, String mediaPa
}
}

Collections.sort(fileList, new SortExecutionFile());

// If there is at least 1 image in the list
if (nbImages > 0) {
tableTmp = new Table(new float[]{150, 500});

imageInserted = false;
for (TestCaseExecutionFile controlFile : fileList) {
for (TestCaseExecutionFile exeFile : fileList) {

if (controlFile.isImage() && !imageInserted) {
if (exeFile.isImage()) {
// Load screenshots to pdf.
ImageData imageData;
try {
File f = new File(mediaPath + controlFile.getFileName());
imageInserted = true;
if (f.exists()) {
imageData = ImageDataFactory.create(mediaPath + controlFile.getFileName());
Image image = new Image(imageData).scaleToFit(500, 200);
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(image.setBorder(Border.NO_BORDER).setHorizontalAlignment(HorizontalAlignment.RIGHT)).setBorder(Border.NO_BORDER));
File f = new File(mediaPath + exeFile.getFileName());
if (exeFile.getFileDesc().contains("Picture") || !imageInserted) {
if (f.exists()) {
imageData = ImageDataFactory.create(mediaPath + exeFile.getFileName());
Image image;
if (!exeFile.getFileDesc().contains("Picture")) {
image = new Image(imageData).scaleToFit(500, 200);
} else {
image = new Image(imageData).scaleToFit(500, 50);
}
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(exeFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(image.setBorder(Border.NO_BORDER).setHorizontalAlignment(HorizontalAlignment.RIGHT)).setBorder(Border.NO_BORDER));

} else {
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(new Paragraph().add(getTextFromString("File no longuer exist !!!", 7, false)).setTextAlignment(TextAlignment.RIGHT)).setBorder(Border.NO_BORDER));
} else {
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(exeFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(new Paragraph().add(getTextFromString("File no longuer exist !!!", 7, false)).setTextAlignment(TextAlignment.RIGHT)).setBorder(Border.NO_BORDER));
}
}
if (!exeFile.getFileDesc().contains("Picture")) {
imageInserted = true;
}
} catch (MalformedURLException ex) {
LOG.error(ex, ex);
Expand Down Expand Up @@ -849,6 +860,20 @@ public int compare(TestCaseExecution a, TestCaseExecution b) {
}
}

class SortExecutionFile implements Comparator<TestCaseExecutionFile> {
// Used for sorting in ascending order of
// Label name.

@Override
public int compare(TestCaseExecutionFile a, TestCaseExecutionFile b) {
if (a != null && b != null) {
return (int) (b.getId() - a.getId());
} else {
return 1;
}
}
}

private Cell getHeaderCell(String text) {
return new Cell().add(new Paragraph(text)).setBackgroundColor(ColorConstants.LIGHT_GRAY).setFontSize(8).setTextAlignment(TextAlignment.CENTER);
}
Expand Down
11 changes: 7 additions & 4 deletions source/src/main/webapp/js/pages/TestCaseExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,13 @@ function Step(json, steps, id) {

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

var conditionTooltip = "<b>Condition : </b>" + this.conditionOperator + "</br>"
conditionTooltip += "<b>Val1 : </b>" + this.conditionVal1 + "</br>"
conditionTooltip += "<b>Val2 : </b>" + this.conditionVal2 + "</br>"
conditionTooltip += "<b>Val3 : </b>" + this.conditionVal3 + "</br>"
var conditionTooltip = "<b>Condition : </b>" + this.conditionOperator + "</br>";
if (conditionVal1 !== undefined)
conditionTooltip += "<b>Val1 : </b>" + this.conditionVal1.replaceAll("'", '').replaceAll('"', '') + "</br>";
if (conditionVal2 !== undefined)
conditionTooltip += "<b>Val2 : </b>" + this.conditionVal2.replaceAll("'", '').replaceAll('"', '') + "</br>";
if (conditionVal3 !== undefined)
conditionTooltip += "<b>Val3 : </b>" + this.conditionVal3.replaceAll("'", '').replaceAll('"', '') + "</br>";

if (this.loop !== "onceIfConditionTrue" && this.loop !== "onceIfConditionFalse") {
var labelOptions = $('<span class="label label-primary optionLabel labelLightGreen">Loop</span>');
Expand Down
9 changes: 6 additions & 3 deletions source/src/main/webapp/js/pages/TestCaseScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2851,9 +2851,12 @@ function printLabelForCondition(element, conditionOperator, conditionValue1, con
} else if (conditionOperator !== 'always') {
var title = "<div><b>Execution Condition : </b></div>";
title += "<div>'Condition' : '" + conditionOperator + "'</div>";
title += "<div>'val1' : '" + conditionValue1 + "'</div>";
title += "<div>'val2' : '" + conditionValue2 + "'</div>";
title += "<div>'val3' : '" + conditionValue3 + "'</div>";
if (conditionValue1 !== undefined)
title += "<div>'val1' : '" + conditionValue1.replaceAll("'", '').replaceAll('"', '') + "'</div>";
if (conditionValue2 !== undefined)
title += "<div>'val2' : '" + conditionValue2.replaceAll("'", '').replaceAll('"', '') + "'</div>";
if (conditionValue3 !== undefined)
title += "<div>'val3' : '" + conditionValue3.replaceAll("'", '').replaceAll('"', '') + "'</div>";
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>');
$(element).append(labelOptions[0]);
}
Expand Down

0 comments on commit 967eb3e

Please sign in to comment.