Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Master changes #2525

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ private MessageEvent evaluateControlIfNumericXXX(String control, String controlV
} catch (NumberFormatException nfe) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);
mes.resolveDescription("COND", control);
mes.resolveDescription("STRINGVALUE", newControlValue1);
mes.resolveDescription("NEWSTRING", newControlValue1);
mes.resolveDescription("STRINGVALUE", controlValue1);
return mes;
}

Expand All @@ -579,7 +580,8 @@ private MessageEvent evaluateControlIfNumericXXX(String control, String controlV
} catch (NumberFormatException nfe) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);
mes.resolveDescription("COND", control);
mes.resolveDescription("STRINGVALUE", newControlValue2);
mes.resolveDescription("NEWSTRING", newControlValue2);
mes.resolveDescription("STRINGVALUE", controlValue2);
return mes;
}

Expand Down Expand Up @@ -1204,22 +1206,26 @@ private MessageEvent switchControl(String control, String path, String actual, S
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOR:
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNUMERICMINOROREQUAL:
double value1;
String actualCleaned = StringUtil.prepareToNumeric(actual);
try {
value1 = Double.parseDouble(actual);
value1 = Double.parseDouble(actualCleaned);
} catch (NumberFormatException nfe) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);
mes.resolveDescription("COND", control);
mes.resolveDescription("NEWSTRING", actualCleaned);
mes.resolveDescription("STRINGVALUE", actual);
return mes;
}

// We try to convert the strings value2 to numeric.
double value2;
String expectedCleaned = StringUtil.prepareToNumeric(expected);
try {
value2 = Double.parseDouble(expected);
value2 = Double.parseDouble(expectedCleaned);
} catch (NumberFormatException nfe) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VALUES_NOTNUMERIC);
mes.resolveDescription("COND", control);
mes.resolveDescription("NEWSTRING", expectedCleaned);
mes.resolveDescription("STRINGVALUE", expected);
return mes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ public enum MessageEventEnum {
ACTION_SUCCESS_WAIT_TIME_WITHWARNINGS(200, "OK", "Waited %TIME% ms with warning : %MESSAGE%", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_WAIT_ELEMENT(200, "OK", "Waited for %ELEMENT%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_WAITVANISH_ELEMENT(200, "OK", "Waited for %ELEMENT% to disappear.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_KEYPRESS(200, "OK", "Keypress '%DATA%' done with modifier '%MODIFIER%' on element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_KEYPRESS_NO_ELEMENT(200, "OK", "Key '%KEY%' pressed with success.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_KEYPRESS(200, "OK", "Key '%KEY%' pressed with success with modifier '%MODIFIER%' on element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_KEYPRESS_NO_ELEMENT_NO_MODIFIER(200, "OK", "Key '%KEY%' pressed with success.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_KEYPRESS_NO_MODIFIER(200, "OK", "Key '%KEY%' pressed with success on element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_OPENURL(200, "OK", "Opened URL '%URL%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_SELECT(200, "OK", "Element '%ELEMENT%' selected with '%DATA%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_CALCULATEPROPERTY(200, "OK", "Property '%PROP%' has been calculated with value '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
Expand Down Expand Up @@ -264,7 +265,8 @@ public enum MessageEventEnum {
ACTION_FAILED_KEYPRESS_MISSINGKEY(264, "FA", "KeyValue in value 2 is mandatory in order to perform the action.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_KEYPRESS_ENV_ERROR(264, "FA", "Environment configurations don't allow you to perform the KeyPress operation.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_KEYPRESS_NOT_AVAILABLE(264, "FA", "KeyPress failed! %KEY% is not available.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_KEYPRESS_OTHER(264, "FA", "Keypress '%DATA%' with modifier '%MODIFIER%' on element '%ELEMENT%' failed due to '%REASON%'.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_KEYPRESS_OTHER(264, "FA", "Keypress '%KEY%' with modifier '%MODIFIER%' on element '%ELEMENT%' failed due to '%REASON%'.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_KEYPRESS_OTHER_NOELEMENT_NOMODIFIER(264, "FA", "Keypress '%KEY%' failed due to '%REASON%'.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_OPENURL(265, "FA", "Failed to open '%URL%'.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_OPENURL_TIMEOUT(265, "FA", "Failed to open '%URL%'. Timeout of %TIMEOUT% milliseconds exceeded.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_CLEANROBOTFILE(265, "FA", "Failed to clean robot file. Please check that action is set correctly.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
Expand Down Expand Up @@ -411,7 +413,7 @@ public enum MessageEventEnum {
CONTROL_FAILED_FATAL(352, "KO", "Fatal Control Failed", true, true, false, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_NO_SUCH_ELEMENT(353, "FA", "Element '%ELEMENT%' doesn't exist. Selenium Exception : %SELEX%.", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_SELENIUM_CONNECTIVITY(354, "CA", "The test case is cancelled due to lost connection to Selenium Server! Detailed error : %ERROR%", true, true, true, MessageGeneralEnum.EXECUTION_FA_CONNECTIVITY),
CONTROL_FAILED_VALUES_NOTNUMERIC(355, "KO", "'%STRINGVALUE%' is not numeric, can not compare non numeric values!", true, false, false, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_VALUES_NOTNUMERIC(355, "KO", "'%STRINGVALUE%' (transformed to %NEWSTRING%) is not numeric, can not compare non numeric values!", true, false, false, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_URL_NOT_MATCH_APPLICATION(356, "FA", "Cannot find application host '%HOST%' inside current URL '%CURRENTURL%'. Maybe this is due to a redirection done on the web site. That can be corrected by modifying the application URL.", true, true, false, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_EQUAL(357, "KO", "'%STRING1%' is not equal to '%STRING2%'.", true, true, false, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_STRINGEQUAL(357, "KO", "'%STRING1%' is not equal to '%STRING2%' %STRING3%.", true, true, false, MessageGeneralEnum.EXECUTION_KO),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public MessageEvent keyPress(Session session, String keyName) {
// Then press the key
try {
((PressesKey) session.getAppiumDriver()).pressKey(new KeyEvent(AndroidKey.valueOf(keyName)));
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT).resolveDescription("KEY", keyName);
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT_NO_MODIFIER).resolveDescription("KEY", keyName);

} catch (IllegalArgumentException e) {
return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE).resolveDescription("KEY", keyName);

} catch (Exception e) {
LOG.warn("Unable to key press due to " + e.getMessage(), e);
return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER)
return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER_NOELEMENT_NOMODIFIER)
.resolveDescription("KEY", keyName)
.resolveDescription("REASON", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public MessageEvent keyPress(Session session, String keyName) {
// Then do the key press
try {
session.getAppiumDriver().getKeyboard().pressKey(keyToPress.getCode());
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT).resolveDescription("KEY", keyName);
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT_NO_MODIFIER).resolveDescription("KEY", keyName);
} catch (Exception e) {
LOG.warn("Unable to key press due to " + e.getMessage());
return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER)
return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER_NOELEMENT_NOMODIFIER)
.resolveDescription("KEY", keyName)
.resolveDescription("REASON", e.getMessage());
}
Expand All @@ -116,7 +116,7 @@ public MessageEvent keyPress(Session session, String keyName) {
@Override
public MessageEvent hideKeyboard(Session session) {
MessageEvent keyPressResult = keyPress(session, KeyCode.RETURN.name());
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT.equals(keyPressResult.getSource())
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT_NO_MODIFIER.equals(keyPressResult.getSource())
? MessageEventEnum.ACTION_SUCCESS_HIDEKEYBOARD
: MessageEventEnum.ACTION_FAILED_HIDEKEYBOARD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,14 @@ public MessageEvent doSikuliActionKeyPress(Session session, String locator, Stri
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_SUCCESS).getCodeString())) {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS)
.resolveDescription("ELEMENT", locator)
.resolveDescription("DATA", textToKey)
.resolveDescription("KEY", textToKey)
.resolveDescription("MODIFIER", modifier);
return message;
}
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_FAILED).getCodeString())) {
MessageEvent mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_OTHER)
.resolveDescription("ELEMENT", locator)
.resolveDescription("DATA", textToKey)
.resolveDescription("KEY", textToKey)
.resolveDescription("MODIFIER", modifier)
.resolveDescription("REASON", actionResult.getMessageDescription());
return mes;
Expand Down Expand Up @@ -807,7 +807,7 @@ public MessageEvent doSikuliEndExecution(Session session) {
AnswerItem<JSONObject> actionResult = doSikuliAction(session, SikuliService.SIKULI_ENDEXECUTION, null, null, "", "");

if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_SUCCESS).getCodeString())) {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS);
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_ENDEXECUTION);
return message;
}
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_FAILED).getCodeString())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,9 +1337,9 @@ public MessageEvent doSeleniumActionKeyPress(Session session, Identifier identif
WebElement webElement = (WebElement) answer.getItem();
if (webElement != null) {
webElement.sendKeys(Keys.valueOf(keyToPress));
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS);
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_MODIFIER);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
message.setDescription(message.getDescription().replace("%DATA%", keyToPress));
message.setDescription(message.getDescription().replace("%KEY%", keyToPress));
return message;
}

