Test Automation: Zoom In on Mobile

MP
1 min readSep 17, 2018

--

How to perform Zoom In on Mobile

Today I had to implement zoom in on Mobile. I will be using Appium, iOS and Python binding. But the concepts should be similar on other platforms.

In order to implement ZoomIn one needs to use touch action commands. In particular MultiAction Api.

Here is how zoom In works in theory —

1. Create Touch Action for finger moving up
2. Create Touch Action for finger moving down
3. Chain the touch actions to perform MultiAction

Sounds simple isn’t it. Here is the documentation related to Appium docs

The example there are self explanatory.

Here is one such example —

# Up finger
a1 = TouchAction()
a1.press(None, startX, startY)
a1.move_to(None, xUp, yUp)
a1.release()
# Down finger
a2 = TouchAction()
a2.press(None, startX, startY)
a2.move_to(None, xDown, yDown)
a2.release()
#Chaining the Actions
ma = MultiAction(driver)
ma.add(a1, a2)
ma.perform()

Note Up and Down fingers start at same location startX & startY

But it fails to mention something very crucial which I discovered while implementing it.

Between the press and move one has to introduce delay as only then the element responds to multiperform . So here is the modified version

# python
# Up finger
a1 = TouchAction()
a1.press(None, startX, startY)
a1.wait(ms=450)
a1.move_to(None, xUp, yUp)
a1.release()
# Down finger
a2 = TouchAction()
a2.press(None, startX, startY)
a2.wait(ms=450)
a2.move_to(None, xDown, yDown)
a2.release()
#Chaining the Actions
ma = MultiAction(driver)
ma.add(a1, a2)
ma.perform()

Thats it!!

Happy Coding!

If this helped you in your work, do tell me

--

--

MP
MP

Written by MP

Startup guy. Loves Programming

No responses yet