Skip to content

Commit

Permalink
Fixed an issue generating action FA on mouseOver with no offset defined.
Browse files Browse the repository at this point in the history
Better error messages on mouseMove and mouseOver. Better tune autocomplete on those 2 actions.
  • Loading branch information
vertigo17 committed Feb 13, 2025
1 parent 344a715 commit 75fb1df
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public enum MessageEventEnum {
ACTION_SUCCESS_DOUBLECLICK(200, "OK", "Element '%ELEMENT%' double clicked.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_RIGHTCLICK(200, "OK", "Right click has been done on Element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_URLLOGIN(200, "OK", "Opened '%URL%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_MOUSEOVER(200, "OK", "Mouse moved over '%ELEMENT%' with an offset %OFFSET%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_MOUSEOVER(200, "OK", "Mouse moved over '%ELEMENT%' with an offset '%OFFSET%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_MOUSEMOVE(200, "OK", "Mouse moved with coord '%COORD%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_SUCCESS_WAIT_TIME(200, "OK", "Waited %TIME% ms.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
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),
Expand Down Expand Up @@ -287,6 +288,8 @@ public enum MessageEventEnum {
ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT(268, "FA", "Failed to double click because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_TYPE_NO_SUCH_ELEMENT(269, "FA", "Failed to type because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT(270, "FA", "Failed to move mouse over because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_MOUSEOVER_OFFSETFORMAT(270, "FA", "Failed to move mouse over with offset because offset '%OFFSET%' does not respect the correct format xoffset,yoffset (ex: -50,50)!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_MOUSEMOVE(270, "FA", "Failed to move mouse with coord '%COORD%' because '%ERROR%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_WAIT_NO_SUCH_ELEMENT(271, "FA", "Failed to wait because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_WAIT_ERRATUM_MISSING_SEPARATOR(271, "FA", "Failed to wait because syntax error on erratum value (separator '%SEPARATOR%' is missing) !", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_WAIT_ERRATUM_ELEMENT_NOT_FOUND(271, "FA", "Failed to wait because Erratum could not match the element on new page ! That can happen if page is too different from the original one.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Cerberus Copyright (C) 2013 - 2025 cerberustesting
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This file is part of Cerberus.
*
*
* Cerberus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* Cerberus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -98,7 +98,7 @@ public class SikuliService implements ISikuliService {
public static final String SIKULI_IDENTIFIER_TEXT = "text";

private JSONObject generatePostParameters(String action, String locator, String locator2, String text, String text2,
long defaultWait, String minSimilarity, Integer highlightElement, String typeDelay) throws JSONException, IOException, MalformedURLException, MimeTypeException {
long defaultWait, String minSimilarity, Integer highlightElement, String typeDelay) throws JSONException, IOException, MalformedURLException, MimeTypeException {
JSONObject result = new JSONObject();
String picture = "";
String extension = "";
Expand Down Expand Up @@ -361,7 +361,7 @@ public AnswerItem<JSONObject> doSikuliAction(Session session, String action, Str

// Send post request
os = new PrintStream(connection.getOutputStream());
LOG.debug("Sending JSON : " + postParameters.toString());
LOG.debug("Sending JSON : " + postParameters.toString(1));
os.println(postParameters.toString());
// os.println("|ENDS|");

Expand Down Expand Up @@ -590,7 +590,28 @@ public MessageEvent doSikuliActionLeftButtonRelease(Session session) {

@Override
public MessageEvent doSikuliActionMouseMove(Session session, String xyoffset) {
AnswerItem<JSONObject> actionResult = doSikuliAction(session, this.SIKULI_MOUSEMOVE, null, null, xyoffset, "");
AnswerItem<JSONObject> actionResult = null;

if (StringUtil.isNotEmptyOrNull(xyoffset)) {
actionResult = doSikuliAction(session, this.SIKULI_MOUSEMOVE, null, null, xyoffset, "");
} else {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEMOVE);
message.resolveDescription("%COORD%", "0,0");
return message;
}

if (actionResult == null || actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_SUCCESS).getCodeString())) {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEMOVE);
message.resolveDescription("COORD", xyoffset);
return message;
}
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_FAILED).getCodeString())) {
MessageEvent mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEMOVE);
mes.resolveDescription("ERROR", actionResult.getMessageDescription());
mes.resolveDescription("COORD", xyoffset);
return mes;
}

return actionResult.getResultMessage();

}
Expand Down Expand Up @@ -649,24 +670,39 @@ public MessageEvent doSikuliActionType(Session session, String locator, String t
public MessageEvent doSikuliActionMouseOver(Session session, String locator, String text, String offset) {
AnswerItem<JSONObject> actionResult = null;

// We check here that offxet format is correct and report an error if invalid.
if (StringUtil.isNotEmptyOrNull(offset)) {
try {
Integer[] offsetInt = StringUtil.getxFromOffset(offset);
} catch (Exception e) {
MessageEvent mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_OFFSETFORMAT);
mes.setDescription(mes.getDescription().replace("%OFFSET%", offset));
return mes;
}
}

if (!locator.isEmpty()) {
actionResult = doSikuliAction(session, this.SIKULI_MOUSEOVER, locator, null, "", "");
actionResult = doSikuliAction(session, this.SIKULI_MOUSEMOVE, null, null, offset, "");
if (StringUtil.isNotEmptyOrNull(offset)) {
actionResult = doSikuliAction(session, this.SIKULI_MOUSEMOVE, null, null, offset, "");
}
} else {
actionResult = doSikuliAction(session, this.SIKULI_MOUSEOVER, null, null, text, "");
actionResult = doSikuliAction(session, this.SIKULI_MOUSEMOVE, null, null, offset, "");
if (StringUtil.isNotEmptyOrNull(offset)) {
actionResult = doSikuliAction(session, this.SIKULI_MOUSEMOVE, null, null, offset, "");
}
}

if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_SUCCESS).getCodeString())) {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVER);
message.setDescription(message.getDescription().replace("%ELEMENT%", locator));
message.setDescription(message.getDescription().replace("%OFFSET%", "("+offset+")"));
message.setDescription(message.getDescription().replace("%OFFSET%", offset));
return message;
}
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_FAILED).getCodeString())) {
MessageEvent mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", locator) + " - " + actionResult.getMessageDescription());
mes.setDescription(mes.getDescription().replace("%OFFSET%", "("+offset+")"));
mes.setDescription(mes.getDescription().replace("%OFFSET%", offset));
return mes;
}

