I would like to inform you that I am traveling while writing this blog post, Hope it will be completed in 1 hour 40 minutes flight journey. The main tutorial will be started after a few travel pictures. 😉
Let’s begin the knowledge sharing session today!
Today we are going to discuss the techniques to test the Android native app using Appium and Selenium. Before we begin, let’s go to last day flashback wherein we discussed techniques to test the web application in the Android browser. We did Android web application testing in chrome browser.
What is Android Native App?
An Android native app is an application which is exclusively designed to use on the Android platform and specifically to the device. It uses the platform’s kernel. They take advantage of the latest technologies and use the inbuilt hardware like GPS.
What is Android Hybrid App?
An Android hybrid app is an application which uses Native as well as web app technology. In Android, it is called WebView. Hybrid apps are made using HTML, CSS, JavaScript which is a web application and they use the native browser to load the entire UI.
Comparative Study between Selenium Grid & Appium
If you remember we discussed that there are many similarities between Appium and Selenium Grid in our previous article. Let’s see the comparative study between them here.
Selenium Grid | Appium |
It is a part of Selenium components, mainly for distributed web testing. | It is exclusive & separate tool for Mobile testing which uses Selenium as a base. |
Selenium Server is required. | Appium Server is required. |
It uses the RemoteWebDriver class. | It uses AndroidDriver, iOSDriver and in some case RemoteWebDriver class as well. |
A node should be registered with the hub. | No concept of node registration. |
Desired Capability for Android Native App Testing
We have separate settings for Android native app in desired capability. Here we do not need to set properties for the browser; rather, we set the property for App activity and App package.
Recommended Reading: How to get App Package and App Activity in Android?
DesiredCapabilities   cap = new DesiredCapabilities(); cap.setCapability("deviceName", "deviceName"); cap.setCapability("udid", "uniqueId"); cap.setCapability("platformName", "AndroidOriOS"); cap.setCapability("platformVersion", "version"); cap.setCapability("appPackage", "package name of the app"); cap.setCapability("appActivity", "testing screen");
Testing Scenario
In this scenario, we will just see whether App is getting launched or not with the expected testing screen. We can use different locators to identify the path of the Mobile Element.
Suggested Readings:
- Step by step guide to configure Appium in Eclipse
- Different types of Mobile Element locators
- How to locate elements using UiAutomatorViewer tool?
Sample program to launch a Native Android App for Testing
Here is the sample program. The below program simply launches the Amazon app and lands to the expected screen.
package AppiumPractice; import org.testng.annotations.Test; import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.ios.IOSDriver; import org.testng.annotations.BeforeMethod; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterMethod; public class AppiumHybridNativeAppTestDemo { AppiumDriver<MobileElement> driver; DesiredCapabilities cap; @Test public void mobileAppTest() throws Exception { DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability("deviceName", "vivo 1818"); cap.setCapability("udid", "d7206a48"); cap.setCapability("platformName", "Android"); cap.setCapability("platformVersion", "9"); cap.setCapability("appPackage", "in.amazon.mShop.android.shopping"); cap.setCapability("appActivity", "com.amazon.mShop.home.HomeActivity"); URL url = new URL("https://127.0.0.1:4723/wd/hub"); driver = new AndroidDriver<MobileElement>(url,cap); System.out.println("Appium Test Started"); } }
Console Output
Video Recording
Â
Hope this article will help you in testing the Android native app. Finally, I completed this article in the first 30 minutes of the travel time. It’s time to enjoy the add-on meals in business class. 🙂
I have some pictures for you. 🙂
Share your doubts, queries, feedback, and suggestions using the comment form below. Also, don’t forget to join our Facebook group for quick updates on Test automation and Selenium.
Happy Learning. 🙂