Skip to content

Commit 2db550d

Browse files
committed
Create parameters for scroll action for mobile. Default parameters are the previous values (from 4/5 bottom to 1/8 top).
1 parent 85bc12b commit 2db550d

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public enum MessageEventEnum {
275275
ACTION_FAILED_SELECT(266, "FA", "Element and Option are both mandatory in order to perform the action.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
276276
ACTION_FAILED_CLICK_NO_SUCH_ELEMENT(267, "FA", "Failed to click because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
277277
ACTION_FAILED_SCROLL_NO_SUCH_ELEMENT(267, "FA", "Failed to scroll because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),
278+
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),
278279
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),
279280
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),
280281
ACTION_FAILED_TYPE_NO_SUCH_ELEMENT(269, "FA", "Failed to type because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION),

source/src/main/java/org/cerberus/core/service/appium/impl/AppiumService.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
import org.cerberus.core.crud.service.impl.ParameterService;
3030
import org.cerberus.core.engine.entity.Identifier;
3131
import org.cerberus.core.engine.entity.MessageEvent;
32+
import org.cerberus.core.engine.entity.MessageGeneral;
3233
import org.cerberus.core.engine.entity.Session;
3334
import org.cerberus.core.enums.MessageEventEnum;
35+
import org.cerberus.core.enums.MessageGeneralEnum;
36+
import org.cerberus.core.exception.CerberusEventException;
37+
import org.cerberus.core.exception.CerberusException;
3438
import org.cerberus.core.service.appium.IAppiumService;
3539
import org.cerberus.core.service.appium.SwipeAction;
3640
import org.cerberus.core.service.appium.SwipeAction.Direction;
@@ -382,6 +386,9 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS
382386
message.setDescription(message.getDescription().replace("%VALUE%", element.toString()));
383387

384388
return message;
389+
} catch (CerberusEventException e) {
390+
LOG.error("An error occured during scroll to (element:" + element + ",numberScrollDownMax:" + numberScrollDownMax + ")", e);
391+
return e.getMessageError();
385392
} catch (Exception e) {
386393
LOG.error("An error occured during scroll to (element:" + element + ",numberScrollDownMax:" + numberScrollDownMax + ")", e);
387394
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);
@@ -397,13 +404,25 @@ public MessageEvent scrollTo(Session session, Identifier element, String numberS
397404
* @param element
398405
* @return
399406
*/
400-
private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown) {
407+
private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown) throws CerberusEventException{
401408

402-
int pressX = driver.manage().window().getSize().width / 2;
409+
Dimension screenSize = driver.manage().window().getSize();
410+
411+
float screenTopPercentage = parameters.getParameterFloatByKey("cerberus_appium_scroll_endTopScreenPercentageScreenHeight", null, 0.125f);
412+
float screenBottomPercentage = parameters.getParameterFloatByKey("cerberus_appium_scroll_startBottomPercentageScreenHeight", null, 0.8f);
403413

404-
int bottomY = driver.manage().window().getSize().height * 4 / 5;
414+
/**
415+
* Check if cerberus_appium_scroll_endTopScreenPercentageScreenHeight and cerberus_appium_scroll_startBottomPercentageScreenHeight parameters are float between 0 and 1
416+
*/
417+
if (screenTopPercentage < 0 || screenTopPercentage > 1 || screenBottomPercentage < 0 || screenBottomPercentage > 1){
418+
MessageEvent me =new MessageEvent(MessageEventEnum.ACTION_FAILED_SCROLL_INVALID_PARAMETER);
419+
throw new CerberusEventException(me);
420+
}
421+
422+
int pressX = driver.manage().window().getSize().width / 2;
405423

406-
int topY = driver.manage().window().getSize().height / 8;
424+
int bottomY = (int) (screenSize.height * screenBottomPercentage);
425+
int topY = (int) (screenSize.height * screenTopPercentage);
407426

408427
int i = 0;
409428

@@ -415,7 +434,7 @@ private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDo
415434
scroll(driver, pressX, bottomY, pressX, topY);
416435
}
417436
i++;
418-
} while (i <= numberOfScrollDown);
437+
} while (i < numberOfScrollDown);
419438

420439
return false;
421440
}

source/src/main/resources/database.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6293,4 +6293,9 @@ INSERT INTO `parameter` (`system`, `param`, `value`, `description`)
62936293
VALUES ('', 'cerberus_pdfcampaignreportdisplayciresult_boolean', 'true', 'Boolean in order to show or hide the cicd campaign result on pdf campaign execution pdf report.');
62946294

62956295
-- 1768
6296-
ALTER TABLE countryenvparam_log MODIFY Creator VARCHAR(45);
6296+
ALTER TABLE countryenvparam_log MODIFY Creator VARCHAR(45);
6297+
6298+
-- 1769
6299+
INSERT INTO `parameter` (`system`, `param`, `value`, `description`)
6300+
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.')
6301+
,('', '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 commit comments

Comments
 (0)