[フレーム]

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Appium Tutorials / Automate Mobile native applications using Appium/Selenium

Automate Mobile native applications using Appium/Selenium

by 29 Comments

[画像:Appium]

Today in this post you will get the complete information about how you can automate native application using Appium

In previous, article we have already discussed installation and running tests on mobile chrome browser so before reading this article it is must to complete the previous post.

Once you are done you need to download the apk file which you want to test.

In Android application extension is .apk file.

In IOS application extension is .ipa file.

I have uploaded the same tutorial on YouTube

[フレーム]

Steps to Automate Native application using Appium

  • Download .apk file for android device
  • Install in your device using ADB
  • Set .apk file in Appium and get the details about application which is required to run your test.
  • Write a test to launch the application on real device
  • Perform some action on application. (We will perform sendkeys i.e typing)

Download .apk file Appium

I have found an easy application which contains almost all kind of web elements.

Visit http://selendroid.io/setup.html and download .apk file.

[画像:Download apk file for testing]

Make sure Appium server is off.

Click on Android ICON.

Check the checkbox before application path

Browse the .apk file which we downloaded at 1st step.

Run the Appium server

Click on Android ICON.

Copy Package and Launch activity.

[画像:Appium-Settings]

We need to deploy application in our local device as well.

Open cmd

Type > adb devices

This will display the device which is connected.

Type > adb install give-apk-file-path-with-application

[画像:Application_deployed]

Once it is deployed to your device you will get a success message.

[画像:Android-App]

Program to automate Native application using Appium

package demo;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class StartApplication {
               
// create global variable
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException 
{
 // Create object of DesiredCapabilities class               
DesiredCapabilities capabilities = new DesiredCapabilities();
// Optional
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
// Specify the device name (any name)
capabilities.setCapability("deviceName", "My New Phone");
// Platform version
capabilities.setCapability("platformVersion", "4.4.2");
// platform name
capabilities.setCapability("platformName", "Android");
// specify the application package that we copied from appium        
capabilities.setCapability("appPackage", "io.selendroid.testapp");
// specify the application activity that we copied from appium          
capabilities.setCapability("appActivity", ".HomeScreenActivity");
 
// Start android driver I used 4727 port by default it will be 4723
driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);
// Specify the implicit wait of 5 second
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// Enter the text in textbox
driver.findElement(By.xpath("//android.widget.EditText[@content-desc='my_text_fieldCD']")).sendKeys("Mukesh Selenium Appium");
// click on registration button 
                  
driver.findElement(By.id("io.selendroid.testapp:id/startUserRegistration")).click();
// Wait for 10 second
Thread.sleep(10000);
// close the application
 driver.quit();
        }
}

Run the program and enjoy the native test automation.

This is just a small program just to make sure everything is up and running.

I took very basic application to automate Native application using Appium but you can take any application and perform the same step.

In next article I will cover how you can perform other activity on application using xpath and other ways.

If you liked this article then please share with your friends or team.

Feel free to comment in case any issue.

You can like our Facebook Page for more updates Learn Automation Page
Join our facebook group for any query Selenium Group Discussion

Reader Interactions

