Skip to content

Commit

Permalink
Implement offset after scroll action for APK and IPA application
Browse files Browse the repository at this point in the history
  • Loading branch information
bcivel committed Nov 4, 2024
1 parent 7ee57f2 commit 5b3e099
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -865,15 +865,16 @@ private MessageEvent doActionScrollTo(TestCaseExecution tCExecution, String elem
MessageEvent message;

try {
Offset offset = new Offset(offsets);

Identifier identifier = identifierService.convertStringToIdentifierStrict(element);
LOG.debug("toto Identifier :'" + identifier.getIdentifier() + "' Locator '" + identifier.getLocator() + "'");
LOG.debug("Identifier :'" + identifier.getIdentifier() + "' Locator '" + identifier.getLocator() + "'");

if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
return androidAppiumService.scrollTo(tCExecution.getSession(), identifier, maxScrollDown);
return androidAppiumService.scrollTo(tCExecution.getSession(), identifier, maxScrollDown, offset.getHOffset(), offset.getVOffset());

} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
return iosAppiumService.scrollTo(tCExecution.getSession(), identifier, maxScrollDown);
return iosAppiumService.scrollTo(tCExecution.getSession(), identifier, maxScrollDown, offset.getHOffset(), offset.getVOffset());

} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
return webdriverService.scrollTo(tCExecution.getSession(), identifier, identifier.isSameIdentifier("") ? element : null, offsets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public interface IAppiumService {
* @return
* @throws IllegalArgumentException
*/
MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax) throws IllegalArgumentException;
MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax, Integer hOffset, Integer vOffset) throws IllegalArgumentException;

/**
* install an application on mobile devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cerberus.core.crud.service.impl.ParameterService;
import org.cerberus.core.engine.entity.Identifier;
import org.cerberus.core.engine.entity.MessageEvent;
import org.cerberus.core.engine.entity.MessageGeneral;
import org.cerberus.core.engine.entity.Session;
import org.cerberus.core.engine.gwt.impl.ActionService;
import org.cerberus.core.enums.MessageEventEnum;
import org.cerberus.core.enums.MessageGeneralEnum;
import org.cerberus.core.exception.CerberusEventException;
Expand Down Expand Up @@ -379,7 +382,7 @@ public Direction getDirectionForSwipe(Session session, SwipeAction action) throw
}

@Override
public MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax) throws IllegalArgumentException {
public MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax, Integer hOffset, Integer vOffset) throws IllegalArgumentException {
AppiumDriver driver = session.getAppiumDriver();
MessageEvent message;
try {
Expand All @@ -394,9 +397,9 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS

// check text
if (element.getIdentifier().equals("text")) {
scrollDown(driver, By.xpath("//*[contains(@text,'" + element.getLocator() + "')]"), numberOfScrollDown);
scrollDown(driver, By.xpath("//*[contains(@text,'" + element.getLocator() + "')]"), numberOfScrollDown, hOffset, vOffset);
} else {
scrollDown(driver, this.getBy(element), numberOfScrollDown);
scrollDown(driver, this.getBy(element), numberOfScrollDown, hOffset, vOffset);
}

message.setDescription(message.getDescription().replace("%VALUE%", element.toString()));
Expand All @@ -420,7 +423,7 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS
* @param element
* @return
*/
private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown) throws CerberusEventException{
private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown, Integer hOffset, Integer vOffset) throws CerberusEventException{

Dimension screenSize = driver.manage().window().getSize();

Expand All @@ -445,6 +448,11 @@ private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDo
do {
boolean isPresent = driver.findElements(element).size() > 0;
if (isPresent && driver.findElement(element).isDisplayed()) {
//Element found, perform another scroll to offset from middle of screen
int pressOffsetX = driver.manage().window().getSize().width / 2;
int pressOffsetY = driver.manage().window().getSize().height / 2;
scroll(driver, pressOffsetX, pressOffsetY, hOffset, vOffset);

return true;
} else {
scroll(driver, pressX, bottomY, pressX, topY);
Expand Down
2 changes: 1 addition & 1 deletion source/src/main/webapp/js/testcase/testcaseStatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ var actionOptList = {
"scrollTo":{"group":"mouse_action","value": "scrollTo","label":{"en":"Scroll to element","fr":"Scroller jusqu'à l'élément"},"application_types":["GUI","IPA","APK","FAT"],
"field1":{"label":{"en": "Element path or Text to scroll to", "fr": "Chemin vers l'élement ou Texte à scroller"},"picto":"images/action-html.png", "class": "col-lg-12 crb-autocomplete-element crb-contextual-button"},
"field2":{"label":{"en": "Max scroll iteration [APK,IPA only]", "fr": "Nombre maximum de scroll vers le bas (8 par defaut) [seulement APK,IPA]"}, "class": "col-lg-12 crb-autocomplete-variable"},
"field3":{"label":{"en": "offsets (h,v) [GUI only]", "fr": "offsets (h,v) [seulement GUI]"}, "class": "col-lg-6 crb-autocomplete-variable"},"documentation":{"en":"...","fr":"..."}},
"field3":{"label":{"en": "offsets (h,v) [APK,IPA,GUI only]", "fr": "offsets (h,v) [seulement APK,IPA,GUI]"}, "class": "col-lg-6 crb-autocomplete-variable"},"documentation":{"en":"...","fr":"..."}},
"installApp":{"group":"access_application","value": "installApp","label":{"en":"Install Application","fr":"Installer l'Application"},"application_types":["IPA","APK"],
"field1":{"label":{"en": "Application path (ex : /root/toto.apk)", "fr": "Chemin vers l'application (ex : /root/toto.apk)"},"picto":"images/action-mobile-application.png", "class": "col-lg-12 crb-autocomplete-variable"},"documentation":{"en":"...","fr":"..."}},
"removeApp":{"group":"access_application","value": "removeApp","label":{"en":"Uninstall Application","fr":"Désinstaller l'Application"},"application_types":["IPA","APK"],
Expand Down

0 comments on commit 5b3e099

Please sign in to comment.