Skip to content

Commit

Permalink
Web application : Ability to use Drag and drop using one element and …
Browse files Browse the repository at this point in the history
…an offset
  • Loading branch information
bcivel committed Aug 20, 2024
1 parent 8980043 commit 2f79a1b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public interface Identifiers {
public static final String IDENTIFIER_TEXT = "text";

public static final String IDENTIFIER_COORD = "coord";
public static final String IDENTIFIER_OFFSET = "offset";

public static final String IDENTIFIER_TITLE = "title";
public static final String IDENTIFIER_REGEXTITLE = "regexTitle";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Identifier getIdentifier(String input, String defaultIdentifier) {
Identifier.IDENTIFIER_CLASS, Identifier.IDENTIFIER_CSS, Identifier.IDENTIFIER_LINK,Identifier.IDENTIFIER_DATACERBERUS,
Identifier.IDENTIFIER_QUERYSELECTOR, Identifier.IDENTIFIER_ERRATUM,
Identifier.IDENTIFIER_PICTURE, Identifier.IDENTIFIER_TEXT,
Identifier.IDENTIFIER_COORD,
Identifier.IDENTIFIER_COORD, Identifier.IDENTIFIER_OFFSET,
Identifier.IDENTIFIER_TITLE, Identifier.IDENTIFIER_REGEXTITLE, Identifier.IDENTIFIER_URL, Identifier.IDENTIFIER_REGEXURL,
Identifier.IDENTIFIER_VALUE, Identifier.IDENTIFIER_REGEXVALUE,
Identifier.IDENTIFIER_INDEX, Identifier.IDENTIFIER_REGEXINDEX,
Expand Down Expand Up @@ -107,7 +107,7 @@ public void checkSelectOptionsIdentifier(String identifier) throws CerberusEvent
public void checkWebElementIdentifier(String identifier) throws CerberusEventException {
String[] selectOptionAttributes = {Identifier.IDENTIFIER_ID, Identifier.IDENTIFIER_NAME, Identifier.IDENTIFIER_CLASS, Identifier.IDENTIFIER_CSS,
Identifier.IDENTIFIER_XPATH, Identifier.IDENTIFIER_LINK, Identifier.IDENTIFIER_DATACERBERUS, Identifier.IDENTIFIER_COORD, Identifier.IDENTIFIER_PICTURE,
Identifier.IDENTIFIER_QUERYSELECTOR, Identifier.IDENTIFIER_ERRATUM};
Identifier.IDENTIFIER_QUERYSELECTOR, Identifier.IDENTIFIER_ERRATUM, Identifier.IDENTIFIER_OFFSET,};

if (!Arrays.asList(selectOptionAttributes).contains(identifier)) {
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKOWN_IDENTIFIER_SELENIUM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,11 @@ public MessageEvent doActionDragAndDrop(TestCaseExecution tCExecution, String va
&& identifierDrop.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
return sikuliService.doSikuliActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop);
} else {
return webdriverService.doSeleniumActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop, true, true);
if (Identifier.IDENTIFIER_OFFSET.equals(identifierDrop.getIdentifier())) {
return webdriverService.doSeleniumActionDragAndDropByOffset(tCExecution.getSession(), identifierDrag, identifierDrop, true, true);
} else {
return webdriverService.doSeleniumActionDragAndDrop(tCExecution.getSession(), identifierDrag, identifierDrop, true, true);
}
}
}
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ public enum MessageEventEnum {
ACTION_FAILED_CLEARFIELD(257, "FA", "Value1 is ‘null’. Parameter is mandatory in order to perform the action clearField.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_PENDING(299, "PE", "Doing Action...", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_FAILED_DRAGANDDROP_NO_SUCH_ELEMENT(299, "FA", "Failed to dragAndDrop because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_DRAGANDDROP_INVALID_FORMAT(299, "FA", "Failed to dragAndDrop because of the value of the offset '%OFFSET%'! It must be offset=integer;integer", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_DRAGANDDROPSIKULI_NO_SUCH_ELEMENT(299, "FA", "Failed to dragAndDrop because could not find an element!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_WAITINGFORMANUALEXECUTION(240, "WE", "", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
ACTION_FAILED_CLEAR_NO_SUCH_ELEMENT(267, "FA", "Failed to long clicked because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,7 @@ public interface IWebDriverService {

MessageEvent doSeleniumActionDragAndDrop(Session session, Identifier object, Identifier property, boolean waitForVisibility, boolean waitForClickability) throws IOException;

MessageEvent doSeleniumActionDragAndDropByOffset(Session session, Identifier object, Identifier offset, boolean waitForVisibility, boolean waitForClickability) throws IOException;

MessageEvent doSeleniumActionRefreshCurrentPage(Session session);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,53 @@ public MessageEvent doSeleniumActionDragAndDrop(Session session, Identifier drag
}
}

@Override
public MessageEvent doSeleniumActionDragAndDropByOffset(Session session, Identifier drag, Identifier offset, boolean waitForVisibility, boolean waitForClickability) throws IOException {
MessageEvent message;
try {
AnswerItem answerDrag = this.getSeleniumElement(session, drag, waitForVisibility, waitForClickability);
String[] offsetCoords = offset.getLocator().split(";");

int xOff = Integer.parseInt(offsetCoords[0]);
int yOff = Integer.parseInt(offsetCoords[1]);

if (answerDrag.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
WebElement source = (WebElement) answerDrag.getItem();

Actions builder = new Actions(session.getDriver());
Action dragAndDrop = builder.clickAndHold(source)
.moveToElement(source, xOff, yOff)
.release()
.build();
dragAndDrop.perform();

message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DRAGANDDROP);
message.setDescription(message.getDescription().replace("%SOURCE%", drag.getIdentifier() + "=" + drag.getLocator()));
message.setDescription(message.getDescription().replace("%TARGET%", offset.getIdentifier() + "=" + offset.getLocator()));
return message;
} else {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", drag.getIdentifier() + "=" + drag.getLocator()));
return message;
}
} catch (NoSuchElementException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", drag.getIdentifier() + "=" + drag.getLocator()));
LOG.debug(exception.toString());
return message;
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
LOG.warn(exception.toString());
return message;
} catch (NumberFormatException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DRAGANDDROP_INVALID_FORMAT);
message.setDescription(message.getDescription().replace("%OFFSET%", offset.getIdentifier() + "=" + offset.getLocator()));
LOG.debug(exception.toString());
return message;
}
}

private void selectRequestedOption(Select select, Identifier property, String element) throws CerberusEventException {
MessageEvent message;
try {
Expand Down
3 changes: 2 additions & 1 deletion source/src/main/webapp/js/global/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ function initTags(configs, context) {
"erratum",
"picture",
"text",
"coord"
"coord",
"offset"
];
var availableIdentifiersSwitch = [
"title",
Expand Down
2 changes: 1 addition & 1 deletion source/src/main/webapp/js/testcase/action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f79a1b

Please sign in to comment.