Android mobile application comprised of two different types, one is Native application and another one is Hybrid application. Each type of application is having some merits and de-merits. Hybrid Application is a combination of both the Native and Web components. Web elements associated with the Hybrid application will re-use the web browser container for displaying the elements in the expected fashion. Hybrid application is developed using the HTML, CSS and Javascript. Native application is developed for the specific platform and it is having all the privilege and permissions to access the system features such as camera, GPS, SMS etc,. Please note, debugging option should be enabled by the Android developer for the Hybrid mobile application.
Using the Java program, we are going to identify the Android mobile application type as stated above and check whether it is a Hybrid app or not.
Prerequisites;
1. Download the latest Appium Client Libraries using the URL: http://appium.io/downloads.html
2. Map the required libraries in the Eclipse IDE based on the step-3 URL
3. Refer the blog post to configure and implement Appium using the URL: https://gopekannan.wordpress.com/2015/08/26/how-to-automate-android-mobile-application-using-appium/
Steps to follow;
1. Initialize the AndroidDriver available in the Appium client libraries – io.appium.java_client.android.AndroidDriver;
2. Get the mobile app screen/activity context by using the method getContextHandles() using the driver object instantiated from AndroidDriver
3. If the context name is webview, it should be a Hybrid application
4. If the context name is Native_APP, it should be a Native application
public class HybridAppCheck {
AndroidDriver<WebElement> driver;
public void contextCheck() {
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains(“WEBVIEW”))
driver.context(contextName);
}}}
If you want to change the context of the mobile app activity back to Native, please use the below step;
driver.context(NATIVE_APP);
Happy Coding!!!