Skip to content

Commit

Permalink
Action ScrollTo : Do not execute the last scroll if offset is not def…
Browse files Browse the repository at this point in the history
…ined.

Add Log Entry
  • Loading branch information
bcivel committed Dec 10, 2024
1 parent 18fa0f2 commit b926217
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()));
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit b926217

Please sign in to comment.