Automate hybrid mobile app using appium (Android & IOS)

In our previous blog post, we have seen how to inspect the hybrid mobile apps using appium inspector.

In this post, we will discuss how to use appium methods to switch between NATIVE_APP and WEB_VIew contexts and automate the hybrid app elements and their actions.

Appium contexts –

There are 2 actions we need in terms of context –

Fetch/get current contexts of the screen – driver.getContextHandles()

Switch to a context – driver.context(String context)

Note – the driver should be of AndroidDriver / IOSDriver type, not AppiumDriver type.

Reference –

https://appium.io/docs/en/writing-running-appium/web/hybrid/


Code implementation -

Refer to the below code for handling android and ios hybrid apps –

IOS – https://github.com/sunilpatro1985/appium-topics/blob/main/src/test/java/topics/nativeToWeb.java

Android – https://github.com/sunilpatro1985/appium-topics/blob/main/src/test/java/topics/nativeToWeb_android.java

To run the tests, please refer to the demo videos attached into this blog post.


Inspect and automate IOS hybrid mobile app -

Inspect and automate Android hybrid mobile app -

Hope this helps!