Expand Down Expand Up @@ -1374,10 +1374,10 @@ public MessageEvent doSeleniumActionKeyPress(Session session, Identifier identif
Duration mydur = Duration.ofMillis(TIMEOUT_WEBELEMENT);
wait.withTimeout(mydur);

message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT);
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT_NO_MODIFIER).resolveDescription("%KEY%", keyToPress);
} else {
//the key enterer is not valid
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE);
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE).resolveDescription("%KEY%", keyToPress);
LOG.debug("Key " + keyToPress + " is not available in the current context");
}

Expand Down
20 changes: 17 additions & 3 deletions source/src/main/java/org/cerberus/core/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,24 @@ public static boolean isBoolean(String str) {
* get converted to float. For ex, it replace , with .
*/
public static String prepareToNumeric(String str) {
if (str.contains(",")) {
return str.replace(",", ".");
String result = str.replaceAll("[^0-9.,]", "");
if (result.contains(",")) {
result = result.replace(",", ".");
}
return str;
int i = 0;
while (nbChars(result, ".") > 1 && i++ < 100) {
result = result.replaceFirst("\\.", "");
LOG.debug("replaced " + result);
}
LOG.debug("Cleaned string from {} to {}", str, result);

return result;
}

public static int nbChars(String str, String substr) {
LOG.debug(str.length() - str.replace(substr, "").length());
return str.length() - str.replace(substr, "").length();

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Allow multiple extraParameters on robot chrome (space seperator).
* Added %system.ROBOTSESSIONID% and %system.ROBOTPROVIDERSESSIONID% system variable.
* Allow to have optional subdata and feed cerberus_testdatalib_subdataDefaultValue parameter to defined its default value (Thanks to Promod team ;-)).
* Make Numeric conversion more robust (ex : 'EUR 123 123.5 €' will be converted to 123123.5 before performing the control)

*Warning to be considered before applying the version (deprecated features)*
[square]
Expand Down
Loading