Skip to content

Commit b272388

Browse files
committed
Added support for clearField on GUI applications. fixed #2624
1 parent 6f65a96 commit b272388

6 files changed

Lines changed: 103 additions & 15 deletions

File tree

source/src/main/java/org/cerberus/core/engine/execution/IIdentifierService.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,52 @@
2828
*/
2929
public interface IIdentifierService {
3030

31+
/**
32+
*
33+
* @param input
34+
* @return
35+
*/
3136
Identifier convertStringToIdentifier(String input);
3237

38+
/**
39+
*
40+
* @param input
41+
* @return
42+
*/
3343
Identifier convertStringToIdentifierStrict(String input);
3444

45+
/**
46+
*
47+
* @param input
48+
* @return
49+
*/
3550
Identifier convertStringToSelectIdentifier(String input);
3651

52+
/**
53+
*
54+
* @param identifier
55+
* @throws CerberusEventException
56+
*/
3757
void checkSelectOptionsIdentifier(String identifier) throws CerberusEventException;
3858

59+
/**
60+
*
61+
* @param identifier
62+
* @throws CerberusEventException
63+
*/
3964
void checkWebElementIdentifier(String identifier) throws CerberusEventException;
4065

66+
/**
67+
*
68+
* @param identifier
69+
* @throws CerberusEventException
70+
*/
4171
void checkSQLIdentifier(String identifier) throws CerberusEventException;
4272

73+
/**
74+
*
75+
* @param identifier
76+
* @throws CerberusEventException
77+
*/
4378
void checkSikuliIdentifier(String identifier) throws CerberusEventException;
4479
}

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public TestCaseStepActionExecution doAction(TestCaseStepActionExecution actionEx
411411
res = this.doActionType(execution, actionExecution, value1, value2, propertyName);
412412
break;
413413
case TestCaseStepAction.ACTION_CLEARFIELD:
414-
res = this.doActionClearField(execution, value1);
414+
res = this.doActionClearField(execution, actionExecution, value1);
415415
break;
416416
case TestCaseStepAction.ACTION_HIDEKEYBOARD:
417417
res = this.doActionHideKeyboard(execution);
@@ -1362,17 +1362,21 @@ private MessageEvent doActionType(TestCaseExecution execution, TestCaseStepActio
13621362
return webdriverService.doSeleniumActionType(execution.getSession(), identifier, value2, propertyName, true, true);
13631363
}
13641364
}
1365+
13651366
} else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
13661367
return androidAppiumService.type(execution.getSession(), identifier, value2, propertyName);
1368+
13671369
} else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
13681370
return iosAppiumService.type(execution.getSession(), identifier, value2, propertyName);
1371+
13691372
} else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
13701373
String locator = "";
13711374
if (!StringUtil.isEmptyOrNull(value1)) {
13721375
identifierService.checkSikuliIdentifier(identifier.getIdentifier());
13731376
locator = identifier.getLocator();
13741377
}
13751378
return sikuliService.doSikuliActionType(execution.getSession(), locator, value2).getResultMessage();
1379+
13761380
} else {
13771381
return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)
13781382
.resolveDescription("ACTION", "Type")
@@ -2394,9 +2398,11 @@ private MessageEvent doActionLongPress(TestCaseExecution tCExecution, String val
23942398
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
23952399
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
23962400
return androidAppiumService.longPress(tCExecution.getSession(), identifier, longPressTime);
2401+
23972402
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
23982403
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
23992404
return iosAppiumService.longPress(tCExecution.getSession(), identifier, longPressTime);
2405+
24002406
} else {
24012407
return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)
24022408
.resolveDescription("ACTION", "Long Click")
@@ -2408,15 +2414,15 @@ private MessageEvent doActionLongPress(TestCaseExecution tCExecution, String val
24082414
}
24092415
}
24102416