Expand Down
19 changes: 19 additions & 0 deletions source/src/main/java/org/cerberus/core/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ public static String getLeftString(String string1, int length) {
}
}

/**
* Return x part of offset.
*
* @param offset
* @return the {length} first character of the string1.
*/
public static Integer[] getxFromOffset(String offset) throws NumberFormatException {
Integer[] res = new Integer[2];
if (offset.contains(",")) {
String x = offset.split(",")[0];
res[0] = Integer.valueOf(x);
String y = offset.split(",")[1];
res[1] = Integer.valueOf(y);
return res;
} else {
throw new NumberFormatException();
}
}

/**
* Return left part of the string adding ... at the end.
*
Expand Down
4 changes: 2 additions & 2 deletions source/src/main/webapp/js/testcase/testcaseStatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ var actionOptList = {
"field2":{"label":{"en": "[Optional] Offset. (ex : 50,100) [GUI only]", "fr": "[Optionnel] Offset (ex : 50,100) [seulement GUI]"},"picto":"images/action-numeric.png", "class": "col-lg-12 crb-autocomplete-element crb-contextual-button"}},
"mouseOver":{"group":"mouse_action", "value": "mouseOver", "label":{"en":"Mouse Over","fr":"Souris sur l'élément"}, "application_types":["GUI","FAT"],
"field1":{"label":{"en": "Element path", "fr": "Chemin vers l'élement"},"picto":"images/action-html.png", "class": "col-lg-12 crb-autocomplete-element crb-contextual-button"},
"field2":{"label":{"en": "[Optional] Offset. (ex : 50,100) [GUI, FAT only]", "fr": "[Optionnel] Offset (ex : 50,100) [seulement GUI,FAT]"},"picto":"images/action-numeric.png", "class": "col-lg-12 crb-autocomplete-element crb-contextual-button"}},
"field2":{"label":{"en": "[Optional] Offset. (ex : 50,100) [GUI, FAT only]", "fr": "[Optionnel] Offset (ex : 50,100) [seulement GUI,FAT]"},"picto":"images/action-numeric.png", "class": "col-lg-12 crb-autocomplete-variable"}},
"mouseMove":{"group":"mouse_action", "value": "mouseMove", "label":{"en":"Move Mouse","fr":"Déplacer la souris"}, "application_types":["GUI","FAT"],
"field1":{"label":{"en": "Relative coord. (ex : 50,100 ; 200,50)", "fr": "Coordonnées relatives (ex : 50,100 ; 200,50)"}, "class": "col-lg-12 crb-autocomplete-element crb-contextual-button"}},
"field1":{"label":{"en": "Relative coord. (ex : 50,100 ; 200,50)", "fr": "Coordonnées relatives (ex : 50,100 ; 200,50)"}, "class": "col-lg-12 crb-autocomplete-variable"}},
"openUrlWithBase":{"group":"access_application","value": "openUrlWithBase","label":{"en":"openUrlWithBase","fr":"Appeler l'URI"},"application_types":["GUI","IPA","APK"],
"field1":{"label":{"en": "URI to call (ex : /index.html)", "fr": "URI à appeler (ex : /index.html)"},"picto":"images/action-link.png", "class": "col-lg-12 crb-autocomplete-variable"}},
"openUrlLogin":{"group":"access_application","value": "openUrlLogin","label":{"en":"openUrlLogin","fr":"Appeler l'URL de Login"},"application_types":["GUI","IPA","APK"]},
Expand Down

0 comments on commit 75fb1df

Please sign in to comment.