Launch Hybrid App using Appium

Let’s see, How can you launch Hybrid App using Appium. You have seen many things in Appium, Now it’s time to execute our First Appium Test.  You will see, How can you launch the Hybrid App in Appium.

 

What is Hybrid App?

Hybrid mobile apps are like any other apps you’ll find on your phone. They install on your device. You can find them in app stores. With them, you can play games, engage your friends through social media, take photos, track your health, and much more.

In your phone, Whatsapp, Facebook, Amazon, Flipkart, Gmail etc they all are Hybrid Apps. You can download these apps from Google Play App Store.

Launch Hybrid App using Appium

I believe you have gone through the previous Appium Tutorials.

We are taking the example of WhatsApp . We will launch the Whatsapp from our Appium Test Script.

 

Prerequisite – 1. The phone should be connected to the Machine.

2. Appium Server should be started in “No Reset” mode.

 

Please find the below-attached code to launch the WhatsApp.

Copy the above code and paste it in your Local and try to execute. The above code will open the Whats app on your Android Device and close it.

 

In Above code, First we set the Desired Capabilities, You have seen this in Set Desired Capabilities tutorial. In Desired Capabilities, we provide the appPackage and appActivity of WhatsApp. Refer the last tutorial to know How to find appPackage and appActivity.

 

After this, we initialized the AndroidDriver with defualtURL and with desired Capabilities. At the end, we quit the Driver. Which is a more important step, If you quit the Driver and try to execute this code again then this will fail.

 

Run Test in Appium if Application is not Installed on Device

Now, What if an application is not installed on the device and we will try to execute the above code.

If you will try the above code the Test will fail because we are proving the appPackage and appActivity of the application which is not available on the target Device.

 

So, Is it necessary to install the Application first ?

The answer is NO, You don’t need to install the app first before executing the Test case. In this case, we will set the Application’s APK path in the test script and execute it. It will execute the Script without install the application on Device.

 

We are taking the Example of Flipkart Mobile app. Flipkart is not installed on my device, I will provide the Flipkart’s APK path and execute test on it.

 

Let’s understand the above code. In above code didn’t declare the appPackage andappActivity. Instead of appPackage and appActivity we have declared our APK file path and set the Absolute path as Desired Capabilities and execute the Test case.

 

File appDir = new File(System.getProperty(“user.dir”) +”//Apps”);

File app = new File(appDir, “Flipkart_com.flipkart.android.apk”);

 

What these lines are doing, We have extracted the Flipkart APK file inside the “Apps” Directory in our Project. So using System.getProperty(“user.dir”) +”//Apps” , we are getting the project default path and appending the Apps into it to reach to APK file.

 

In Next line, we are declaring our APK file name and telling the system that our APK file is present inside the appDir.

 

How can you execute this in your Local Machine?

To Execute the above code on your local machine, You need to follow the below-mentioned steps.

 

  • Extract the Flipkart APK file or any Application’s APK file.
  • Create a new folder inside your Project name “Apps”.
  • Put the APK file inside this Apps folder.
  • Copy and Paste the above code in your local machine.
  • Edit the File path & APK name if required.
  • Start the Appium Server with No Reset Mode.
  • Connect your device to the machine.
  • Execute the Test Case.

 

This will first install the Flipkart on your Device then execute the Test i.e launch the App and close it.

Using this way we can execute our Tests on Appium.

NoteIt’s recommended to use both File and APK concept and appPackage and appActivity concept in your script. So that it will minimize the risk of test failure. 

 

If the application is not present on your Device then first it will install then execute else It will directly call the Application. Because on the server side you will use Emulator or Simulator to execute the Test Case, So we need to install the app first before executing the Test case. So it’s advisable to keep both concepts in your Script.

0 Comment

Leave a Reply