diff --git a/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java b/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java index f7439e051..391f4b63a 100644 --- a/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java +++ b/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java @@ -871,10 +871,10 @@ private MessageEvent doActionScrollTo(TestCaseExecution tCExecution, String elem LOG.debug("Identifier :'" + identifier.getIdentifier() + "' Locator '" + identifier.getLocator() + "'"); if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) { - return androidAppiumService.scrollTo(tCExecution.getSession(), identifier, maxScrollDown, offset.getHOffset(), offset.getVOffset()); + return androidAppiumService.scrollTo(tCExecution, identifier, maxScrollDown, offset.getHOffset(), offset.getVOffset()); } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) { - return iosAppiumService.scrollTo(tCExecution.getSession(), identifier, maxScrollDown, offset.getHOffset(), offset.getVOffset()); + return iosAppiumService.scrollTo(tCExecution, 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); diff --git a/source/src/main/java/org/cerberus/core/service/appium/IAppiumService.java b/source/src/main/java/org/cerberus/core/service/appium/IAppiumService.java index c3c8abeaf..415b62be5 100644 --- a/source/src/main/java/org/cerberus/core/service/appium/IAppiumService.java +++ b/source/src/main/java/org/cerberus/core/service/appium/IAppiumService.java @@ -19,6 +19,7 @@ */ package org.cerberus.core.service.appium; +import org.cerberus.core.crud.entity.TestCaseExecution; import org.cerberus.core.engine.entity.Identifier; import org.cerberus.core.engine.entity.MessageEvent; import org.cerberus.core.engine.entity.Session; @@ -112,7 +113,7 @@ public interface IAppiumService { * @return * @throws IllegalArgumentException */ - MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax, Integer hOffset, Integer vOffset) throws IllegalArgumentException; + MessageEvent scrollTo(TestCaseExecution testCaseExecution, Identifier element, String numberScrollDownMax, Integer hOffset, Integer vOffset) throws IllegalArgumentException; /** * install an application on mobile devices diff --git a/source/src/main/java/org/cerberus/core/service/appium/impl/AppiumService.java b/source/src/main/java/org/cerberus/core/service/appium/impl/AppiumService.java index 1b44c49c5..c09839447 100644 --- a/source/src/main/java/org/cerberus/core/service/appium/impl/AppiumService.java +++ b/source/src/main/java/org/cerberus/core/service/appium/impl/AppiumService.java @@ -28,11 +28,9 @@ import lombok.Setter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.cerberus.core.crud.entity.TestCaseExecution; 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.entity.*; import org.cerberus.core.engine.gwt.impl.ActionService; import org.cerberus.core.enums.MessageEventEnum; import org.cerberus.core.enums.MessageGeneralEnum; @@ -382,8 +380,8 @@ public Direction getDirectionForSwipe(Session session, SwipeAction action) throw } @Override - public MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax, Integer hOffset, Integer vOffset) throws IllegalArgumentException { - AppiumDriver driver = session.getAppiumDriver(); + public MessageEvent scrollTo(TestCaseExecution testCaseExecution, Identifier element, String numberScrollDownMax, Integer hOffset, Integer vOffset) throws IllegalArgumentException { + AppiumDriver driver = testCaseExecution.getSession().getAppiumDriver(); MessageEvent message; try { message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SCROLLTO); @@ -397,9 +395,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, hOffset, vOffset); + scrollDown(testCaseExecution, By.xpath("//*[contains(@text,'" + element.getLocator() + "')]"), numberOfScrollDown, hOffset, vOffset); } else { - scrollDown(driver, this.getBy(element), numberOfScrollDown, hOffset, vOffset); + scrollDown(testCaseExecution, this.getBy(element), numberOfScrollDown, hOffset, vOffset); } message.setDescription(message.getDescription().replace("%VALUE%", element.toString())); @@ -423,8 +421,9 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS * @param element * @return */ - private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown, Integer hOffset, Integer vOffset) throws CerberusEventException{ + private boolean scrollDown(TestCaseExecution testCaseExecution, By element, int numberOfScrollDown, Integer hOffset, Integer vOffset) throws CerberusEventException{ + AppiumDriver driver = testCaseExecution.getSession().getAppiumDriver(); Dimension screenSize = driver.manage().window().getSize(); float screenTopPercentage = parameters.getParameterFloatByKey("cerberus_appium_scroll_endTopScreenPercentageScreenHeight", null, 0.125f); @@ -451,13 +450,20 @@ private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDo //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, pressOffsetX-hOffset, pressOffsetY-vOffset); + if (hOffset!=0 && vOffset!=0){ + scroll(driver, pressOffsetX, pressOffsetY, pressOffsetX - hOffset, pressOffsetY - vOffset); + testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" displayed. Applied the offset ("+hOffset+";"+vOffset+") scrolling from the coord("+pressOffsetX+";"+pressOffsetY+")"); + } else { + testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" displayed. No offset defined."); + } return true; } else { scroll(driver, pressX, bottomY, pressX, topY); + testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" not displayed. Scrolled "+i+"/"+numberOfScrollDown+" from coord("+pressX+";"+bottomY+") to coord("+pressX+";"+topY+")"); } i++; + } while (i < numberOfScrollDown); return false;