2411-
private MessageEvent doActionClearField(TestCaseExecution tCExecution, String value1) {
2417+
private MessageEvent doActionClearField(TestCaseExecution execution, TestCaseStepActionExecution actionExecution, String value1) {
24122418
String element;
24132419
try {
24142420
/**
24152421
* Check object and property are not null for GUI/APK/IPA Check
24162422
* property is not null for FAT Application
24172423
*/
2418-
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)
2419-
|| tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
2424+
if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)
2425+
|| execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
24202426
if (value1 == null) {
24212427
return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLEARFIELD);
24222428
}
@@ -2429,16 +2435,29 @@ private MessageEvent doActionClearField(TestCaseExecution tCExecution, String va
24292435
identifier = identifierService.convertStringToIdentifier(value1);
24302436
}
24312437

2432-
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
2438+
if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
24332439
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
2434-
return androidAppiumService.clearField(tCExecution.getSession(), identifier);
2435-
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
2440+
return androidAppiumService.clearField(execution.getSession(), identifier);
2441+
2442+
} else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
24362443
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
2437-
return iosAppiumService.clearField(tCExecution.getSession(), identifier);
2444+
return iosAppiumService.clearField(execution.getSession(), identifier);
2445+
2446+
} else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
2447+
2448+
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
2449+
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
2450+
AnswerItem<JSONObject> answer = sikuliService.doSikuliActionClearField(execution.getSession(), identifier.getLocator());
2451+
actionExecution.addFileList(recorderService.recordExecutionScreenshotDebug(execution, actionExecution, StringUtil.convertAnswerJSONToString(answer, "screenshotDebug")));
2452+
return answer.getResultMessage();
2453+
} else {
2454+
return webdriverService.doSeleniumActionType(execution.getSession(), identifier, "", "", true, true);
2455+
}
2456+
24382457
} else {
24392458
return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION)
24402459
.resolveDescription("ACTION", "ClearField")
2441-
.resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());
2460+
.resolveDescription("APPLICATIONTYPE", execution.getApplicationObj().getType());
24422461
}
24432462
} catch (CerberusEventException ex) {
24442463
LOG.fatal("Error doing Action Type : " + ex);

source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public enum MessageEventEnum {
186186
ACTION_SUCCESS_CLICKANDWAIT(200, "OK", "Element '%ELEMENT%' clicked and waited %TIME% ms.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
187187
ACTION_SUCCESS_CLICKANDNOWAIT(200, "OK", "Element '%ELEMENT%' clicked and waited for page to load", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
188188
ACTION_SUCCESS_TYPE(200, "OK", "%ELEMENTFOUND%. Element '%ELEMENT%' feeded with '%DATA%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
189+
ACTION_SUCCESS_TYPE_CLEARINPUT(200, "OK", "%ELEMENTFOUND%. Element '%ELEMENT%' cleared from any data.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
189190
ACTION_SUCCESS_DOUBLECLICK(200, "OK", "%ELEMENTFOUND%. Element '%ELEMENT%' double clicked.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
190191
ACTION_SUCCESS_RIGHTCLICK(200, "OK", "%ELEMENTFOUND% Right click has been done on Element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
191192
ACTION_SUCCESS_URLLOGIN(200, "OK", "Opened '%URL%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
@@ -288,6 +289,7 @@ public enum MessageEventEnum {
288289
ACTION_FAILED_LONG_CLICK_NO_SUCH_ELEMENT(267, "FA", "Failed to long clicked because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
289290
ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT(268, "FA", "Failed to double click because could not find element '%ELEMENT%'! %MESSAGE%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
290291
ACTION_FAILED_TYPE_NO_SUCH_ELEMENT(269, "FA", "Failed to type because could not find element '%ELEMENT%'! %MESSAGE%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
292+
ACTION_FAILED_CLEARFIELD_NO_SUCH_ELEMENT(269, "FA", "Failed to clear field because could not find element '%ELEMENT%'! %MESSAGE%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
291293
ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT(270, "FA", "Failed to move mouse over because could not find element '%ELEMENT%'! %MESSAGE%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
292294
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),
293295
ACTION_FAILED_MOUSEMOVE(270, "FA", "Failed to move mouse with coord '%COORD%' because '%ERROR%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),

source/src/main/java/org/cerberus/core/service/robotextension/ISikuliService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ public interface ISikuliService {
157157
*/
158158
public AnswerItem<JSONObject> doSikuliActionDoubleClick(Session session, String locator, String text);
159159

160+
/**
161+
*
162+
* @param session
163+
* @param locator
164+
* @param property
165+
* @return
166+
*/
167+
public AnswerItem<JSONObject> doSikuliActionClearField(Session session, String locator);
168+
160169
/**
161170
*
162171
* @param session

source/src/main/java/org/cerberus/core/service/robotextension/impl/SikuliService.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class SikuliService implements ISikuliService {
8686
public static final String SIKULI_CLOSEAPP = "closeApp";
8787
public static final String SIKULI_SWITCHAPP = "switchApp";
8888
public static final String SIKULI_PASTE = "paste";
89+
public static final String SIKULI_CLEARFIELD = "clearField";
8990
public static final String SIKULI_WAIT = "wait";
9091
public static final String SIKULI_WAITVANISH = "waitVanish";
9192
public static final String SIKULI_MOUSEOVER = "mouseOver";
@@ -724,6 +725,28 @@ public AnswerItem<JSONObject> doSikuliActionType(Session session, String locator
724725
return actionResult;
725726
}
726727

728+
@Override
729+
public AnswerItem<JSONObject> doSikuliActionClearField(Session session, String locator) {
730+
AnswerItem<JSONObject> actionResult = doSikuliAction(session, 0, this.SIKULI_CLEARFIELD, locator, null, "", "");
731+
732+
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_SUCCESS).getCodeString())) {
733+
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE_CLEARINPUT);
734+
message.resolveDescription("ELEMENTFOUND", actionResult.getMessageDescription())
735+
.resolveDescription("ELEMENT", generateSikuliObjectFromLocator(locator));
736+
actionResult.setResultMessage(message);
737+
return actionResult;
738+
}
739+
if (actionResult.getResultMessage().getCodeString().equals(new MessageEvent(MessageEventEnum.ACTION_FAILED).getCodeString())) {
740+
MessageEvent mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLEARFIELD_NO_SUCH_ELEMENT);
741+
mes.resolveDescription("MESSAGE", actionResult.getMessageDescription())
742+
.resolveDescription("ELEMENT", generateSikuliObjectFromLocator(locator));
743+
actionResult.setResultMessage(mes);
744+
return actionResult;
745+
}
746+
747+
return actionResult;
748+
}
749+
727750
@Override
728751
public AnswerItem<JSONObject> doSikuliActionMouseOver(Session session, String locator, String text, String offset) {
729752
AnswerItem<JSONObject> actionResult = null;

source/src/main/java/org/cerberus/core/service/webdriver/impl/WebDriverService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private AnswerItem<WebElement> getSeleniumElement(Session session, Identifier id
414414
answer.setItem(element);
415415
Integer numberOfElement = this.getNumberOfElements(session, identifier);
416416
msg = AnswerUtil.getMessageDependingOnNbOfElement(numberOfElement, identifier.getIdentifier() + "=" + identifier.getLocator() + erratumMessage);
417-
417+
418418
/**
419419
* Element was found, so we can now highlight it if requested.
420420
*/
@@ -1312,14 +1312,14 @@ public MessageEvent doSeleniumActionType(Session session, Identifier identifier,
13121312
if (!StringUtil.isEmptyOrNULLString(valueToType)) {
13131313
webElement.sendKeys(valueToType);
13141314
}
1315-
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);
1316-
message.setDescription(message.getDescription().replace("%ELEMENTFOUND%", answer.getResultMessage().getDescription()));
1317-
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
13181315
if (!StringUtil.isEmptyOrNULLString(valueToType)) {
1319-
message.setDescription(message.getDescription().replace("%DATA%", ParameterParserUtil.securePassword(valueToType, propertyName)));
1316+
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);
1317+
message.resolveDescription("DATA", ParameterParserUtil.securePassword(valueToType, propertyName));
13201318
} else {
1321-
message.setDescription(message.getDescription().replace("%DATA%", "No property"));
1319+
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE_CLEARINPUT);
13221320
}
1321+
message.resolveDescription("ELEMENTFOUND", answer.getResultMessage().getDescription());
1322+
message.resolveDescription("ELEMENT", identifier.getIdentifier() + "=" + identifier.getLocator());
13231323
return message;
13241324
}
13251325
}

0 commit comments

Comments
 (0)