Comments

  1. Roshni D. says

    Hi Mukesh,

    Thanks for your videos,
    Can you please help how to hit the mobile application via Proxy ? I need a help to implement the proxy for Mobile App.

  2. Akash says

    Hi Mukesh, I am referring your tutorial in 2019, can you do one more video on mobile testing with latest android version, latest appium version and NOX android emulator.

  3. Pradeep B B says

    In Appium framework, Package and Launch activity is blank even though I checked d check box, can you please help me, bt sample selendroid.apk is installed in my device

  4. jayesh says

    Hi Mukesh…Thanks for your excellent tutorial & documention…I have been following this for long time. I need your suggestion in one place where I stuck..I alreday posted the issue in slack and some forums –[http://stackoverflow.com/questions/40643411/appium-webview-switch-not-working-in-ubuntu] can you please this link and help

  5. Anjali Kashyap says

    Hi mukesh,
    While running the program you mentioned in your post, I got below error:
    Failed to start an Appium session, err was: Error: ‘java -version’ failed. Error: spawn ENOENT

  6. Richa Shrivastava says

    Hi Mukesh,

    I am using windows machine currently
    If I want to test on my app on iphone then can I simply change something in above script and run it? OR I have to setup everything on Mac machine?

  7. Lokesh says

    Hi Mukesh,
    I have been following you on youtube videos and they are good.I like the way you have explained it and the communication is the key.

    I am at automation engineer been working on Appium, I am stuck with doing scroll on Mobile Apps for both iOS and Android, will be helpful if you could link me to those videos on how to do it, or give me an example for any app which it is implemented and working fine.

    Or else if you could help me i can share you the .apk/.ipa file of the App which i am working on.

    Look forward to hear back from you.

    Regards,
    Lokesh

  8. Ankur Gupta says

    Hi Mukesh,

    I would like to say thank you for the all videos you have uploaded till now. Videos are totally awesome. You have explained small to small very clearly.
    Please upload some more videos on Appium tool. This is my request to you.

  9. santosh singh says

    Hi Mukesh,
    i am new in appium and learn lot of concept from your site ,some confusion i am craeate script for mobile Automation but some time i am my appium server is not start so what can i do and i am wriing all functionality code but some time it works and some time it fails.
    package gotuktuk;

    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;

    import io.appium.java_client.android.AndroidDriver;

    public class StartApplication {

    private static RemoteWebDriver driver;

    public static String phoneNum = “9926895346”;
    public static String pickUpAdd = “Corporate House, Rabindranath Tagore Marg, Chhoti Gwaltoli, Indore, Madhya Pradesh”;
    public static String dropAdd = “301/4 Nehru Nagar, Patni Pura Indore, Madhya Pradesh 452001”;

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
    System.out.println(“**************************start***********************************”);
    File classpathRoot = new File(System.getProperty(“user.dir”));
    System.out.println(“USER DIR : “+System.getProperty(“user.dir”));
    File appDir = new File(classpathRoot, “/Android/data/”);
    File app = new File(appDir, “RIDER.apk”);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, ” “);
    capabilities.setCapability(“deviceName”, “Galaxy j5(2016)”);
    capabilities.setCapability(“platformVersion”, “6.0.1”);
    capabilities.setCapability(“platformName”, “Android”);
    capabilities.setCapability(“app”, app.getAbsolutePath());
    capabilities.setCapability(“appPackage”, “in.gotuktuk.rider”);
    //capabilities.setCapability(“appActivity”, “com.tuktuk.corelib.ui.activity.LogoSplashActivity”);
    driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

    //Thread.sleep(4000);
    setPhoneNumber(phoneNum);
    Thread.sleep(20000);
    getMenu();
    // Thread.sleep(20000);
    // getHistory();
    // Thread.sleep(5000);
    // getRateCard();

    //setCurrentPickupLocation(pickUpAdd);
    //seeRateCard(dropAdd);

    // driver.quit();
    System.out.println(“**********************************End***********************************”);
    }

    private static void setPhoneNumber(String phoneNum2) {
    // TODO Auto-generated method stub
    System.out.println(“==>Entering phone number ..”);
    driver.findElement(By.id(“in.gotuktuk.rider:id/phoneNumberEditText”)).sendKeys(phoneNum2);
    driver.findElement(By.id(“in.gotuktuk.rider:id/verifySMSButton”)).click();
    System.out.println(“==>Clicked on Button ..”);
    }

    private static void seeRateCard(String dropAdd2) throws InterruptedException {
    // TODO Auto-generated method stub
    System.out.println(“==>Entering drop address ..”);
    driver.findElement(By.className(“android.widget.RelativeLayout”)).findElements(By.id(“0”));
    Thread.sleep(5000);
    driver.findElement(By.id(“in.gotuktuk.rider:id/staticComponentDropAddressTextView”)).getAttribute(dropAdd2);
    System.out.println(“==>Clicked on Rate Card Button ..”);
    }

    private static void setCurrentPickupLocation(String pickUpAdd2) throws InterruptedException {
    // TODO Auto-generated method stub
    System.out.println(“==>Setting current address ..”);
    driver.findElement(By.id(“in.gotuktuk.rider:id/myLocationImageView”)).click();
    Thread.sleep(2000);
    //driver.findElement(By.id(“in.gotuktuk.rider:id/bookingButtonActionEnableTextView”)).click();
    System.out.println(“==>Clicked on Button ..”);
    }

    private static void getMenu() throws InterruptedException {
    // TODO Auto-generated method stub
    //Thread.sleep(3000);
    System.out.println(“==>in get menu ..”);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    Thread.sleep(7000);
    System.out.println(“==>Clicking on History ..”);
    driver.findElement(By.name(“HISTORY”)).click();
    Thread.sleep(3000);
    driver.findElement(By.className(“android.support.v7.app.ActionBar$Tab”)).click();
    Thread.sleep(5000);
    System.out.println(“==>Back button from history ..”);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    Thread.sleep(5000);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    Thread.sleep(5000);
    System.out.println(“==>Clicking on tCash ..”);
    driver.findElement(By.name(“tCASH”)).click();
    System.out.println(“==>Clicking on SHARE REFERRAL CODE ..”);
    Thread.sleep(3000);
    //driver.findElement(By.id(“in.gotuktuk.rider:id/tCashSocialMediaShareView”)).click();
    System.out.println(“==>Back button from refereal code ..”);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    //driver.findElement(By.className(“android.widget.ImageButton”)).click();
    driver.findElement(By.className(“in.gotuktuk.rider:id/menu_row_name”)).click();
    }

    private static void getHistory() {
    // TODO Auto-generated method stub
    driver.findElement(By.id(“in.gotuktuk.rider:id/menu_row_icon”)).click();
    }

    private static void getRateCard() {
    // TODO Auto-generated method stub
    driver.findElement(By.className(“in.gotuktuk.rider:id/menu_row_icon”)).click();
    }
    private static void Notification() {
    // TODO Auto-generated method stub
    System.out.println(“==>Back button from refereal code ..”);

    driver.findElement(By.className(“in.gotuktuk.rider:id/menu_row_name”)).click();
    driver.quit();
    }
    }
    so can you share me this type of solution

    • Mukesh Otwani says

      Hey Santosh,

      We need to find out the pattern and then we need to make changes. Run multiple time and when it fails try to collect logs, then only we can make the changes.

  10. cg says

    Hello! Awesome tutorials! I was wondering how to integrate appium with jenkins? Also what if you don’t have a local jenkins server? Thanks!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

AltStyle によって変換されたページ (->オリジナル) /