Skip to content

Commit

Permalink
Create parameters for scroll action for mobile. Default parameters ar…
Browse files Browse the repository at this point in the history
…e the previous values (from 4/5 bottom to 1/8 top).
  • Loading branch information
bcivel committed Apr 2, 2024
1 parent 85bc12b commit 2db550d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public enum MessageEventEnum {
ACTION_FAILED_SELECT(266, "FA", "Element and Option are both mandatory in order to perform the action.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_CLICK_NO_SUCH_ELEMENT(267, "FA", "Failed to click because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_SCROLL_NO_SUCH_ELEMENT(267, "FA", "Failed to scroll because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_SCROLL_INVALID_PARAMETER(267, "FA", "Invalid parameter. Verify parameters cerberus_appium_scroll_endTopScreenPercentageScreenHeight and cerberus_appium_scroll_startBottomPercentageScreenHeight have float value between 0 and 1", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
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),
ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT(268, "FA", "Failed to double click because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
ACTION_FAILED_TYPE_NO_SUCH_ELEMENT(269, "FA", "Failed to type 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 @@ -29,8 +29,12 @@
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.enums.MessageEventEnum;
import org.cerberus.core.enums.MessageGeneralEnum;
import org.cerberus.core.exception.CerberusEventException;
import org.cerberus.core.exception.CerberusException;
import org.cerberus.core.service.appium.IAppiumService;
import org.cerberus.core.service.appium.SwipeAction;
import org.cerberus.core.service.appium.SwipeAction.Direction;
Expand Down Expand Up @@ -382,6 +386,9 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS
message.setDescription(message.getDescription().replace("%VALUE%", element.toString()));

return message;
} catch (CerberusEventException e) {
LOG.error("An error occured during scroll to (element:" + element + ",numberScrollDownMax:" + numberScrollDownMax + ")", e);
return e.getMessageError();
} catch (Exception e) {
LOG.error("An error occured during scroll to (element:" + element + ",numberScrollDownMax:" + numberScrollDownMax + ")", e);
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);
Expand All @@ -397,13 +404,25 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS
* @param element
* @return
*/
private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown) {
private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown) throws CerberusEventException{

int pressX = driver.manage().window().getSize().width / 2;
Dimension screenSize = driver.manage().window().getSize();

float screenTopPercentage = parameters.getParameterFloatByKey("cerberus_appium_scroll_endTopScreenPercentageScreenHeight", null, 0.125f);
float screenBottomPercentage = parameters.getParameterFloatByKey("cerberus_appium_scroll_startBottomPercentageScreenHeight", null, 0.8f);

int bottomY = driver.manage().window().getSize().height * 4 / 5;
/**
* Check if cerberus_appium_scroll_endTopScreenPercentageScreenHeight and cerberus_appium_scroll_startBottomPercentageScreenHeight parameters are float between 0 and 1
*/
if (screenTopPercentage < 0 || screenTopPercentage > 1 || screenBottomPercentage < 0 || screenBottomPercentage > 1){
MessageEvent me =new MessageEvent(MessageEventEnum.ACTION_FAILED_SCROLL_INVALID_PARAMETER);
throw new CerberusEventException(me);
}

int pressX = driver.manage().window().getSize().width / 2;

int topY = driver.manage().window().getSize().height / 8;
int bottomY = (int) (screenSize.height * screenBottomPercentage);
int topY = (int) (screenSize.height * screenTopPercentage);

int i = 0;

Expand All @@ -415,7 +434,7 @@ private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDo
scroll(driver, pressX, bottomY, pressX, topY);
}
i++;
} while (i <= numberOfScrollDown);
} while (i < numberOfScrollDown);

return false;
}
Expand Down
7 changes: 6 additions & 1 deletion source/src/main/resources/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6293,4 +6293,9 @@ INSERT INTO `parameter` (`system`, `param`, `value`, `description`)
VALUES ('', 'cerberus_pdfcampaignreportdisplayciresult_boolean', 'true', 'Boolean in order to show or hide the cicd campaign result on pdf campaign execution pdf report.');

-- 1768
ALTER TABLE countryenvparam_log MODIFY Creator VARCHAR(45);
ALTER TABLE countryenvparam_log MODIFY Creator VARCHAR(45);

-- 1769
INSERT INTO `parameter` (`system`, `param`, `value`, `description`)
VALUES ('', 'cerberus_appium_scroll_endTopScreenPercentageScreenHeight', '0.125', 'Float value between 0 and 1 that represents the percentage of the screen height where the scroll ends. 0 for the top of the screen, 0.5 for the middle.')

This comment has been minimized.

Copy link
@vertigo17

vertigo17 Apr 2, 2024

Member

Les 2ieme lignes sont à indenter pour considerer que c'est le même SQL.

,('', 'cerberus_appium_scroll_startBottomPercentageScreenHeight', '0.8', 'Float value between 0 and 1 that represents the percentage of the screen height where the scroll starts. 0.5 for the middle of the screen, 1 for the bottom.');

0 comments on commit 2db550d

Please sign in to comment.