Home » appium-tutorial » First Appium Test to Launch Flipkart

Newly Updated Posts

First Appium Test to Launch Flipkart

Previous Topic, In this tutorial we will learn to write our First Appium Test to Launch Flipkart.

How to write First Appium Test to Launch Flipkart?

Before writing script , we need to launch Appium server first, below are the steps to launch server.

Step 1) Open the Appium server.

Launching appium server

Let keep the host=”0.0.0.0″ and port “4723” as it is( default).

Step 2) Click to Start Server button and the server will get start working with default host number and port number.

First Appium Test to Launch whatsapp

Step 3) Now copy the below code and paste in a class inside the eclipse ide.

package code2test.MavenAppiumProject;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;

public class Harness {

public AndroidDriver<AndroidElement> adriver;		
public void openapp(){
			
System.out.println("Opening App");
File app =new File(System.getProperty("user.dir")+"\\apks\\Flipkart-7.3.apk");
DesiredCapabilities capabilities =new DesiredCapabilities();
capabilities.setCapability("deviceName","Redmi");
capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("platformVersion","9 PKQ1.181203.001");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("noReset","true");
capabilities.setCapability("fullReset","false");
			
capabilities.setCapability("appPackage","com.flipkart.android");
capabilities.setCapability("appActivity","com.flipkart.android.activity.HomeFragmentHolderActivity");
capabilities.setCapability("app", app.getAbsolutePath());		
	
try {
adriver = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); 
   } catch (MalformedURLException e) {

e.printStackTrace();
				
Assert.fail("Driver failed to start" + e.getMessage());
	}
adriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);							
		}
public static void main(String[] args) {
Harness flipDriver=new Harness();
flipDriver.openapp();
 }
}

Code Inside Eclipse will look as below:

First Appium Test to Launch Flipkart application

Step 4) Now run the code by right click to code Run->Run As->Java Application.

Step 5) In few minutes of time we see that the flipkart application in mobile gets opened.

Code explanation step by step:

//Code to provide the path of Flipkart APK in system

File app =new File(System.getProperty(“user.dir”)+”\apks\Flipkart-7.3.apk”);

Desired Capabilities:

DesiredCapabilities capabilities =new DesiredCapabilities(); // Creating object for desired capabilities.

// Defining the name of your device
capabilities.setCapability(“deviceName”,”Redmi”);

//Defining the name of mobile browser as empty
capabilities.setCapability(CapabilityType.BROWSER_NAME,””);

// Defining the platform version of the device
capabilities.setCapability(“platformVersion”,”9 PKQ1.181203.001″);

//Defining Name of the platform, as Android
capabilities.setCapability(“platformName”,”Android”);

//defining the mobile to open in noReset
capabilities.setCapability(“noReset”,”true”);

//Defining the capability to not re-install application
capabilities.setCapability(“fullReset”,”false”);

capabilities.setCapability(“appPackage”,”com.flipkart.android”); // defining the application packackage of Flipkart

//Defining application activity of flipkart
capabilities.setCapability(“appActivity”,”com.flipkart.android.activity.HomeFragmentHolderActivity”);

//Defining the file path in one statement and retuning a String
capabilities.setCapability(“app”, app.getAbsolutePath());

try {
// Creating the object of android driver and passing host and port number and capabilities to it
adriver = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); 
   } catch (MalformedURLException e) {

e.printStackTrace();
				
Assert.fail("Driver failed to start" + e.getMessage());
	}

So following the below steps, we now able to create and execute the appium script to launch flipkart application and other application too.

#code2test