How to use takeScreenShot method of org.cerberus.service.webdriver.impl.WebDriverService class

Best Cerberus-source code snippet using org.cerberus.service.webdriver.impl.WebDriverService.takeScreenShot

Source:ControlService.java Github

copy

Full Screen

1/**2 * Cerberus Copyright (C) 2013 - 2017 cerberustesting3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4 *5 * This file is part of Cerberus.6 *7 * Cerberus is free software: you can redistribute it and/or modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation, either version 3 of the License, or10 * (at your option) any later version.11 *12 * Cerberus is distributed in the hope that it will be useful,13 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with Cerberus. If not, see <http://www.gnu.org/licenses/>.19 */20package org.cerberus.engine.gwt.impl;21import com.google.common.primitives.Ints;22import com.jayway.jsonpath.PathNotFoundException;23import org.apache.logging.log4j.LogManager;24import org.apache.logging.log4j.Logger;25import org.cerberus.crud.entity.*;26import org.cerberus.engine.entity.Identifier;27import org.cerberus.engine.entity.MessageEvent;28import org.cerberus.engine.entity.MessageGeneral;29import org.cerberus.engine.execution.IIdentifierService;30import org.cerberus.engine.execution.IRecorderService;31import org.cerberus.engine.execution.IRobotServerService;32import org.cerberus.engine.execution.impl.RobotServerService;33import org.cerberus.engine.gwt.IControlService;34import org.cerberus.engine.gwt.IVariableService;35import org.cerberus.enums.MessageEventEnum;36import org.cerberus.exception.CerberusEventException;37import org.cerberus.service.json.IJsonService;38import org.cerberus.service.sikuli.ISikuliService;39import org.cerberus.service.sikuli.impl.SikuliService;40import org.cerberus.service.webdriver.IWebDriverService;41import org.cerberus.service.xmlunit.IXmlUnitService;42import org.cerberus.util.ParameterParserUtil;43import org.cerberus.util.StringUtil;44import org.cerberus.util.answer.AnswerItem;45import org.openqa.selenium.NoSuchElementException;46import org.openqa.selenium.TimeoutException;47import org.openqa.selenium.WebDriver;48import org.openqa.selenium.WebDriverException;49import org.openqa.selenium.support.ui.WebDriverWait;50import org.springframework.beans.factory.annotation.Autowired;51import org.springframework.stereotype.Service;52import java.util.*;53import java.util.concurrent.TimeUnit;54import java.util.function.Function;55import java.util.regex.Matcher;56import java.util.regex.Pattern;57import java.util.regex.PatternSyntaxException;58/**59 * {Insert class description here}60 *61 * @author Tiago Bernardes62 * @version 1.0, 24/01/201363 * @since 2.0.064 */65@Service66public class ControlService implements IControlService {67 private static final Logger LOG = LogManager.getLogger(ControlService.class);68 @Autowired69 private IWebDriverService webdriverService;70 @Autowired71 private IXmlUnitService xmlUnitService;72 @Autowired73 private IJsonService jsonService;74 @Autowired75 private IIdentifierService identifierService;76 @Autowired77 private ISikuliService sikuliService;78 @Autowired79 private IRecorderService recorderService;80 @Autowired81 private IVariableService variableService;82 @Autowired83 private IRobotServerService robotServerService;84 @Override85 public TestCaseStepActionControlExecution doControl(TestCaseStepActionControlExecution controlExecution) {86 MessageEvent res;87 TestCaseExecution execution = controlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();88 AnswerItem<String> answerDecode = new AnswerItem<>();89 // Decode the step action control description90 try {91 // When starting a new control, we reset the property list that was already calculated.92 execution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());93 answerDecode = variableService.decodeStringCompletly(controlExecution.getDescription(),94 execution, controlExecution.getTestCaseStepActionExecution(), false);95 controlExecution.setDescription(answerDecode.getItem());96 if (!(answerDecode.isCodeStringEquals("OK"))) {97 // If anything wrong with the decode --> we stop here with decode message in the control result.98 controlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Description"));99 controlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));100 controlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());101 controlExecution.setEnd(new Date().getTime());102 LOG.debug("Control interrupted due to decode 'Description' Error.");103 return controlExecution;104 }105 } catch (CerberusEventException cex) {106 controlExecution.setControlResultMessage(cex.getMessageError());107 controlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));108 return controlExecution;109 }110 //Decode the 2 fields property and values before doing the control.111 try {112 // for both control property and control value113 //if the getvalue() indicates that the execution should stop then we stop it before the doControl or114 //if the property service was unable to decode the property that is specified in the object,115 //then the execution of this control should not performed116 if (controlExecution.getValue1() == null) {117 controlExecution.setValue1("");118 }119 if (controlExecution.getValue1().contains("%")) {120 // When starting a new control, we reset the property list that was already calculated.121 execution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());122 answerDecode = variableService.decodeStringCompletly(controlExecution.getValue1(), execution,123 controlExecution.getTestCaseStepActionExecution(), false);124 controlExecution.setValue1(answerDecode.getItem());125 if (!(answerDecode.isCodeStringEquals("OK"))) {126 // If anything wrong with the decode --> we stop here with decode message in the control result.127 controlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value1"));128 controlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));129 controlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());130 controlExecution.setEnd(new Date().getTime());131 LOG.debug("Control interrupted due to decode 'Control Value1' Error.");132 return controlExecution;133 }134 }135 if (controlExecution.getValue2() == null) {136 controlExecution.setValue2("");137 }138 if (controlExecution.getValue2().contains("%")) {139 // When starting a new control, we reset the property list that was already calculated.140 execution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());141 answerDecode = variableService.decodeStringCompletly(controlExecution.getValue2(),142 execution, controlExecution.getTestCaseStepActionExecution(), false);143 controlExecution.setValue2(answerDecode.getItem());144 if (!(answerDecode.isCodeStringEquals("OK"))) {145 // If anything wrong with the decode --> we stop here with decode message in the control result.146 controlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value2"));147 controlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));148 controlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());149 controlExecution.setEnd(new Date().getTime());150 LOG.debug("Control interrupted due to decode 'Control Value2' Error.");151 return controlExecution;152 }153 }154 if (controlExecution.getValue3() == null) {155 controlExecution.setValue3("");156 }157 if (controlExecution.getValue3().contains("%")) {158 // When starting a new control, we reset the property list that was already calculated.159 execution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());160 answerDecode = variableService.decodeStringCompletly(controlExecution.getValue3(),161 execution, controlExecution.getTestCaseStepActionExecution(), false);162 controlExecution.setValue3(answerDecode.getItem());163 if (!(answerDecode.isCodeStringEquals("OK"))) {164 // If anything wrong with the decode --> we stop here with decode message in the control result.165 controlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value3"));166 controlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));167 controlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());168 controlExecution.setEnd(new Date().getTime());169 LOG.debug("Control interrupted due to decode 'Control Value3' Error.");170 return controlExecution;171 }172 }173 } catch (CerberusEventException cex) {174 controlExecution.setControlResultMessage(cex.getMessageError());175 controlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));176 return controlExecution;177 }178 //Timestamp starts after the decode.179 controlExecution.setStart(new Date().getTime());180 controlExecution.setEnd(new Date().getTime());181 // When starting a new control, we reset the property list that was already calculated.182 execution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList<>());183 String value1 = controlExecution.getValue1();184 String value2 = controlExecution.getValue2();185 String value3 = controlExecution.getValue3();186 // Define Timeout187 HashMap<String, String> optionsMap = robotServerService.getMapFromOptions(controlExecution.getOptions());188 if (optionsMap.containsKey(RobotServerService.OPTIONS_TIMEOUT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX).isEmpty()) {189 Optional<Integer> timeoutOptionValue = Optional.ofNullable(Ints.tryParse(optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX)));190 if (timeoutOptionValue.isPresent()) {191 robotServerService.setOptionsTimeout(execution.getSession(), timeoutOptionValue.get());192 } else {193 //TODO return a message alerting about the failed cast194 LOG.debug("failed to parse option value : {}", optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));195 }196 }197 if (optionsMap.containsKey(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX).isEmpty()) {198 Optional<Integer> highlightOptionValue = Optional.ofNullable(Ints.tryParse(optionsMap.get(RobotServerService.OPTIONS_HIGHLIGHTELEMENT_SYNTAX)));199 if (highlightOptionValue.isPresent()) {200 robotServerService.setOptionsHighlightElement(execution.getSession(), highlightOptionValue.get());201 } else {202 //TODO return a message alerting about the failed cast203 LOG.debug("failed to parse option value : {}", optionsMap.get(RobotServerService.OPTIONS_TIMEOUT_SYNTAX));204 }205 }206 if (optionsMap.containsKey(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX).isEmpty()) {207 String minSimilarity = optionsMap.get(RobotServerService.OPTIONS_MINSIMILARITY_SYNTAX);208 robotServerService.setOptionsMinSimilarity(execution.getSession(), minSimilarity);209 }210 if (optionsMap.containsKey(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX) && !optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX).isEmpty()) {211 String typeDelay = optionsMap.get(RobotServerService.OPTIONS_TYPEDELAY_SYNTAX);212 robotServerService.setOptionsTypeDelay(execution.getSession(), typeDelay);213 }214 // Record picture= files at action level.215 Identifier identifier = identifierService.convertStringToIdentifier(value1);216 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isNullOrEmpty(identifier.getLocator())) {217 LOG.warn("Saving Image 1 on Control : {}", identifier.getLocator());218 controlExecution.addFileList(recorderService.recordPicture(controlExecution.getTestCaseStepActionExecution(), controlExecution.getControlId(), identifier.getLocator(), "1"));219 }220 identifier = identifierService.convertStringToIdentifier(value2);221 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE) && !StringUtil.isNullOrEmpty(identifier.getLocator())) {222 LOG.warn("Saving Image 2 on Control : {}", identifier.getLocator());223 controlExecution.addFileList(recorderService.recordPicture(controlExecution.getTestCaseStepActionExecution(), controlExecution.getControlId(), identifier.getLocator(), "2"));224 }225 try {226 switch (controlExecution.getControl()) {227 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGEQUAL:228 res = this.verifyStringEqual(value1, controlExecution.getValue2(), controlExecution.getValue3());229 break;230 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGDIFFERENT:231 res = this.verifyStringDifferent(value1, controlExecution.getValue2(), controlExecution.getValue3());232 break;233 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGGREATER:234 res = this.verifyStringGreater(value1, controlExecution.getValue2());235 break;236 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGMINOR:237 res = this.verifyStringMinor(value1, controlExecution.getValue2());238 break;239 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGCONTAINS:240 res = this.verifyStringContains(value1, controlExecution.getValue2(), controlExecution.getValue3());241 break;242 case TestCaseStepActionControl.CONTROL_VERIFYSTRINGNOTCONTAINS:243 res = this.verifyStringNotContains(value1, controlExecution.getValue2(), controlExecution.getValue3());244 break;245 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:246 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:247 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:248 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:249 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:250 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:251 res = this.evaluateControlIfNumericXXX(controlExecution.getControl(), value1, controlExecution.getValue2());252 break;253 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT:254 res = this.verifyElementPresent(execution, value1);255 break;256 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT:257 res = this.verifyElementNotPresent(execution, value1);258 break;259 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE:260 res = this.verifyElementVisible(execution, value1);261 break;262 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:263 res = this.verifyElementNotVisible(execution, value1);264 break;265 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:266 res = this.verifyElementEquals(execution, value1, controlExecution.getValue2());267 break;268 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:269 res = this.verifyElementDifferent(execution, value1, controlExecution.getValue2());270 break;271 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:272 res = this.verifyElementInElement(execution, value1, controlExecution.getValue2());273 break;274 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:275 res = this.verifyElementClickable(execution, value1);276 break;277 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:278 res = this.verifyElementNotClickable(execution, value1);279 break;280 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:281 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());282 break;283 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:284 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());285 break;286 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS:287 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());288 break;289 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:290 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());291 break;292 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:293 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());294 break;295 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:296 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());297 break;298 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:299 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());300 break;301 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:302 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());303 break;304 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:305 res = this.verifyElementXXX(TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL, execution, value1, controlExecution.getValue2(), controlExecution.getValue3());306 break;307 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX:308 res = this.verifyElementTextMatchRegex(execution, value1, controlExecution.getValue2());309 break;310 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:311 res = this.verifyTextInPage(execution, value1);312 break;313 case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:314 res = this.verifyTextNotInPage(execution, value1);315 break;316 case TestCaseStepActionControl.CONTROL_VERIFYTITLE:317 res = this.verifyTitle(execution, value1, controlExecution.getValue3());318 break;319 case TestCaseStepActionControl.CONTROL_VERIFYURL:320 res = this.verifyUrl(execution, value1);321 break;322 case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:323 res = this.verifyTextInDialog(execution, value1, controlExecution.getValue2());324 break;325 case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:326 res = this.verifyXmlTreeStructure(execution, value1, controlExecution.getValue2());327 break;328 case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:329 res = this.takeScreenshot(execution, controlExecution.getTestCaseStepActionExecution(), controlExecution, value1);330 break;331 case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:332 res = this.getPageSource(execution, controlExecution.getTestCaseStepActionExecution(), controlExecution);333 break;334 default:335 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);336 res.resolveDescription("CONTROL", controlExecution.getControl());337 }338 } catch (final CerberusEventException exception) {339 res = exception.getMessageError();340 } catch (final Exception unexpected) {341 LOG.debug("Unexpected exception on control!", unexpected);342 res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());343 }344 // Reset Timeout to default345 robotServerService.setOptionsToDefault(execution.getSession());346 controlExecution.setControlResultMessage(res);347 /*348 * Updating Control result message only if control is not successful.349 * This is to keep the last KO information and preventing KO to be350 * transformed to OK.351 */352 if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {353 controlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));354 }355 /*356 * We only stop the test if Control Event message is in stop status AND357 * the control is FATAL. If control is not fatal, we continue the test358 * but refresh the Execution status.359 */360 if (res.isStopTest() && controlExecution.getFatal().equals("Y")) {361 controlExecution.setStopExecution(true);362 }363 controlExecution.setEnd(new Date().getTime());364 return controlExecution;365 }366 private MessageEvent verifyStringDifferent(String value1, String value2, String isCaseSensitive) {367 MessageEvent mes;368 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? !value1.equals(value2) : !value1.equalsIgnoreCase(value2)) {369 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGDIFFERENT);370 } else {371 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGDIFFERENT);372 }373 mes.resolveDescription("STRING1", value1);374 mes.resolveDescription("STRING2", value2);375 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));376 return mes;377 }378 private MessageEvent verifyStringEqual(String value1, String value2, String isCaseSensitive) {379 MessageEvent mes;380 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.equals(value2) : value1.equalsIgnoreCase(value2)) {381 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_STRINGEQUAL);382 } else {383 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_STRINGEQUAL);384 }385 mes.resolveDescription("STRING1", value1);386 mes.resolveDescription("STRING2", value2);387 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));388 return mes;389 }390 private MessageEvent verifyStringContains(String value1, String value2, String isCaseSensitive) {391 MessageEvent mes;392 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.contains(value2) : value1.toLowerCase().contains(value2.toLowerCase())) {393 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CONTAINS);394 } else {395 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CONTAINS);396 }397 mes.resolveDescription("STRING1", value1);398 mes.resolveDescription("STRING2", value2);399 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));400 return mes;401 }402 private MessageEvent verifyStringNotContains(String value1, String value2, String isCaseSensitive) {403 MessageEvent mes;404 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? value1.contains(value2) : value1.toLowerCase().contains(value2.toLowerCase())) {405 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCONTAINS);406 } else {407 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCONTAINS);408 }409 mes.resolveDescription("STRING1", value1);410 mes.resolveDescription("STRING2", value2);411 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));412 return mes;413 }414 private MessageEvent verifyStringGreater(String value1, String value2) {415 MessageEvent mes;416 if (value1.compareToIgnoreCase(value2) > 0) {417 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);418 } else {419 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);420 }421 mes.resolveDescription("STRING1", value1);422 mes.resolveDescription("STRING2", value2);423 return mes;424 }425 private MessageEvent verifyStringMinor(String value1, String value2) {426 MessageEvent mes;427 if (value1.compareToIgnoreCase(value2) < 0) {428 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);429 } else {430 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);431 }432 mes.resolveDescription("STRING1", value1);433 mes.resolveDescription("STRING2", value2);434 return mes;435 }436 private MessageEvent evaluateControlIfNumericXXX(String control, String controlValue1, String controlValue2) {437 if (LOG.isDebugEnabled()) {438 LOG.debug("Checking if Numeric Equals");439 }440 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_PENDING);441 // We first prepare the string for numeric conversion to replace , by .442 String newControlValue1 = StringUtil.prepareToNumeric(controlValue1);443 String newControlValue2 = StringUtil.prepareToNumeric(controlValue2);444 // We try to convert the strings value1 to numeric.445 Double value1;446 try {447 value1 = Double.valueOf(newControlValue1);448 } catch (NumberFormatException nfe) {449 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);450 mes.resolveDescription("COND", control);451 mes.resolveDescription("STRINGVALUE", newControlValue1);452 return mes;453 }454 // We try to convert the strings value2 to numeric.455 Double value2;456 try {457 value2 = Double.valueOf(newControlValue2);458 } catch (NumberFormatException nfe) {459 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);460 mes.resolveDescription("COND", control);461 mes.resolveDescription("STRINGVALUE", newControlValue2);462 return mes;463 }464 // Now that both values are converted to double we check the operator here.465 switch (control) {466 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:467 if (Objects.equals(value1, value2)) {468 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_EQUAL);469 } else {470 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_EQUAL);471 }472 break;473 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:474 if (!(Objects.equals(value1, value2))) {475 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_DIFFERENT);476 } else {477 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_DIFFERENT);478 }479 break;480 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:481 if (value1 > value2) {482 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATER);483 } else {484 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATER);485 }486 break;487 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:488 if (value1 >= value2) {489 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GREATEROREQUAL);490 } else {491 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GREATEROREQUAL);492 }493 break;494 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:495 if (value1 < value2) {496 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOR);497 } else {498 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOR);499 }500 break;501 case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:502 if (value1 <= value2) {503 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_MINOROREQUAL);504 } else {505 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_MINOROREQUAL);506 }507 break;508 default:509 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);510 }511 mes.resolveDescription("COND", control);512 mes.resolveDescription("STRING1", value1.toString());513 mes.resolveDescription("STRING2", value2.toString());514 return mes;515 }516 private MessageEvent verifyElementPresent(TestCaseExecution tCExecution, String elementPath) {517 LOG.debug("Control: verifyElementPresent on: {}", elementPath);518 MessageEvent mes;519 if (!StringUtil.isNull(elementPath)) {520 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);521 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)522 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)523 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {524 try {525 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {526 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), "");527 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {528 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), "", identifier.getLocator());529 } else if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {530 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);531 mes.resolveDescription("STRING1", elementPath);532 return mes;533 } else {534 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);535 mes.resolveDescription("STRING1", elementPath);536 return mes;537 }538 } catch (WebDriverException exception) {539 return parseWebDriverException(exception);540 }541 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {542 if (tCExecution.getLastServiceCalled() != null) {543 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();544 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {545 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:546 if (xmlUnitService.isElementPresent(responseBody, elementPath)) {547 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);548 } else {549 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);550 }551 mes.resolveDescription("STRING1", elementPath);552 return mes;553 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {554 try {555 //Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.556 if (!jsonService.getFromJson(responseBody, null, elementPath).equals("[]")) {557 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);558 mes.resolveDescription("STRING1", elementPath);559 return mes;560 } else {561 throw new PathNotFoundException();562 }563 } catch (PathNotFoundException ex) {564 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);565 mes.resolveDescription("STRING1", elementPath);566 return mes;567 } catch (Exception ex) {568 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);569 mes.resolveDescription("ERROR", ex.toString());570 return mes;571 }572 }573 default:574 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);575 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());576 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);577 return mes;578 }579 } else {580 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);581 return mes;582 }583 } else if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {584 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {585 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator(), "");586 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {587 return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), "", identifier.getLocator());588 } else {589 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION_AND_IDENTIFIER);590 mes.resolveDescription("IDENTIFIER", identifier.getIdentifier());591 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);592 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());593 return mes;594 }595 } else {596 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);597 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT);598 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());599 return mes;600 }601 } else {602 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT_NULL);603 }604 }605 private MessageEvent verifyElementNotPresent(TestCaseExecution execution, String elementPath) {606 LOG.debug("Control: verifyElementNotPresent on: {}", elementPath);607 MessageEvent mes;608 if (!StringUtil.isNull(elementPath)) {609 Identifier identifier = identifierService.convertStringToIdentifier(elementPath);610 if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)611 || execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)612 || execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {613 try {614 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {615 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), identifier.getLocator(), "");616 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {617 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), "", identifier.getLocator());618 } else if (!this.webdriverService.isElementPresent(execution.getSession(), identifier)) {619 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);620 } else {621 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);622 }623 mes.resolveDescription("STRING1", elementPath);624 return mes;625 } catch (WebDriverException exception) {626 return parseWebDriverException(exception);627 }628 } else if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {629 if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_PICTURE)) {630 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), identifier.getLocator(), "");631 } else if (identifier.getIdentifier().equals(Identifier.IDENTIFIER_TEXT)) {632 return sikuliService.doSikuliVerifyElementNotPresent(execution.getSession(), "", identifier.getLocator());633 } else {634 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION_AND_IDENTIFIER);635 mes.resolveDescription("IDENTIFIER", identifier.getIdentifier());636 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);637 mes.resolveDescription("APPLICATIONTYPE", execution.getAppTypeEngine());638 return mes;639 }640 } else if (execution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {641 if (execution.getLastServiceCalled() != null) {642 String responseBody = execution.getLastServiceCalled().getResponseHTTPBody();643 switch (execution.getLastServiceCalled().getResponseHTTPBodyContentType()) {644 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:645 if (!(xmlUnitService.isElementPresent(responseBody, elementPath))) {646 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);647 } else {648 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);649 }650 mes.resolveDescription("STRING1", elementPath);651 return mes;652 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {653 try {654 //Return of getFromJson can be "[]" in case when the path has this pattern "$..ex" and no elements found. Two dots after $ return a list.655 if (!jsonService.getFromJson(responseBody, null, elementPath).equals("[]")) {656 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);657 mes.resolveDescription("STRING1", elementPath);658 return mes;659 } else {660 throw new PathNotFoundException();661 }662 } catch (PathNotFoundException ex) {663 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);664 mes.resolveDescription("STRING1", elementPath);665 return mes;666 } catch (Exception ex) {667 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);668 mes.resolveDescription("ERROR", ex.toString());669 return mes;670 }671 }672 default:673 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);674 mes.resolveDescription("TYPE", execution.getLastServiceCalled().getResponseHTTPBodyContentType());675 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);676 return mes;677 }678 } else {679 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);680 return mes;681 }682 } else {683 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);684 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT);685 mes.resolveDescription("APPLICATIONTYPE", execution.getAppTypeEngine());686 return mes;687 }688 } else {689 return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT_NULL);690 }691 }692 private MessageEvent verifyElementInElement(TestCaseExecution tCExecution, String element, String childElement) {693 LOG.debug("Control: verifyElementInElement on: '{}' is child of '{}'", element, childElement);694 MessageEvent mes;695 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)696 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {697 if (!StringUtil.isNull(element) && !StringUtil.isNull(childElement)) {698 try {699 Identifier identifier = identifierService.convertStringToIdentifier(element);700 Identifier childIdentifier = identifierService.convertStringToIdentifier(childElement);701 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {702 if (this.webdriverService.isElementInElement(tCExecution.getSession(), identifier, childIdentifier)) {703 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTINELEMENT);704 } else {705 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);706 }707 mes.resolveDescription("STRING2", element);708 mes.resolveDescription("STRING1", childElement);709 } else {710 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NO_SUCH_ELEMENT);711 mes.resolveDescription("SELEX", new NoSuchElementException("").toString());712 mes.resolveDescription("ELEMENT", element);713 }714 } catch (WebDriverException exception) {715 return parseWebDriverException(exception);716 }717 } else {718 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);719 mes.resolveDescription("STRING2", element);720 mes.resolveDescription("STRING1", childElement);721 }722 } else {723 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);724 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT);725 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());726 }727 return mes;728 }729 private MessageEvent verifyElementVisible(TestCaseExecution tCExecution, String html) {730 LOG.debug("Control: verifyElementVisible on: {}", html);731 MessageEvent mes;732 if (!StringUtil.isNull(html)) {733 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)734 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)735 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {736 try {737 Identifier identifier = identifierService.convertStringToIdentifier(html);738 if (this.webdriverService.isElementVisible(tCExecution.getSession(), identifier)) {739 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_VISIBLE);740 } else {741 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE);742 }743 mes.resolveDescription("STRING1", html);744 } catch (WebDriverException exception) {745 return parseWebDriverException(exception);746 }747 } else {748 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);749 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE);750 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());751 }752 } else {753 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE_NULL);754 }755 return mes;756 }757 private MessageEvent verifyElementNotVisible(TestCaseExecution tCExecution, String html) {758 LOG.debug("Control: verifyElementNotVisible on: {}", html);759 MessageEvent mes;760 if (!StringUtil.isNull(html)) {761 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)762 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)763 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {764 try {765 Identifier identifier = identifierService.convertStringToIdentifier(html);766 if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {767 if (this.webdriverService.isElementNotVisible(tCExecution.getSession(), identifier)) {768 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTVISIBLE);769 } else {770 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE);771 }772 mes.resolveDescription("STRING1", html);773 } else {774 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);775 }776 mes.resolveDescription("STRING1", html);777 } catch (WebDriverException exception) {778 return parseWebDriverException(exception);779 }780 } else {781 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);782 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE);783 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());784 }785 } else {786 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE_NULL);787 }788 return mes;789 }790 private MessageEvent verifyElementEquals(TestCaseExecution tCExecution, String xpath, String expectedElement) {791 LOG.debug("Control: verifyElementEquals on: {} expected Element: {}", xpath, expectedElement);792 MessageEvent mes;793 // If case of not compatible application then exit with error794 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {795 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);796 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS);797 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());798 } else if (tCExecution.getLastServiceCalled() != null) {799 // Check if element on the given xpath is equal to the given expected element800 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();801 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {802 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, expectedElement) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTEQUALS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTEQUALS);803 mes.resolveDescription("XPATH", xpath);804 mes.resolveDescription("EXPECTED_ELEMENT", expectedElement);805 } else {806 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);807 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());808 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS);809 }810 } else {811 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);812 }813 return mes;814 }815 private MessageEvent verifyElementDifferent(TestCaseExecution tCExecution, String xpath, String differentElement) {816 LOG.debug("Control: verifyElementDifferent on: {} expected Element: {}", xpath, differentElement);817 MessageEvent mes = null;818 // If case of not compatible application then exit with error819 if (!tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_SRV)) {820 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);821 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT);822 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());823 } else if (tCExecution.getLastServiceCalled() != null) {824 //Check if element on the given xpath is different from the given different element825 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {826 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();827 mes = xmlUnitService.isElementEquals(xmlResponse, xpath, differentElement) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTDIFFERENT);828 mes.resolveDescription("XPATH", xpath);829 mes.resolveDescription("DIFFERENT_ELEMENT", differentElement);830 } else {831 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);832 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());833 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT);834 }835 } else {836 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);837 }838 return mes;839 }840 @Override841 public MessageEvent verifyElementXXX(String control, TestCaseExecution tCExecution, String path, String expected, String isCaseSensitive) {842 LOG.debug("Control: verifyElementXXX ({}) on {} element against value: {} AppType: {}", control, path, expected, tCExecution.getAppTypeEngine());843 MessageEvent mes;844 // Get value from the path element according to the application type845 String actual;846 try {847 Identifier identifier = identifierService.convertStringToIdentifier(path);848 String applicationType = tCExecution.getAppTypeEngine();849 switch (applicationType) {850 case Application.TYPE_GUI:851 case Application.TYPE_APK:852 case Application.TYPE_IPA:853 actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);854 // In case of null actual value then we alert user855 if (actual == null) {856 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);857 mes.resolveDescription("STRING1", path);858 return mes;859 }860 // Get the result depending on the control required.861 mes = switchControl(control, path, actual, expected, isCaseSensitive);862 return mes;863 case Application.TYPE_SRV:864 if (tCExecution.getLastServiceCalled() != null) {865 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();866 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {867 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:868 if (!xmlUnitService.isElementPresent(responseBody, path)) {869 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);870 mes.resolveDescription("ELEMENT", path);871 return mes;872 }873 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");874 actual = xmlUnitService.getFromXml(responseBody, newPath);875 // In case of null actual value then we alert user876 if (actual == null) {877 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NULL);878 mes.resolveDescription("ELEMENT", path);879 return mes;880 }881 // Get the result depending on the control required.882 mes = switchControl(control, path, actual, expected, isCaseSensitive);883 return mes;884 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON: {885 try {886 actual = jsonService.getFromJson(responseBody, null, path);887 } catch (Exception ex) {888 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);889 mes.resolveDescription("ERROR", ex.toString());890 return mes;891 }892 }893 // In case of null actual value then we alert user894 if (actual == null) {895 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);896 mes.resolveDescription("ELEMENT", path);897 return mes;898 }899 // Get the result depending on the control required.900 mes = switchControl(control, path, actual, expected, isCaseSensitive);901 return mes;902 default:903 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);904 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());905 mes.resolveDescription("CONTROL", control);906 return mes;907 }908 } else {909 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);910 return mes;911 }912 default:913 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);914 mes.resolveDescription("CONTROL", control);915 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());916 return mes;917 }918 } catch (NoSuchElementException exception) {919 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);920 mes.resolveDescription("ELEMENT", path);921 return mes;922 } catch (WebDriverException exception) {923 return parseWebDriverException(exception);924 }925 }926 private MessageEvent switchControl(String control, String path, String actual, String expected, String isCaseSensitive) {927 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);928 mes.resolveDescription("CONTROL", "switchControl-" + control);929 switch (control) {930 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTEQUAL:931 mes = verifyElementTextEqualCaseSensitiveCheck(actual, expected, isCaseSensitive);932 break;933 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTDIFFERENT:934 mes = verifyElementTextDifferentCaseSensitiveCheck(actual, expected, isCaseSensitive);935 break;936 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTCONTAINS:937 mes = verifyElementTextContainsCaseSensitiveCheck(actual, expected, isCaseSensitive);938 break;939 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:940 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:941 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:942 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:943 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:944 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:945 double value1;946 try {947 value1 = Double.parseDouble(actual);948 } catch (NumberFormatException nfe) {949 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);950 mes.resolveDescription("COND", control);951 mes.resolveDescription("STRINGVALUE", actual);952 return mes;953 }954 // We try to convert the strings value2 to numeric.955 double value2;956 try {957 value2 = Double.parseDouble(expected);958 } catch (NumberFormatException nfe) {959 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);960 mes.resolveDescription("COND", control);961 mes.resolveDescription("STRINGVALUE", expected);962 return mes;963 }964 mes = checkNumericVerifyElement(control, value1, value2);965 break;966 }967 mes.resolveDescription("ELEMENT", path);968 mes.resolveDescription("ELEMENTVALUE", actual);969 mes.resolveDescription("VALUE", expected);970 mes.resolveDescription("CASESENSITIVE", caseSensitiveMessageValue(isCaseSensitive));971 return mes;972 }973 private MessageEvent verifyElementTextEqualCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {974 MessageEvent mes;975 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {976 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);977 } else {978 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTEQUAL) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTEQUAL);979 }980 return mes;981 }982 private MessageEvent verifyElementTextDifferentCaseSensitiveCheck(String actual, String expected, String isCaseSensitive) {983 MessageEvent mes;984 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {985 mes = actual.equals(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);986 } else {987 mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTDIFFERENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT);988 }989 return mes;990 }991 private MessageEvent verifyElementTextContainsCaseSensitiveCheck(String text, String textToSearch, String isCaseSensitive) {992 MessageEvent mes;993 if (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false)) {994 mes = text.contains(textToSearch) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);995 } else {996 mes = text.toLowerCase().contains(textToSearch.toLowerCase()) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTTEXTCONTAINS) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTTEXTCONTAINS);997 }998 return mes;999 }1000 private MessageEvent checkNumericVerifyElement(String control, Double actual, Double expected) {1001 switch (control) {1002 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICEQUAL:1003 return actual.equals(expected)1004 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICEQUAL)1005 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICEQUAL);1006 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICDIFFERENT:1007 return !actual.equals(expected)1008 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT)1009 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICDIFFERENT);1010 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATER:1011 return actual > expected1012 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATER)1013 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATER);1014 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICGREATEROREQUAL:1015 return actual >= expected1016 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL)1017 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICGREATEROREQUAL);1018 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:1019 return actual < expected1020 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOR)1021 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOR);1022 case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:1023 return actual <= expected1024 ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL)1025 : new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTNUMERICMINOROREQUAL);1026 default:1027 MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1028 return mes.resolveDescription("CONTROL", "checkNumericVerifyElement-" + control);1029 }1030 }1031 private MessageEvent verifyElementTextMatchRegex(TestCaseExecution tCExecution, String path, String regex) {1032 LOG.debug("Control: VerifyElementTextMatchRegex on: {} element against value: {}", path, regex);1033 MessageEvent mes;1034 String pathContent;1035 try {1036 Identifier identifier = identifierService.convertStringToIdentifier(path);1037 String applicationType = tCExecution.getAppTypeEngine();1038 // Get value from the path element according to the application type1039 if (Application.TYPE_GUI.equalsIgnoreCase(applicationType)1040 || Application.TYPE_APK.equalsIgnoreCase(applicationType)1041 || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {1042 pathContent = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);1043 } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {1044 if (tCExecution.getLastServiceCalled() != null) {1045 String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();1046 switch (tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {1047 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:1048 if (!xmlUnitService.isElementPresent(responseBody, path)) {1049 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENT_NOSUCHELEMENT);1050 mes.resolveDescription("ELEMENT", path);1051 return mes;1052 }1053 String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");1054 pathContent = xmlUnitService.getFromXml(responseBody, newPath);1055 break;1056 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:1057 try {1058 pathContent = jsonService.getFromJson(responseBody, null, path);1059 } catch (Exception ex) {1060 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);1061 mes.resolveDescription("ERROR", ex.toString());1062 return mes;1063 }1064 break;1065 default:1066 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1067 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1068 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1069 return mes;1070 }1071 // TODO Give the actual element found into the description.1072 } else {1073 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1074 return mes;1075 }1076 } else {1077 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1078 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTTEXTMATCHREGEX);1079 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1080 return mes;1081 }1082 LOG.debug("Control: VerifyElementMatchRegex element: {} has value: {}", path, StringUtil.sanitize(pathContent));1083 if (path != null && pathContent != null) {1084 try {1085 Pattern pattern = Pattern.compile(regex);1086 Matcher matcher = pattern.matcher(pathContent);1087 if (matcher.find()) {1088 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_REGEXINELEMENT);1089 } else {1090 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT);1091 }1092 mes.resolveDescription("STRING1", path);1093 mes.resolveDescription("STRING2", StringUtil.sanitize(pathContent));1094 mes.resolveDescription("STRING3", regex);1095 } catch (PatternSyntaxException e) {1096 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_INVALIDPATTERN);1097 mes.resolveDescription("PATTERN", regex);1098 mes.resolveDescription("ERROR", e.getMessage());1099 }1100 } else if (pathContent != null) {1101 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NULL);1102 } else {1103 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1104 mes.resolveDescription("ELEMENT", path);1105 }1106 } catch (NoSuchElementException exception) {1107 LOG.debug(exception.toString());1108 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);1109 mes.resolveDescription("ELEMENT", path);1110 } catch (WebDriverException exception) {1111 return parseWebDriverException(exception);1112 }1113 return mes;1114 }1115 private MessageEvent verifyTextInDialog(TestCaseExecution tCExecution, String property, String value) {1116 LOG.debug("Control: verifyTextInDialog against value: {}", value);1117 MessageEvent mes;1118 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1119 try {1120 String str = this.webdriverService.getAlertText(tCExecution.getSession());1121 LOG.debug("Control: verifyTextInAlertPopup has value: {}", str);1122 if (str != null) {1123 String valueToTest = property;1124 if (valueToTest == null || "".equals(valueToTest.trim())) {1125 valueToTest = value;1126 }1127 if (str.trim().equalsIgnoreCase(valueToTest)) {1128 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINALERT);1129 } else {1130 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT);1131 }1132 mes.resolveDescription("STRING1", str);1133 mes.resolveDescription("STRING2", valueToTest);1134 } else {1135 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINALERT_NULL);1136 }1137 } catch (WebDriverException exception) {1138 return parseWebDriverException(exception);1139 }1140 } else {1141 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1142 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG);1143 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1144 }1145 return mes;1146 }1147 private MessageEvent verifyTextInPage(TestCaseExecution tCExecution, String regex) {1148 LOG.debug("Control: verifyTextInPage on : {}", regex);1149 MessageEvent mes;1150 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1151 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1152 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1153 String pageSource;1154 try {1155 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1156 LOG.debug(pageSource);1157 Pattern pattern = Pattern.compile(regex);1158 Matcher matcher = pattern.matcher(pageSource);1159 if (matcher.find()) {1160 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINPAGE);1161 } else {1162 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE);1163 }1164 mes.resolveDescription("STRING1", Pattern.quote(regex));1165 } catch (PatternSyntaxException e) {1166 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINPAGE_INVALIDPATTERN);1167 mes.resolveDescription("PATTERN", Pattern.quote(regex));1168 mes.resolveDescription("ERROR", e.getMessage());1169 } catch (WebDriverException exception) {1170 return parseWebDriverException(exception);1171 }1172 } else if (Application.TYPE_FAT.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1173 mes = sikuliService.doSikuliVerifyTextInPage(tCExecution.getSession(), regex);1174 } else {1175 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1176 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE);1177 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1178 }1179 return mes;1180 }1181 private MessageEvent verifyTextNotInPage(TestCaseExecution tCExecution, String regex) {1182 LOG.debug("Control: VerifyTextNotInPage on: {}", regex);1183 MessageEvent mes;1184 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())1185 || Application.TYPE_APK.equalsIgnoreCase(tCExecution.getAppTypeEngine())1186 || Application.TYPE_IPA.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1187 String pageSource;1188 try {1189 pageSource = this.webdriverService.getPageSource(tCExecution.getSession());1190 LOG.debug(pageSource);1191 Pattern pattern = Pattern.compile(regex);1192 Matcher matcher = pattern.matcher(pageSource);1193 if (!(matcher.find())) {1194 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINPAGE);1195 } else {1196 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE);1197 }1198 mes.resolveDescription("STRING1", Pattern.quote(regex));1199 } catch (PatternSyntaxException e) {1200 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINPAGE_INVALIDPATTERN);1201 mes.resolveDescription("PATTERN", Pattern.quote(regex));1202 mes.resolveDescription("ERROR", e.getMessage());1203 } catch (WebDriverException exception) {1204 return parseWebDriverException(exception);1205 }1206 } else {1207 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1208 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE);1209 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1210 }1211 return mes;1212 }1213 private MessageEvent verifyUrl(TestCaseExecution tCExecution, String value1) throws CerberusEventException {1214 LOG.debug("Control: verifyUrl on: {}", value1);1215 MessageEvent mes;1216 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1217 String url;1218 // Control is made forcing the / at the beginning of URL. getCurrentUrl from Selenium1219 // already have that control but value1 is specified by user and could miss it.1220 final String controlUrl = StringUtil.addPrefixIfNotAlready(value1, "/");1221 try {1222 LOG.debug("Before wait: {}", System.currentTimeMillis());1223 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1224 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1225 //Wait until the url is the expected one1226 wait.until(new Function<WebDriver, Boolean>() {1227 final String expectedValue = controlUrl;1228 @Override1229 public Boolean apply(WebDriver driver) {1230 String value = "";1231 try {1232 value = webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1233 LOG.debug("Get new url: {} >> Expected url: {}", value, expectedValue);1234 } catch (CerberusEventException ex) {1235 LOG.warn(ex.getMessageError().getDescription());1236 }1237 return value.equalsIgnoreCase(expectedValue);1238 }1239 });1240 LOG.debug("After wait: {}", System.currentTimeMillis());1241 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1242 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_URL);1243 mes.resolveDescription("STRING1", url);1244 } catch (TimeoutException exception) {1245 url = this.webdriverService.getCurrentUrl(tCExecution.getSession(), tCExecution.getUrl());1246 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL);1247 mes.resolveDescription("STRING1", url);1248 } catch (WebDriverException exception) {1249 return parseWebDriverException(exception);1250 }1251 mes.resolveDescription("STRING2", controlUrl);1252 } else {1253 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1254 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYURL);1255 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1256 }1257 return mes;1258 }1259 private MessageEvent verifyTitle(TestCaseExecution tCExecution, String title, String isCaseSensitive) {1260 LOG.debug("Control: verifyTitle on: {}", title);1261 MessageEvent mes;1262 if (Application.TYPE_GUI.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1263 String pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1264 try {1265 LOG.debug("Before wait {}", System.currentTimeMillis());1266 WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),1267 TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));1268 //Wait until the title is the expected one1269 wait.until(new Function<WebDriver, Boolean>() {1270 final String expectedValue = title;1271 @Override1272 public Boolean apply(WebDriver driver) {1273 String value = webdriverService.getTitle(tCExecution.getSession());1274 LOG.debug("Get new title: {} >> Expected title: {}", value, expectedValue);1275 return ParameterParserUtil.parseBooleanParam(isCaseSensitive, false) ? expectedValue.equals(value) : expectedValue.equalsIgnoreCase(value);1276 }1277 });1278 LOG.debug("After wait {}", System.currentTimeMillis());1279 pageTitle = this.webdriverService.getTitle(tCExecution.getSession());1280 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TITLE);1281 } catch (TimeoutException exception) {1282 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TITLE);1283 } catch (WebDriverException exception) {1284 return parseWebDriverException(exception);1285 }1286 mes.resolveDescription("STRING1", pageTitle);1287 mes.resolveDescription("STRING2", title);1288 mes.resolveDescription("STRING3", caseSensitiveMessageValue(isCaseSensitive));1289 } else {1290 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1291 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYTITLE);1292 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1293 }1294 return mes;1295 }1296 private MessageEvent verifyXmlTreeStructure(TestCaseExecution tCExecution, String controlProperty, String controlValue) {1297 LOG.debug("Control: verifyXmlTreeStructure on: {}", controlProperty);1298 MessageEvent mes;1299 if (Application.TYPE_SRV.equalsIgnoreCase(tCExecution.getAppTypeEngine())) {1300 try {1301 if (tCExecution.getLastServiceCalled() != null) {1302 if (AppService.RESPONSEHTTPBODYCONTENTTYPE_XML.equals(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType())) {1303 String xmlResponse = tCExecution.getLastServiceCalled().getResponseHTTPBody();1304 if (this.xmlUnitService.isSimilarTree(xmlResponse, controlProperty, controlValue)) {1305 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_SIMILARTREE);1306 } else {1307 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SIMILARTREE);1308 }1309 mes.resolveDescription("STRING1", StringUtil.sanitize(controlProperty));1310 mes.resolveDescription("STRING2", StringUtil.sanitize(controlValue));1311 } else {1312 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);1313 mes.resolveDescription("TYPE", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType());1314 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE);1315 }1316 } else {1317 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);1318 }1319 } catch (Exception exception) {1320 LOG.fatal(exception.toString());1321 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED);1322 }1323 } else {1324 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1325 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE);1326 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1327 }1328 return mes;1329 }1330 private MessageEvent verifyElementClickable(TestCaseExecution tCExecution, String html) {1331 LOG.debug("Control: verifyElementClickable: {}", html);1332 MessageEvent mes;1333 if (!StringUtil.isNull(html)) {1334 Identifier identifier = identifierService.convertStringToIdentifier(html);1335 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1336 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1337 try {1338 if (this.webdriverService.isElementClickable(tCExecution.getSession(), identifier)) {1339 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CLICKABLE);1340 } else {1341 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE);1342 }1343 mes.resolveDescription("ELEMENT", html);1344 } catch (WebDriverException exception) {1345 return parseWebDriverException(exception);1346 }1347 } else {1348 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1349 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE);1350 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1351 }1352 } else {1353 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE_NULL);1354 }1355 return mes;1356 }1357 private MessageEvent verifyElementNotClickable(TestCaseExecution tCExecution, String html) {1358 LOG.debug("Control: verifyElementNotClickable on: {}", html);1359 MessageEvent mes;1360 if (!StringUtil.isNull(html)) {1361 Identifier identifier = identifierService.convertStringToIdentifier(html);1362 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1363 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)) {1364 try {1365 if (this.webdriverService.isElementNotClickable(tCExecution.getSession(), identifier)) {1366 mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCLICKABLE);1367 } else {1368 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE);1369 }1370 mes.resolveDescription("ELEMENT", html);1371 } catch (WebDriverException exception) {1372 return parseWebDriverException(exception);1373 }1374 } else {1375 mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1376 mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE);1377 mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());1378 }1379 } else {1380 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE_NULL);1381 }1382 return mes;1383 }1384 private String caseSensitiveMessageValue(String isCaseSensitive) {1385 return (ParameterParserUtil.parseBooleanParam(isCaseSensitive, false))1386 ? "(case sensitive)"1387 : "(case insensitive)";1388 }1389 private MessageEvent takeScreenshot(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String cropValues) {1390 MessageEvent message;1391 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1392 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1393 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)1394 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_FAT)) {1395 List<TestCaseExecutionFile> file = recorderService.recordScreenshot(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlId(), cropValues);1396 testCaseStepActionControlExecution.addFileList(file);1397 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TAKESCREENSHOT);1398 return message;1399 }1400 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1401 message.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_TAKESCREENSHOT);1402 message.resolveDescription("APPLICATIONTYPE", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine());1403 return message;1404 }1405 private MessageEvent getPageSource(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {1406 MessageEvent message;1407 if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)1408 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)1409 || tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {1410 TestCaseExecutionFile file = recorderService.recordPageSource(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlId());1411 if (file != null) {1412 List<TestCaseExecutionFile> fileList = new ArrayList<>();1413 fileList.add(file);1414 testCaseStepActionControlExecution.setFileList(fileList);1415 }1416 message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GETPAGESOURCE);1417 return message;1418 }1419 message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1420 message.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_TAKESCREENSHOT);1421 message.resolveDescription("APPLICATIONTYPE", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getAppTypeEngine());1422 return message;1423 }1424 /**1425 * @param exception the exception need to be parsed by Cerberus1426 * @return A new Event Message with selenium related description1427 * @author memiks1428 */1429 private MessageEvent parseWebDriverException(WebDriverException exception) {1430 MessageEvent mes;1431 LOG.error(exception.toString(), exception);1432 mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_SELENIUM_CONNECTIVITY);1433 mes.resolveDescription("ERROR", exception.getMessage().split("\n")[0]);1434 return mes;1435 }1436}...

Full Screen

Full Screen

Source:ActionService.java Github

copy

Full Screen

1/**2 * Cerberus Copyright (C) 2013 - 2017 cerberustesting3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4 *5 * This file is part of Cerberus.6 *7 * Cerberus is free software: you can redistribute it and/or modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation, either version 3 of the License, or10 * (at your option) any later version.11 *12 * Cerberus is distributed in the hope that it will be useful,13 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with Cerberus. If not, see <http://www.gnu.org/licenses/>.19 */20package org.cerberus.engine.gwt.impl;21import java.util.ArrayList;22import java.util.Date;23import org.apache.logging.log4j.Logger;24import org.apache.logging.log4j.LogManager;25import org.cerberus.crud.entity.AppService;26import org.cerberus.crud.entity.Application;27import org.cerberus.crud.entity.TestCaseCountryProperties;28import org.cerberus.crud.entity.TestCaseExecution;29import org.cerberus.crud.entity.TestCaseExecutionData;30import org.cerberus.crud.entity.TestCaseStepAction;31import org.cerberus.crud.entity.TestCaseStepActionExecution;32import org.cerberus.crud.factory.IFactoryTestCaseExecutionData;33import org.cerberus.crud.service.IAppServiceService;34import org.cerberus.crud.service.ILogEventService;35import org.cerberus.crud.service.IParameterService;36import org.cerberus.crud.service.ITestCaseExecutionDataService;37import org.cerberus.engine.entity.Identifier;38import org.cerberus.engine.entity.MessageEvent;39import org.cerberus.engine.entity.MessageGeneral;40import org.cerberus.engine.entity.SwipeAction;41import org.cerberus.engine.execution.IIdentifierService;42import org.cerberus.engine.execution.IRecorderService;43import org.cerberus.engine.gwt.IActionService;44import org.cerberus.engine.gwt.IPropertyService;45import org.cerberus.engine.gwt.IVariableService;46import org.cerberus.enums.MessageEventEnum;47import org.cerberus.enums.MessageGeneralEnum;48import org.cerberus.exception.CerberusEventException;49import org.cerberus.exception.CerberusException;50import org.cerberus.service.appium.IAppiumService;51import org.cerberus.service.appservice.IServiceService;52import org.cerberus.service.rest.IRestService;53import org.cerberus.service.sikuli.ISikuliService;54import org.cerberus.service.sikuli.impl.SikuliService;55import org.cerberus.service.soap.ISoapService;56import org.cerberus.service.sql.ISQLService;57import org.cerberus.service.webdriver.IWebDriverService;58import org.cerberus.service.xmlunit.IXmlUnitService;59import org.cerberus.util.StringUtil;60import org.cerberus.util.answer.AnswerItem;61import org.springframework.beans.factory.annotation.Autowired;62import org.springframework.beans.factory.annotation.Qualifier;63import org.springframework.stereotype.Service;64/**65 *66 * @author bcivel67 */68@Service69public class ActionService implements IActionService {70 @Autowired71 private IParameterService parameterService;72 @Autowired73 private IWebDriverService webdriverService;74 @Autowired75 private ISoapService soapService;76 @Autowired77 private IRestService restService;78 @Autowired79 private IAppServiceService appServiceService;80 @Autowired81 private IRecorderService recorderService;82 @Autowired83 private IXmlUnitService xmlUnitService;84 @Autowired85 private ISikuliService sikuliService;86 @Autowired87 private IIdentifierService identifierService;88 @Autowired89 @Qualifier("AndroidAppiumService")90 private IAppiumService androidAppiumService;91 @Autowired92 @Qualifier("IOSAppiumService")93 private IAppiumService iosAppiumService;94 @Autowired95 private ISQLService sqlService;96 @Autowired97 private ILogEventService logEventService;98 @Autowired99 private IVariableService variableService;100 @Autowired101 private IPropertyService propertyService;102 @Autowired103 private IServiceService serviceService;104 @Autowired105 private IFactoryTestCaseExecutionData factoryTestCaseExecutionData;106 @Autowired107 private ITestCaseExecutionDataService testCaseExecutionDataService;108 private static final Logger LOG = LogManager.getLogger(ActionService.class);109 private static final String MESSAGE_DEPRECATED = "[DEPRECATED]";110 @Override111 public TestCaseStepActionExecution doAction(TestCaseStepActionExecution testCaseStepActionExecution) {112 MessageEvent res;113 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();114 AnswerItem<String> answerDecode = new AnswerItem();115 /**116 * Decode the object field before doing the action.117 */118 try {119 // When starting a new action, we reset the property list that was already calculated.120 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());121 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue1(),122 tCExecution, testCaseStepActionExecution, false);123 testCaseStepActionExecution.setValue1((String) answerDecode.getItem());124 if (!(answerDecode.isCodeStringEquals("OK"))) {125 // If anything wrong with the decode --> we stop here with decode message in the action result.126 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Value1"));127 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));128 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());129 testCaseStepActionExecution.setEnd(new Date().getTime());130 LOG.debug("Action interupted due to decode 'Action Value1' Error.");131 return testCaseStepActionExecution;132 }133 } catch (CerberusEventException cex) {134 testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());135 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));136 testCaseStepActionExecution.setEnd(new Date().getTime());137 return testCaseStepActionExecution;138 }139 try {140 // When starting a new action, we reset the property list that was already calculated.141 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());142 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue2(),143 tCExecution, testCaseStepActionExecution, false);144 testCaseStepActionExecution.setValue2((String) answerDecode.getItem());145 if (!(answerDecode.isCodeStringEquals("OK"))) {146 // If anything wrong with the decode --> we stop here with decode message in the action result.147 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Value2"));148 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));149 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());150 testCaseStepActionExecution.setEnd(new Date().getTime());151 LOG.debug("Action interupted due to decode 'Action Value2' Error.");152 return testCaseStepActionExecution;153 }154 } catch (CerberusEventException cex) {155 testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());156 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));157 testCaseStepActionExecution.setEnd(new Date().getTime());158 return testCaseStepActionExecution;159 }160 /**161 * Timestamp starts after the decode. TODO protect when property is162 * null.163 */164 testCaseStepActionExecution.setStart(new Date().getTime());165 String value1 = testCaseStepActionExecution.getValue1();166 String value2 = testCaseStepActionExecution.getValue2();167 String propertyName = testCaseStepActionExecution.getPropertyName();168 LOG.debug("Doing Action : " + testCaseStepActionExecution.getAction() + " with value1 : " + value1 + " and value2 : " + value2);169 // When starting a new action, we reset the property list that was already calculated.170 tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());171 try {172 switch (testCaseStepActionExecution.getAction()) {173 case TestCaseStepAction.ACTION_CLICK:174 res = this.doActionClick(tCExecution, value1, value2);175 break;176 case TestCaseStepAction.ACTION_MOUSELEFTBUTTONPRESS:177 res = this.doActionMouseLeftButtonPress(tCExecution, value1, value2);178 break;179 case TestCaseStepAction.ACTION_MOUSELEFTBUTTONRELEASE:180 res = this.doActionMouseLeftButtonRelease(tCExecution, value1, value2);181 break;182 case TestCaseStepAction.ACTION_DOUBLECLICK:183 res = this.doActionDoubleClick(tCExecution, value1, value2);184 break;185 case TestCaseStepAction.ACTION_RIGHTCLICK:186 res = this.doActionRightClick(tCExecution, value1, value2);187 break;188 case TestCaseStepAction.ACTION_MOUSEOVER:189 res = this.doActionMouseOver(tCExecution, value1, value2);190 break;191 case TestCaseStepAction.ACTION_FOCUSTOIFRAME:192 res = this.doActionFocusToIframe(tCExecution, value1, value2);193 break;194 case TestCaseStepAction.ACTION_FOCUSDEFAULTIFRAME:195 res = this.doActionFocusDefaultIframe(tCExecution);196 break;197 case TestCaseStepAction.ACTION_SWITCHTOWINDOW:198 res = this.doActionSwitchToWindow(tCExecution, value1, value2);199 break;200 case TestCaseStepAction.ACTION_MANAGEDIALOG:201 res = this.doActionManageDialog(tCExecution, value1, value2);202 break;203 case TestCaseStepAction.ACTION_OPENURLWITHBASE:204 res = this.doActionOpenURL(tCExecution, value1, value2, true);205 break;206 case TestCaseStepAction.ACTION_OPENURLLOGIN:207 testCaseStepActionExecution.setValue1(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getCountryEnvironmentParameters().getUrlLogin());208 res = this.doActionUrlLogin(tCExecution);209 break;210 case TestCaseStepAction.ACTION_OPENURL:211 res = this.doActionOpenURL(tCExecution, value1, value2, false);212 break;213 case TestCaseStepAction.ACTION_EXECUTEJS:214 res = this.doActionExecuteJS(tCExecution, value1, value2);215 break;216 case TestCaseStepAction.ACTION_OPENAPP:217 res = this.doActionOpenApp(tCExecution, value1);218 break;219 case TestCaseStepAction.ACTION_CLOSEAPP:220 res = this.doActionCloseApp(tCExecution, value1);221 break;222 case TestCaseStepAction.ACTION_SELECT:223 res = this.doActionSelect(tCExecution, value1, value2);224 break;225 case TestCaseStepAction.ACTION_KEYPRESS:226 res = this.doActionKeyPress(tCExecution, value1, value2);227 break;228 case TestCaseStepAction.ACTION_TYPE:229 res = this.doActionType(tCExecution, value1, value2, propertyName);230 break;231 case TestCaseStepAction.ACTION_HIDEKEYBOARD:232 res = this.doActionHideKeyboard(tCExecution);233 break;234 case TestCaseStepAction.ACTION_SWIPE:235 res = this.doActionSwipe(tCExecution, value1, value2);236 break;237 case TestCaseStepAction.ACTION_WAIT:238 res = this.doActionWait(tCExecution, value1, value2);239 break;240 case TestCaseStepAction.ACTION_WAITVANISH:241 res = this.doActionWaitVanish(tCExecution, value1);242 break;243 case TestCaseStepAction.ACTION_CALLSERVICE:244 res = this.doActionCallService(testCaseStepActionExecution, value1);245 break;246 case TestCaseStepAction.ACTION_EXECUTESQLUPDATE:247 res = this.doActionExecuteSQLUpdate(tCExecution, value1, value2);248 break;249 case TestCaseStepAction.ACTION_EXECUTESQLSTOREPROCEDURE:250 res = this.doActionExecuteSQLStoredProcedure(tCExecution, value1, value2);251 break;252 case TestCaseStepAction.ACTION_CALCULATEPROPERTY:253 res = this.doActionCalculateProperty(testCaseStepActionExecution, value1, value2);254 break;255 case TestCaseStepAction.ACTION_DONOTHING:256 res = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);257 break;258 // DEPRECATED ACTIONS FROM HERE.259 case TestCaseStepAction.ACTION_MOUSEOVERANDWAIT:260 res = this.doActionMouseOverAndWait(tCExecution, value1, value2);261 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());262 logEventService.createForPrivateCalls("ENGINE", "mouseOverAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");263 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action mouseOverAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");264 break;265 case TestCaseStepAction.ACTION_REMOVEDIFFERENCE:266 res = this.doActionRemoveDifference(testCaseStepActionExecution, value1, value2);267 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());268 logEventService.createForPrivateCalls("ENGINE", "removeDifference", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");269 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action removeDifference triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");270 break;271 case TestCaseStepAction.ACTION_GETPAGESOURCE:272 res = this.doActionGetPageSource(testCaseStepActionExecution);273 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());274 logEventService.createForPrivateCalls("ENGINE", "getPageSource", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");275 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action getPageSource triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");276 break;277 case TestCaseStepAction.ACTION_TAKESCREENSHOT:278 res = this.doActionTakeScreenshot(testCaseStepActionExecution);279 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());280 logEventService.createForPrivateCalls("ENGINE", "takeScreenshot", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");281 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action takeScreenshot triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");282 break;283 case TestCaseStepAction.ACTION_CLICKANDWAIT:284 res = this.doActionClickWait(tCExecution, value1, value2);285 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());286 logEventService.createForPrivateCalls("ENGINE", "clickAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");287 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action clickAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");288 break;289 case TestCaseStepAction.ACTION_ENTER:290 res = this.doActionKeyPress(tCExecution, value1, "RETURN");291 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());292 logEventService.createForPrivateCalls("ENGINE", "enter", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");293 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action enter triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");294 break;295 case TestCaseStepAction.ACTION_SELECTANDWAIT:296 res = this.doActionSelect(tCExecution, value1, value2);297 this.doActionWait(tCExecution, StringUtil.NULL, StringUtil.NULL);298 res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());299 logEventService.createForPrivateCalls("ENGINE", "selectAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");300 LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action selectAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");301 break;302 default:303 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKNOWNACTION);304 res.setDescription(res.getDescription().replace("%ACTION%", testCaseStepActionExecution.getAction()));305 }306 } catch (final Exception unexpected) {307 LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);308 res = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", unexpected.getMessage());309 }310 LOG.debug("Result of the action : " + res.getCodeString() + " " + res.getDescription());311 /**312 * In case 1/ the action is flaged as being Forced with a specific313 * return code = PE and 2/ the return of the action is stoping the test314 * --> whatever the return of the action is, we force the return to move315 * forward the test with no screenshot, pagesource.316 */317 if (testCaseStepActionExecution.getForceExeStatus().equals("PE") && res.isStopTest()) {318 res.setDescription(res.getDescription() + " -- Execution forced to continue.");319 res.setDoScreenshot(false);320 res.setGetPageSource(false);321 res.setStopTest(false);322 res.setMessage(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING);323 }324 testCaseStepActionExecution.setActionResultMessage(res);325 /**326 * Determine here the impact of the Action on the full test return code327 * from the ResultMessage of the Action.328 */329 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));330 /**331 * Determine here if we stop the test from the ResultMessage of the332 * Action.333 */334 testCaseStepActionExecution.setStopExecution(res.isStopTest());335 testCaseStepActionExecution.setEnd(new Date().getTime());336 return testCaseStepActionExecution;337 }338 private MessageEvent doActionClick(TestCaseExecution tCExecution, String value1, String value2) {339 String element;340 try {341 /**342 * Get element to use String object if not empty, String property if343 * object empty, throws Exception if both empty)344 */345 element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_CLICK, tCExecution);346 /**347 * Get Identifier (identifier, locator) and check it's valid348 */349 Identifier identifier = identifierService.convertStringToIdentifier(element);350 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {351 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {352 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");353 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {354 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());355 } else {356 identifierService.checkWebElementIdentifier(identifier.getIdentifier());357 return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);358 }359 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {360 identifierService.checkWebElementIdentifier(identifier.getIdentifier());361 return androidAppiumService.click(tCExecution.getSession(), identifier);362 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {363 identifierService.checkWebElementIdentifier(identifier.getIdentifier());364 return iosAppiumService.click(tCExecution.getSession(), identifier);365 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {366 identifierService.checkSikuliIdentifier(identifier.getIdentifier());367 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {368 return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");369 } else {370 return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());371 }372 } else {373 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)374 .resolveDescription("ACTION", "Click")375 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());376 }377 } catch (CerberusEventException ex) {378 LOG.fatal("Error doing Action Click :" + ex);379 return ex.getMessageError();380 }381 }382 private MessageEvent doActionExecuteJS(TestCaseExecution tCExecution, String value1, String value2) {383 MessageEvent message;384 String script = value1;385 String valueFromJS;386 try {387 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {388 valueFromJS = this.webdriverService.getValueFromJS(tCExecution.getSession(), script);389 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_EXECUTEJS);390 message.setDescription(message.getDescription().replace("%SCRIPT%", script));391 message.setDescription(message.getDescription().replace("%VALUE%", valueFromJS));392 return message;393 }394 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);395 message.setDescription(message.getDescription().replace("%ACTION%", "executeJS"));396 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));397 return message;398 } catch (Exception e) {399 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTEJS);400 String messageString = e.getMessage().split("\n")[0];401 message.setDescription(message.getDescription().replace("%EXCEPTION%", messageString));402 LOG.debug("Exception Running JS Script :" + messageString);403 return message;404 }405 }406 private MessageEvent doActionMouseLeftButtonPress(TestCaseExecution tCExecution, String object, String property) {407 MessageEvent message;408 String element;409 try {410 /**411 * Get element to use String object if not empty, String property if412 * object empty, throws Exception if both empty)413 */414 element = getElementToUse(object, property, "mouseLeftButtonPress", tCExecution);415 /**416 * Get Identifier (identifier, locator)417 */418 Identifier identifier = identifierService.convertStringToIdentifier(element);419 identifierService.checkWebElementIdentifier(identifier.getIdentifier());420 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {421 return webdriverService.doSeleniumActionMouseDown(tCExecution.getSession(), identifier);422 }423 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);424 message.setDescription(message.getDescription().replace("%ACTION%", "MouseDown"));425 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));426 return message;427 } catch (CerberusEventException ex) {428 LOG.fatal("Error doing Action MouseDown :" + ex);429 return ex.getMessageError();430 }431 }432 private MessageEvent doActionRightClick(TestCaseExecution tCExecution, String object, String property) {433 MessageEvent message;434 String element;435 try {436 /**437 * Get element to use String object if not empty, String property if438 * object empty, throws Exception if both empty)439 */440 element = getElementToUse(object, property, "rightClick", tCExecution);441 /**442 * Get Identifier (identifier, locator)443 */444 Identifier identifier = identifierService.convertStringToIdentifier(element);445 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {446 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {447 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");448 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {449 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());450 } else {451 identifierService.checkWebElementIdentifier(identifier.getIdentifier());452 return webdriverService.doSeleniumActionRightClick(tCExecution.getSession(), identifier);453 }454 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {455 identifierService.checkSikuliIdentifier(identifier.getIdentifier());456 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {457 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");458 } else {459 return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());460 }461 }462 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);463 message.setDescription(message.getDescription().replace("%ACTION%", "rightClick"));464 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));465 return message;466 } catch (CerberusEventException ex) {467 LOG.fatal("Error doing Action RightClick :" + ex);468 return ex.getMessageError();469 }470 }471 private MessageEvent doActionMouseLeftButtonRelease(TestCaseExecution tCExecution, String object, String property) {472 MessageEvent message;473 String element;474 try {475 /**476 * Get element to use String object if not empty, String property if477 * object empty, throws Exception if both empty)478 */479 element = getElementToUse(object, property, "mouseLeftButtonRelease", tCExecution);480 /**481 * Get Identifier (identifier, locator)482 */483 Identifier identifier = identifierService.convertStringToIdentifier(element);484 identifierService.checkWebElementIdentifier(identifier.getIdentifier());485 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {486 return webdriverService.doSeleniumActionMouseUp(tCExecution.getSession(), identifier);487 }488 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);489 message.setDescription(message.getDescription().replace("%ACTION%", "MouseUp"));490 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));491 return message;492 } catch (CerberusEventException ex) {493 LOG.fatal("Error doing Action MouseUp :" + ex);494 return ex.getMessageError();495 }496 }497 private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) {498 String element;499 try {500 /**501 * Get element to use String object if not empty, String property if502 * object empty, throws Exception if both empty)503 */504 element = getElementToUse(object, property, "switchToWindow", tCExecution);505 /**506 * Get Identifier (identifier, locator)507 */508 Identifier identifier = identifierService.convertStringToIdentifier(element);509 //identifierService.checkWebElementIdentifier(identifier.getIdentifier());510 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {511 return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier);512 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {513 return androidAppiumService.switchToContext(tCExecution.getSession(), identifier);514 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {515 return iosAppiumService.switchToContext(tCExecution.getSession(), identifier);516 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {517 return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator());518 } else {519 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)520 .resolveDescription("ACTION", "SwitchToWindow")521 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());522 }523 } catch (CerberusEventException ex) {524 LOG.fatal("Error doing Action SwitchToWindow :" + ex);525 return ex.getMessageError();526 }527 }528 private MessageEvent doActionManageDialog(TestCaseExecution tCExecution, String object, String property) {529 MessageEvent message;530 String element;531 try {532 /**533 * Get element to use String object if not empty, String property if534 * object empty, throws Exception if both empty)535 */536 element = getElementToUse(object, property, "manageDialog", tCExecution);537 /**538 * Get Identifier (identifier, locator)539 */540 Identifier identifier = identifierService.convertStringToIdentifier(element);541 identifierService.checkWebElementIdentifier(identifier.getIdentifier());542 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {543 return webdriverService.doSeleniumActionManageDialog(tCExecution.getSession(), identifier);544 }545 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);546 message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialog"));547 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));548 return message;549 } catch (CerberusEventException ex) {550 LOG.fatal("Error doing Action ManageDialog :" + ex);551 return ex.getMessageError();552 }553 }554 private MessageEvent doActionClickWait(TestCaseExecution tCExecution, String string1, String string2) {555 MessageEvent message;556 try {557 Identifier identifier = identifierService.convertStringToIdentifier(string1);558 identifierService.checkWebElementIdentifier(identifier.getIdentifier());559 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {560 message = webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);561 if (message.getCodeString().equals("OK")) {562 message = this.doActionWait(tCExecution, string2, null);563 }564 return message;565 }566 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);567 message.setDescription(message.getDescription().replace("%ACTION%", "ClickAndWait"));568 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", string1));569 return message;570 } catch (CerberusEventException ex) {571 LOG.fatal("Error doing Action ClickAndWait :" + ex);572 return ex.getMessageError();573 }574 }575 private MessageEvent doActionDoubleClick(TestCaseExecution tCExecution, String object, String property) {576 MessageEvent message;577 String element;578 try {579 /**580 * Get element to use String object if not empty, String property if581 * object empty, throws Exception if both empty)582 */583 element = getElementToUse(object, property, "doubleClick", tCExecution);584 /**585 * Get Identifier (identifier, locator)586 */587 Identifier identifier = identifierService.convertStringToIdentifier(element);588 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {589 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {590 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");591 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {592 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());593 } else {594 identifierService.checkWebElementIdentifier(identifier.getIdentifier());595 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);596 }597 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)598 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {599 identifierService.checkWebElementIdentifier(identifier.getIdentifier());600 return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);601 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {602 identifierService.checkSikuliIdentifier(identifier.getIdentifier());603 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {604 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");605 } else {606 return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());607 }608 }609 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);610 message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));611 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));612 return message;613 } catch (CerberusEventException ex) {614 LOG.fatal("Error doing Action DoubleClick :" + ex);615 return ex.getMessageError();616 }617 }618 private MessageEvent doActionType(TestCaseExecution tCExecution, String object, String property, String propertyName) {619 try {620 /**621 * Check object and property are not null for GUI/APK/IPA Check622 * property is not null for FAT Application623 */624 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)625 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)626 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {627 if (object == null || property == null) {628 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);629 }630 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {631 if (property == null) {632 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);633 }634 }635 /**636 * Get Identifier (identifier, locator) if object not null637 */638 Identifier identifier = new Identifier();639 if (object != null) {640 identifier = identifierService.convertStringToIdentifier(object);641 }642 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {643 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {644 return sikuliService.doSikuliActionType(tCExecution.getSession(), identifier.getLocator(), property);645 } else {646 identifierService.checkWebElementIdentifier(identifier.getIdentifier());647 return webdriverService.doSeleniumActionType(tCExecution.getSession(), identifier, property, propertyName);648 }649 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {650 return androidAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);651 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {652 return iosAppiumService.type(tCExecution.getSession(), identifier, property, propertyName);653 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {654 String locator = "";655 if (!StringUtil.isNullOrEmpty(object)) {656 identifierService.checkSikuliIdentifier(identifier.getIdentifier());657 locator = identifier.getLocator();658 }659 return sikuliService.doSikuliActionType(tCExecution.getSession(), locator, property);660 } else {661 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)662 .resolveDescription("ACTION", "Type")663 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());664 }665 } catch (CerberusEventException ex) {666 LOG.fatal("Error doing Action Type : " + ex);667 return ex.getMessageError();668 }669 }670 private MessageEvent doActionMouseOver(TestCaseExecution tCExecution, String object, String property) {671 MessageEvent message;672 String element;673 try {674 /**675 * Get element to use String object if not empty, String property if676 * object empty, throws Exception if both empty)677 */678 element = getElementToUse(object, property, "mouseOver", tCExecution);679 /**680 * Get Identifier (identifier, locator)681 */682 Identifier identifier = identifierService.convertStringToIdentifier(element);683 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {684 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {685 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");686 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {687 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());688 } else {689 identifierService.checkWebElementIdentifier(identifier.getIdentifier());690 return webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier);691 }692 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {693 identifierService.checkSikuliIdentifier(identifier.getIdentifier());694 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {695 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");696 } else {697 return sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());698 }699 }700 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);701 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOver"));702 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));703 return message;704 } catch (CerberusEventException ex) {705 LOG.fatal("Error doing Action MouseOver :" + ex);706 return ex.getMessageError();707 }708 }709 private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {710 MessageEvent message;711 try {712 /**713 * Check object is not null714 */715 if (object == null) {716 return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);717 }718 /**719 * Get Identifier (identifier, locator)720 */721 Identifier identifier = identifierService.convertStringToIdentifier(object);722 identifierService.checkWebElementIdentifier(identifier.getIdentifier());723 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {724 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {725 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");726 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {727 message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());728 } else {729 message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier);730 }731 if (message.getCodeString().equals("OK")) {732 message = this.doActionWait(tCExecution, property, null);733 }734 return message;735 }736 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);737 message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));738 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));739 return message;740 } catch (CerberusEventException ex) {741 LOG.fatal("Error doing Action MouseOverAndWait :" + ex);742 return ex.getMessageError();743 }744 }745 private MessageEvent doActionWait(TestCaseExecution tCExecution, String object, String property) {746 MessageEvent message;747 String element;748 long timeToWaitInMs = 0;749 Identifier identifier = null;750 try {751 /**752 * Get element to use String object if not empty, String property if753 * object empty, null if both are empty754 */755 element = getElementToUse(object, property, "wait", tCExecution);756 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)757 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)758 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)759 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { // If application are Selenium or appium based, we have a session and can use it to wait.760 /**761 * if element is integer, set time to that value else Get762 * Identifier (identifier, locator)763 */764 if (StringUtil.isNullOrEmpty(element)) {765 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();766 } else if (StringUtil.isInteger(element)) {767 timeToWaitInMs = Long.valueOf(element);768 } else {769 identifier = identifierService.convertStringToIdentifier(element);770 }771 if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {772 return sikuliService.doSikuliActionWait(tCExecution.getSession(), identifier.getLocator(), "");773 } else if (identifier != null && identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {774 return sikuliService.doSikuliActionWait(tCExecution.getSession(), "", identifier.getLocator());775 } else if (identifier != null) {776 identifierService.checkWebElementIdentifier(identifier.getIdentifier());777 return webdriverService.doSeleniumActionWait(tCExecution.getSession(), identifier);778 } else {779 return this.waitTime(timeToWaitInMs);780 }781 } else { // For any other application we wait for the integer value.782 if (StringUtil.isNullOrEmpty(element)) {783 // Get default wait from parameter784 timeToWaitInMs = tCExecution.getCerberus_action_wait_default();785 } else if (StringUtil.isInteger(element)) {786 timeToWaitInMs = Long.valueOf(element);787 }788 return this.waitTime(timeToWaitInMs);789 }790 } catch (CerberusEventException ex) {791 LOG.fatal("Error doing Action Wait :" + ex);792 return ex.getMessageError();793 }794 }795 private MessageEvent doActionKeyPress(TestCaseExecution tCExecution, String value1, String value2) {796 try {797 String appType = tCExecution.getApplicationObj().getType();798 /**799 * Check object and property are not null For IPA and APK, only800 * value2 (key to press) is mandatory For GUI and FAT, both801 * parameters are mandatory802 */803// if (appType.equalsIgnoreCase(Application.TYPE_APK) || appType.equalsIgnoreCase(Application.TYPE_IPA)) {804 if (StringUtil.isNullOrEmpty(value2)) {805 return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_MISSINGKEY).resolveDescription("APPLICATIONTYPE", appType);806 }807// } else if (appType.equalsIgnoreCase(Application.TYPE_GUI) || appType.equalsIgnoreCase(Application.TYPE_FAT)) {808// if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {809// return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS);810// }811// }812 /**813 * Get Identifier (identifier, locator)814 */815 Identifier objectIdentifier = identifierService.convertStringToIdentifier(value1);816 if (appType.equalsIgnoreCase(Application.TYPE_GUI)) {817 if (objectIdentifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {818 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);819 } else {820 identifierService.checkWebElementIdentifier(objectIdentifier.getIdentifier());821 return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2);822 }823 } else if (appType.equalsIgnoreCase(Application.TYPE_APK)) {824 return androidAppiumService.keyPress(tCExecution.getSession(), value2);825 } else if (appType.equalsIgnoreCase(Application.TYPE_IPA)) {826 return iosAppiumService.keyPress(tCExecution.getSession(), value2);827 } else if (appType.equalsIgnoreCase(Application.TYPE_FAT)) {828 return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);829 } else {830 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)831 .resolveDescription("ACTION", "KeyPress")832 .resolveDescription("APPLICATIONTYPE", appType);833 }834 } catch (CerberusEventException ex) {835 LOG.fatal("Error doing Action KeyPress :" + ex);836 return ex.getMessageError();837 }838 }839 private MessageEvent doActionOpenURL(TestCaseExecution tCExecution, String object, String property, boolean withBase) {840 MessageEvent message;841 String element;842 try {843 /**844 * Get element to use String object if not empty, String property if845 * object empty, throws Exception if both empty)846 */847 element = getElementToUse(object, property, "openUrl[WithBase]", tCExecution);848 /**849 * Get Identifier (identifier, locator)850 */851 Identifier identifier = new Identifier();852 identifier.setIdentifier("url");853 identifier.setLocator(element);854 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {855 return webdriverService.doSeleniumActionOpenURL(tCExecution.getSession(), tCExecution.getUrl(), identifier, withBase);856 }857 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);858 message.setDescription(message.getDescription().replace("%ACTION%", "OpenURL[WithBase]"));859 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));860 return message;861 } catch (CerberusEventException ex) {862 LOG.fatal("Error doing Action OpenUrl :" + ex);863 return ex.getMessageError();864 }865 }866 private MessageEvent doActionOpenApp(TestCaseExecution tCExecution, String value1) {867 MessageEvent message;868 /**869 * Check value1 is not null or empty870 */871 if (value1 == null || "".equals(value1)) {872 return new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENAPP);873 }874 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)875 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {876 return sikuliService.doSikuliActionOpenApp(tCExecution.getSession(), value1);877 }878 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);879 message.setDescription(message.getDescription().replace("%ACTION%", "OpenApp"));880 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));881 return message;882 }883 private MessageEvent doActionCloseApp(TestCaseExecution tCExecution, String value1) {884 MessageEvent message;885 /**886 * Check value1 is not null or empty887 */888 if (value1 == null || "".equals(value1)) {889 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);890 }891 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)892 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {893 return sikuliService.doSikuliActionCloseApp(tCExecution.getSession(), value1);894 }895 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);896 message.setDescription(message.getDescription().replace("%ACTION%", "CloseApp"));897 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));898 return message;899 }900 private MessageEvent doActionWaitVanish(TestCaseExecution tCExecution, String value1) {901 try {902 /**903 * Check value1 is not null or empty904 */905 if (value1 == null || "".equals(value1)) {906 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSEAPP);907 }908 /**909 * Get Identifier (identifier, locator)910 */911 Identifier identifier = identifierService.convertStringToIdentifier(value1);912 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {913 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {914 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");915 } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {916 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());917 } else {918 identifierService.checkWebElementIdentifier(identifier.getIdentifier());919 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);920 }921 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)922 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {923 identifierService.checkWebElementIdentifier(identifier.getIdentifier());924 return webdriverService.doSeleniumActionWaitVanish(tCExecution.getSession(), identifier);925 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {926 identifierService.checkSikuliIdentifier(identifier.getIdentifier());927 if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {928 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), identifier.getLocator(), "");929 } else {930 return sikuliService.doSikuliActionWaitVanish(tCExecution.getSession(), "", identifier.getLocator());931 }932 } else {933 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)934 .resolveDescription("ACTION", "WaitVanish")935 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());936 }937 } catch (CerberusEventException ex) {938 LOG.fatal("Error doing Action KeyPress :" + ex);939 return ex.getMessageError();940 }941 }942 private MessageEvent doActionSelect(TestCaseExecution tCExecution, String value1, String value2) {943 MessageEvent message;944 try {945 /**946 * Check object and property are not null947 */948 if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {949 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT);950 }951 /**952 * Get Identifier (identifier, locator)953 */954 Identifier identifierObject = identifierService.convertStringToIdentifier(value1);955 Identifier identifierValue = identifierService.convertStringToSelectIdentifier(value2);956 identifierService.checkWebElementIdentifier(identifierObject.getIdentifier());957 identifierService.checkSelectOptionsIdentifier(identifierValue.getIdentifier());958 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)959 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)960 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {961 return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierObject, identifierValue);962 }963 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);964 message.setDescription(message.getDescription().replace("%ACTION%", "Select"));965 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));966 return message;967 } catch (CerberusEventException ex) {968 LOG.fatal("Error doing Action Select :" + ex);969 return ex.getMessageError();970 }971 }972 private MessageEvent doActionUrlLogin(TestCaseExecution tCExecution) {973 MessageEvent message;974 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {975 return webdriverService.doSeleniumActionUrlLogin(tCExecution.getSession(), tCExecution.getUrl(), tCExecution.getCountryEnvironmentParameters().getUrlLogin());976 }977 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);978 message.setDescription(message.getDescription().replace("%ACTION%", "UrlLogin"));979 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));980 return message;981 }982 private MessageEvent doActionFocusToIframe(TestCaseExecution tCExecution, String object, String property) {983 MessageEvent message;984 String element;985 try {986 /**987 * Get element to use String object if not empty, String property if988 * object empty, throws Exception if both empty)989 */990 element = getElementToUse(object, property, "focusToIframe", tCExecution);991 /**992 * Get Identifier (identifier, locator)993 */994 Identifier identifier = identifierService.convertStringToIdentifier(element);995 identifierService.checkWebElementIdentifier(identifier.getIdentifier());996 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {997 return webdriverService.doSeleniumActionFocusToIframe(tCExecution.getSession(), identifier);998 }999 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1000 message.setDescription(message.getDescription().replace("%ACTION%", "FocusToIframe"));1001 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1002 return message;1003 } catch (CerberusEventException ex) {1004 LOG.fatal("Error doing Action FocusToIframe :" + ex);1005 return ex.getMessageError();1006 }1007 }1008 private MessageEvent doActionFocusDefaultIframe(TestCaseExecution tCExecution) {1009 MessageEvent message;1010 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {1011 return webdriverService.doSeleniumActionFocusDefaultIframe(tCExecution.getSession());1012 }1013 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1014 message.setDescription(message.getDescription().replace("%ACTION%", "FocusDefaultIframe"));1015 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));1016 return message;1017 }1018 private MessageEvent doActionCallService(TestCaseStepActionExecution testCaseStepActionExecution, String value1) {1019 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);1020 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1021 AnswerItem lastServiceCalledAnswer;1022 lastServiceCalledAnswer = serviceService.callService(value1, null, null, null, null, tCExecution);1023 message = lastServiceCalledAnswer.getResultMessage();1024 if (lastServiceCalledAnswer.getItem() != null) {1025 AppService lastServiceCalled = (AppService) lastServiceCalledAnswer.getItem();1026 tCExecution.setLastServiceCalled(lastServiceCalled);1027 /**1028 * Record the Request and Response in filesystem.1029 */1030 testCaseStepActionExecution.addFileList(recorderService.recordServiceCall(tCExecution, testCaseStepActionExecution, 0, null, lastServiceCalled));1031 }1032 return message;1033 }1034 private MessageEvent doActionTakeScreenshot(TestCaseStepActionExecution testCaseStepActionExecution) {1035 MessageEvent message;1036 if (testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1037 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1038 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1039 recorderService.recordScreenshot(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution(),1040 testCaseStepActionExecution, 0);1041 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TAKESCREENSHOT);1042 return message;1043 } else if (testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {1044 /**1045 * TODO Implement screenshot for FAT client application1046 */1047 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1048 }1049 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1050 message.setDescription(message.getDescription().replace("%ACTION%", "TakeScreenShot"));1051 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType()));1052 return message;1053 }1054 private MessageEvent doActionGetPageSource(TestCaseStepActionExecution testCaseStepActionExecution) {1055 MessageEvent message;1056 if (testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)1057 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)1058 || testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {1059 recorderService.recordPageSource(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution(), testCaseStepActionExecution, 0);1060 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_GETPAGESOURCE);1061 return message;1062 }1063 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);1064 message.setDescription(message.getDescription().replace("%ACTION%", "getPageSource"));1065 message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType()));1066 return message;1067 }1068 private MessageEvent doActionRemoveDifference(TestCaseStepActionExecution testCaseStepActionExecution, String object, String property) {1069 // Filters differences from the given object pattern1070 String filteredDifferences = xmlUnitService.removeDifference(object, property);1071 // If filtered differences are null then service has returned with errors1072 if (filteredDifferences == null) {1073 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_REMOVEDIFFERENCE);1074 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1075 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1076 return message;1077 }1078 // Sets the property value to the new filtered one1079 for (TestCaseExecutionData data : testCaseStepActionExecution.getTestCaseExecutionDataList()) {1080 if (data.getProperty().equals(testCaseStepActionExecution.getPropertyName())) {1081 data.setValue(filteredDifferences);1082 break;1083 }1084 }1085 // Sends success1086 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_REMOVEDIFFERENCE);1087 message.setDescription(message.getDescription().replace("%DIFFERENCE%", object));1088 message.setDescription(message.getDescription().replace("%DIFFERENCES%", property));1089 return message;1090 }1091 private MessageEvent doActionCalculateProperty(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2) {1092 MessageEvent message;1093 AnswerItem<String> answerDecode = new AnswerItem();1094 if (StringUtil.isNullOrEmpty(value1)) {1095 // Value1 is a mandatory parameter.1096 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_MISSINGPROPERTY);1097 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY));1098 } else {1099 try {1100 TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();1101 // Getting the Country property definition.1102 TestCaseCountryProperties tccp = null;1103 boolean propertyExistOnAnyCountry = false;1104 for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {1105 if ((object.getProperty().equalsIgnoreCase(value1)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {1106 tccp = object;1107 }1108 if ((object.getProperty().equalsIgnoreCase(value1))) {1109 propertyExistOnAnyCountry = true;1110 }1111 }1112 if (tccp == null) { // Could not find a country property inside the existing execution.1113 if (propertyExistOnAnyCountry) {1114 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);1115 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1116 .replace("%PROP%", value1)1117 .replace("%COUNTRY%", tCExecution.getCountry()));1118 return message;1119 } else {1120 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);1121 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1122 .replace("%PROP%", value1)1123 .replace("%COUNTRY%", tCExecution.getCountry()));1124 return message;1125 }1126 } else {1127 if (!(StringUtil.isNullOrEmpty(value2))) {1128 // If value2 is fed with something, we control here that value is a valid property name and gets its defintion.1129 tccp = null;1130 propertyExistOnAnyCountry = false;1131 for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {1132 if ((object.getProperty().equalsIgnoreCase(value2)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {1133 tccp = object;1134 }1135 if ((object.getProperty().equalsIgnoreCase(value2))) {1136 propertyExistOnAnyCountry = true;1137 }1138 }1139 if (tccp == null) { // Could not find a country property inside the existing execution.1140 if (propertyExistOnAnyCountry) {1141 message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);1142 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1143 .replace("%PROP%", value2)1144 .replace("%COUNTRY%", tCExecution.getCountry()));1145 return message;1146 } else {1147 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);1148 message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY)1149 .replace("%PROP%", value2)1150 .replace("%COUNTRY%", tCExecution.getCountry()));1151 return message;1152 }1153 }1154 }1155 // We calculate the property here.1156 long now = new Date().getTime();1157 TestCaseExecutionData tcExeData;1158 tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), tccp.getProperty(), 1, tccp.getDescription(), null, tccp.getType(),1159 tccp.getValue1(), tccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING),1160 tccp.getRetryNb(), tccp.getRetryPeriod(), tccp.getDatabase(), tccp.getValue1(), tccp.getValue2(), tccp.getLength(), tccp.getLength(),1161 tccp.getRowLimit(), tccp.getNature(), "", "", "", "", "", "N");1162 tcExeData.setTestCaseCountryProperties(tccp);1163 propertyService.calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, tccp, true);1164 // Property message goes to Action message.1165 message = tcExeData.getPropertyResultMessage();1166 if (message.getCodeString().equals("OK")) {1167 // If Property calculated successfully we summarize the message to a shorter version.1168 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALCULATEPROPERTY);1169 message.setDescription(message.getDescription()1170 .replace("%PROP%", value1)1171 .replace("%VALUE%", tcExeData.getValue()));1172 if (tcExeData.getDataLibRawData() != null) {1173 message.setDescription(message.getDescription() + " %NBROWS% row(s) with %NBSUBDATA% Subdata(s) calculated."1174 .replace("%NBROWS%", String.valueOf(tcExeData.getDataLibRawData().size()))1175 .replace("%NBSUBDATA%", String.valueOf(tcExeData.getDataLibRawData().get(0).size())));1176 }1177 }1178 if (!(StringUtil.isNullOrEmpty(value2))) {1179 // If value2 is fed we force the result to value1.1180 tcExeData.setProperty(value1);1181 }1182 //saves the result 1183 try {1184 testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));1185 LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + tcExeData.getIndex() + "' Value : '" + tcExeData.getValue() + "'");1186 tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);1187 if (tcExeData.getDataLibRawData() != null) { // If the property is a TestDataLib, we same all rows retreived in order to support nature such as NOTINUSe or RANDOMNEW.1188 for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {1189 now = new Date().getTime();1190 TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1),1191 tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), "", "",1192 tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", "", "", "", "", "", "N");1193 testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));1194 }1195 }1196 } catch (CerberusException cex) {1197 LOG.error(cex.getMessage(), cex);1198 }1199 }1200 } catch (Exception ex) {1201 LOG.error(ex.toString(), ex);1202 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", ex.toString());1203 }1204 }1205 return message;1206 }1207 private String getElementToUse(String value1, String value2, String action, TestCaseExecution tCExecution) throws CerberusEventException {1208 if (!StringUtil.isNullOrEmpty(value1)) {1209 return value1;1210 } else if (!StringUtil.isNullOrEmpty(value2)) {1211 logEventService.createForPrivateCalls("ENGINE", action, MESSAGE_DEPRECATED + " Beware, in future release, it won't be allowed to use action without using field value1. Triggered by TestCase : ['" + tCExecution.getTest() + "'|'" + tCExecution.getTestCase() + "'] Property : " + value2);1212 LOG.warn(MESSAGE_DEPRECATED + " Action : " + action + ". Beware, in future release, it won't be allowed to use action without using field value1. Triggered by TestCase : ['" + tCExecution.getTest() + "'|'" + tCExecution.getTestCase() + "'] Property : " + value2);1213 return value2;1214 }1215 if (!(action.equals("wait"))) { // Wait is the only action can be excuted with no parameters. For all other actions we raize an exception as this should never happen.1216 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_NO_ELEMENT_TO_PERFORM_ACTION);1217 message.setDescription(message.getDescription().replace("%ACTION%", action));1218 throw new CerberusEventException(message);1219 }1220 return null;1221 }1222 private MessageEvent waitTime(Long timeToWaitMs) {1223 MessageEvent message;1224 /**1225 * if timeToWait is null, throw CerberusException1226 */1227 if (timeToWaitMs == 0) {1228 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_INVALID_FORMAT);1229 return message;1230 }1231 try {1232 LOG.debug("TIME TO WAIT = " + timeToWaitMs);1233 Thread.sleep(timeToWaitMs);1234 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME);1235 message.setDescription(message.getDescription().replace("%TIME%", String.valueOf(timeToWaitMs)));1236 return message;1237 } catch (InterruptedException exception) {1238 LOG.info(exception.toString());1239 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT);1240 message.setDescription(message.getDescription()1241 .replace("%TIME%", String.valueOf(timeToWaitMs))1242 .replace("%MESSAGE%", exception.toString()));1243 return message;1244 }1245 }1246 private MessageEvent doActionExecuteSQLUpdate(TestCaseExecution tCExecution, String object, String property) {1247 return sqlService.executeUpdate(tCExecution.getApplicationObj().getSystem(),1248 tCExecution.getCountry(), tCExecution.getEnvironment(), object, property);1249 }1250 private MessageEvent doActionExecuteSQLStoredProcedure(TestCaseExecution tCExecution, String object, String property) {1251 return sqlService.executeCallableStatement(tCExecution.getApplicationObj().getSystem(),1252 tCExecution.getCountry(), tCExecution.getEnvironment(), object, property);1253 }1254 private MessageEvent doActionHideKeyboard(TestCaseExecution tCExecution) {1255 // Check argument1256 if (tCExecution == null) {1257 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);1258 }1259 // Hide keyboard according to application type1260 String applicationType = tCExecution.getApplicationObj().getType();1261 if (Application.TYPE_APK.equals(applicationType)) {1262 return androidAppiumService.hideKeyboard(tCExecution.getSession());1263 }1264 if (Application.TYPE_IPA.equals(applicationType)) {1265 return iosAppiumService.hideKeyboard(tCExecution.getSession());1266 }1267 // Else we are faced with a non supported application1268 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1269 .resolveDescription("ACTION", "Hide keyboard")1270 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1271 }1272 private MessageEvent doActionSwipe(TestCaseExecution tCExecution, String object, String property) {1273 // Check arguments1274 if (tCExecution == null || object == null) {1275 return new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE);1276 }1277 // Create the associated swipe action to the given arguments1278 SwipeAction action = null;1279 try {1280 action = SwipeAction.fromStrings(object, property);1281 } catch (Exception e) {1282 return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE)1283 .resolveDescription("DIRECTION", action == null ? "Unknown" : action.getActionType().name())1284 .resolveDescription("REASON", e.getMessage());1285 }1286 // Swipe screen according to the application type1287 String applicationType = tCExecution.getApplicationObj().getType();1288 if (Application.TYPE_APK.equals(applicationType)) {1289 return androidAppiumService.swipe(tCExecution.getSession(), action);1290 }1291 if (Application.TYPE_IPA.equals(applicationType)) {1292 return iosAppiumService.swipe(tCExecution.getSession(), action);1293 }1294 // Else we are faced with a non supported application1295 return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)1296 .resolveDescription("ACTION", "Swipe screen")1297 .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());1298 }1299}...

Full Screen

Full Screen

takeScreenShot

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.webdriver.impl;2import java.io.File;3import java.io.IOException;4import java.text.DateFormat;5import java.text.SimpleDateFormat;6import java.util.Date;7import org.apache.commons.logging.Log;8import org.apache.commons.logging.LogFactory;9import org.cerberus.engine.entity.MessageEvent;10import org.cerberus.engine.entity.MessageGeneral;11import org.cerberus.engine.entity.MessageGeneralEnum;12import org.cerberus.engine.execution.IRecorderService;13import org.cerberus.engine.execution.impl.RecorderService;14import org.cerberus.exception.CerberusException;15import org.cerberus.service.webdriver.IWebDriverService;16import org.cerberus.util.StringUtil;17import org.openqa.selenium.OutputType;18import org.openqa.selenium.TakesScreenshot;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebDriverException;21import org.springframework.beans.factory.annotation.Autowired;22import org.springframework.stereotype.Service;23public class WebDriverService implements IWebDriverService {24 IRecorderService recorderService;25 private static final Log LOG = LogFactory.getLog(WebDriverService.class);26 public MessageEvent takeScreenShot(WebDriver driver, String folder, String filename) {27 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);28 try {29 TakesScreenshot scrShot = ((TakesScreenshot) driver);30 File SrcFile = scrShot.getScreenshotAs(OutputType.FILE);31 File DestFile = new File(folder + filename);32 org.apache.commons.io.FileUtils.copyFile(SrcFile, DestFile);33 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TAKESCREENSHOT);34 message.setDescription(message.getDescription().replace("%SCREENSHOTURL%", DestFile.getAbsolutePath()));35 message.setDescription(message.getDescription().replace("%SCREENSHOTPATH%", folder));36 message.setDescription(message.getDescription().replace("%SCREENSHOTNAME%", filename));37 message.setDescription(message.getDescription().replace("%SCREENSHOT%", filename));38 message.setDescription(message.getDescription().replace("%SCREENSHOTEXT%", "png"));39 } catch (WebDriverException e) {40 LOG.error("Unable to take screenshot : " + e.toString());41 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TAKESCREENSHOT).resolveDescription("WebDriverException", e.toString());42 } catch (IOException e) {43 LOG.error("

Full Screen

Full Screen

takeScreenShot

Using AI Code Generation

copy

Full Screen

1package com.cerberus;2import java.io.File;3import java.io.IOException;4import org.apache.commons.io.FileUtils;5import org.cerberus.engine.entity.MessageEvent;6import org.cerberus.engine.entity.MessageGeneral;7import org.cerberus.engine.entity.Session;8import org.cerberus.engine.execution.IExecutionHandlerService;9import org.cerberus.exception.CerberusEventException;10import org.cerberus.exception.CerberusException;11import org.cerberus.service.webdriver.impl.WebDriverService;12import org.openqa.selenium.WebDriver;13import org.springframework.beans.factory.annotation.Autowired;14import org.springframework.stereotype.Service;15public class ScreenShotService {16 private WebDriverService webDriverService;17 private IExecutionHandlerService executionHandlerService;18 public void takeScreenShot(String path, String fileName) throws CerberusException {19 WebDriver driver = null;20 try {21 driver = webDriverService.getDriver();22 File scrFile = ((org.openqa.selenium.TakesScreenshot) driver).getScreenshotAs(org.openqa.selenium.OutputType.FILE);23 FileUtils.copyFile(scrFile, new File(path + fileName));24 } catch (IOException ex) {25 throw new CerberusEventException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_ERROR_SCREENSHOT));26 } catch (CerberusEventException ex) {27 executionHandlerService.handleException(new Session(), ex);28 } finally {29 if (driver != null) {30 driver.quit();31 }32 }33 }34}35package com.cerberus;36import java.io.IOException;37import org.cerberus.engine.entity.Session;38import org.cerberus.engine.execution.IExecutionHandlerService;39import org.cerberus.exception.CerberusEventException;40import org.cerberus.exception.CerberusException;41import org.springframework.beans.factory.annotation.Autowired;42import org.springframework.stereotype.Service;43public class ScreenShotService {44 private WebDriverService webDriverService;45 private IExecutionHandlerService executionHandlerService;46 public void takeScreenShot(String path, String fileName) throws CerberusException {47 WebDriver driver = null;48 try {49 driver = webDriverService.getDriver();50 File scrFile = ((org.openqa.selenium.Takes

Full Screen

Full Screen

takeScreenShot

Using AI Code Generation

copy

Full Screen

1public void testTakeScreenShot() {2 WebDriver driver = WebDriverFactory.getDriver("chrome");3 WebDriverService.takeScreenShot(driver, "testTakeScreenShot", "1");4 driver.quit();5}6public void testTakeScreenShot() {7 WebDriver driver = WebDriverFactory.getDriver("chrome");8 WebDriverService.takeScreenShot(driver, "testTakeScreenShot", "1", "png");9 driver.quit();10}11public void testTakeScreenShot() {12 WebDriver driver = WebDriverFactory.getDriver("chrome");13 WebDriverService.takeScreenShot(driver, "testTakeScreenShot", "1", "png", "C:\\Users\\user\\Desktop\\");14 driver.quit();15}16public void testTakeScreenShot() {17 WebDriver driver = WebDriverFactory.getDriver("chrome");18 WebDriverService.takeScreenShot(driver, "testTakeScreenShot", "1", "png", "C:\\Users\\user\\Desktop\\", "test");19 driver.quit();20}21public void testTakeScreenShot() {22 WebDriver driver = WebDriverFactory.getDriver("chrome");23 WebDriverService.takeScreenShot(driver, "testTakeScreenShot", "1", "png", "C:\\Users\\user\\Desktop\\", "test", "test");24 driver.quit();25}26public void testTakeScreenShot() {27 WebDriver driver = WebDriverFactory.getDriver("chrome");28 WebDriverService.takeScreenShot(driver, "testTake

Full Screen

Full Screen

takeScreenShot

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.webdriver.impl;2import org.cerberus.service.webdriver.IWebDriverService;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.support.events.EventFiringWebDriver;5public class WebDriverService implements IWebDriverService {6 public String takeScreenShot(WebDriver driver, String fileName) {7 String path = "";8 try {9 EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(driver);10 path = eventFiringWebDriver.getScreenshotAs(fileName);11 } catch (Exception ex) {12 System.out.println("Exception while taking screenshot: " + ex.getMessage());13 }14 return path;15 }16}17package org.cerberus.service.webdriver.impl;18import org.cerberus.service.webdriver.IWebDriverService;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.support.events.EventFiringWebDriver;21public class WebDriverService implements IWebDriverService {22 public String takeScreenShot(WebDriver driver, String fileName) {23 String path = "";24 try {25 EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(driver);26 path = eventFiringWebDriver.getScreenshotAs(fileName);27 } catch (Exception ex) {28 System.out.println("Exception while taking screenshot: " + ex.getMessage());29 }30 return path;31 }32}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful