Learn Selenium and Java for Selenium

Sunday, 2 July 2017

Mobile automation using APPIUM

Mobile automation using APPIUM

Author : Ashwini Velapure (Test Automation Engineer)https://www.linkedin.com/in/ashwinivelapure


Hello everyone, Before we go for the mobile automation, we should be familiar with atleast core  JAVA and Selenium web driver.
Lets start!!
We have to follow 5 steps for achieving the complete mobile automation setup.
1.Android Setup and connecting android device to PC
2.Installtion of Appium
3. Required java code  and Modifications the as per mobile device model.
4.Run the Java Application
5.Inspect Mobile element.

1.Android Setup and connecting android device to PC
  1. a.Download latest android SDK for Windows. Following folders should be there.

  1. B.Open SDK manager.Install all the API.As appium support only above android 4.2.
It will take  more time.




Set environment variable
Right click on ‘My Computer’  Go to ‘Properties’

Go to Advanced system settings and Go to Environment variables TAB
.
ANDROID_HOME  will be pointing toward your Android SDK folder.

  1. Go ‘Command Prompt’.Type %ANDROID_HOME%. It will open Android SDK folder.

  1. Set PATH variable.
You just need to concatenate below String for your existing PATH.
;%ANDROID_HOME%\tools;%ANDRIOD_HOME%\platforms-tools



  1. Now Connect your android phone to laptop in Debug mode.
f.Go to ‘Command Prompt’.change directory to ‘Android SDK\platform-tools’
Type ‘ adb devices’
You will get attached devices.
(In screen shot,as my SDK is on D drive. I have changed the drive)


Here You done with Android Set up.

2.Installtion of Appium

 1: Downoad Appium From  http://appium.io/
Note:Extract  file and Install Appium.(If you are getting .NET frame work related error message,)


3.Required java code  and Modifications the as per mobile device model.
Java Code
package Ashwini;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import io.appium.java_client.android.AndroidDriver;

public class Appium {
      
       public static void main(String[] args) throws Exception {
             
             
              AndroidDriver driver;

       DesiredCapabilities capabilities = new DesiredCapabilities();
       //1
       capabilities.setCapability("deviceName","Redmi");
       capabilities.setCapability("platformName","Android");
       capabilities.setCapability("platformVersion","6.0.1");
//2
    File file=new File("C:\\Users\\ASHWINI1\\workspace\\Blog\\Apache POI\\src\\Ashwini\\first2.apk");
    capabilities.setCapability("app", file.getAbsolutePath());
//3
   
 driver=new AndroidDriver(new URL("http://192.168.1.103:4723/wd/hub"),capabilities);

WebElement ele=driver.findElementByAccessibilityId("Login");
 ele.click();
}
      


}

1.Here we are defining ,which android device we connecting to PC.You can get phone details from ‘Settings->Abpout Phone’. Give the android version which is present in ur mobile.

2.Here we giving apk file detail,which we are going to install on our phone
3.We need to give URL where appium is running.For getting this URL please follow below steps:
a)  Run cmd and type ip config
b)  Go to Appium General Settings.
.
c)  Give the server address same as machine ip


4.Run the Java Application
a.Launch the appium
b.Connect phone in USB debug mode.(also check device is connected propery by adb devices command)
c.Check the checkbox “No Reset”.(It will does not install android app on your phone,As its already intalled)

d.Start the Appium Node server.
c.Run the java application


5.Inspect Mobile element.
For inspecting mobile element,We need UiAutomaterViewer.This batch file is present in ‘Tools’Folder in the android SDK.
Connect your android phone to PC.Open android app in your phone,in which you are supposed to inspect element.


Using multiple types of locators you can automate your mobile application.








0 comments:

Post a Comment

Popular Posts

Recent Posts



Newsletter

Join our newsletter to get secret tips directly in your inbox!


*We Hate Spam!

Powered by Blogger.