Scroll and swipe methods
1 - Introduction
It exists 2 types of methods pour navigate on the screen :
Scroll
Swipe
Differences
Scroll | Swipe |
---|---|
The finger rests on the screen and glides as it is held down. | The finger glides over the screen without remaining pressed down |
Relies on the first "scrollable" view element | Not based on any view elements but only on screen coordinates |
If what you want to do is go to a certain place on the page without the gesture being important, you may prefer swipe-type methods.
2 - Swipe focus
The swipe is a finger slide between point A and point B on the screen.
The coordinates of points A and B are defined as a percentage of screen width for the abscissa and as a percentage of screen height for the ordinate :
percStartX : screen width of point A
percStartY : screen height of point A
percEndX : screen width of point B
percEndY : screen height of point B
Example with image below : A (90%, 50%) et B (10%, 50%).
Â
This swipe gesture to the bottom of the screen could be performed by the following GDSL methods :
# swipeDownward(percX, percStartY) : les paramètres sont optionnels
# percX par défaut est 50. Les 2 points A et B auront l'absisse 50% (percStartX = percEndX = 50)
# percStartY par défaut swipe des coordonnées A (X 50%, Y 90%) aux coordonnées B (X 50%, Y 10%).
# Ce sont les valeurs par défaut de la méthode, on note que percEndY n'est pas à renseigner dans
# cette méthode car il est toujours fixé à 10%
swipeDownward
# swipeDownward(percX, percStartY)
swipeDownward,50,90
# swipeVertical(percStartY, percEndY, percX)
swipeVertical,90,10,50
3 - Scroll focus
Websites case
For all websites, the Chrome application on the phone interprets the website using a webview.
For websites, there is often a dump element with the class "android.webkit.Webview" with the information scrollable = true. This element is generally the first element in the dump that is "scrollable".
We can then scroll the screen using scroll-type methods.
Â
Mobile apps case
For applications, there's usually a dump element with the class "android.support.v7.widget.RecyclerView" which is scrollable.
4 - List of scroll and swipe commands
5 - Use case
Here's a diagram showing the methods that can be used to scroll the screen in the desired direction.
Use case 1 : I want to go down on the screen
Issue 1 : I just want to scroll my screen down, so I need an easy-to-use method with no parameters.
Here are the 2 simplest methods :
# Swipe des coordonnées A (X 50%, Y 90%) aux coordonnées B (X 50%, Y 10%)
swipeDownward
# Défilement de l'écran vers le bas
scrollDownward
Issue 2 : When I swipe, the automation seems to click on an element instead of swiping.
In this case, you can shift the swipe to the left or right so that the gesture is no longer central with X 50%.
# Swipe des coordonnées (X 30%, Y 90%) aux coordonnées (X 30%, Y 10%)
swipeDownward,30
Â
Issue 3 : I want to scroll down the screen by choosing the scroll length, I don't need to go as low as the default method.
The greater the difference in ordinates between point A and point B, the further down the screen will scroll.
Example
Â
Issue 4 : For my various test iterations, each time I swipe, I don't always arrive at the same place on the screen, which blocks my automation.
In this case, you need to use the method that allows you to fully define the swipe and change the scroll duration (scrolling speed).
The longer you increase the scroll time, the slower the action will arrive at the same point on the screen. In fact, a fast action requires more processing on the phone and therefore depends more on its occupation at the time of scrolling (CPU used, for example), which can lead to small differences between each test iteration.
Â
Use case 2 : I want to reach a text in the screen
Issue 1 : I want to reach the text at the bottom of the screen
Â
Issue 2 : I'm in the middle of the screen and want to reach the text before or after my position.
Â
Use case 3 : I want to go to the bottom of the screen
This method scrolls up to 20 times to reach the end of the page.
It can be used without parameters.
If this function doesn't work, it may be due to the following factors:
Maximum number of scrolls reached
Scrollable element that doesn't scroll to the bottom of the page
Numerous videos being launched during scrolls.
In this case, you need to use swipe methods several times to reach the bottom of the screen.
Â