Friday, 29 May 2015

Appium C# - Executing 'Appium-Webdriver' automation script on mobile device

This session demonstrates automating the script for 'EriBank' app and executing the automation script in mobile device using Visual Studio with C#.

Prerequisites:
- Java is installed
- Set path for Java
- Android SDK is installed
- Set path for Android SDK
- Appium Server is installed

  Refer below url's for installation/configuration.
  http://automation-home.blogspot.in/2015/05/appium-installation.html 
  http://automation-home.blogspot.com/2015/05/appium-uiautomatorviewer.html

- Developer Options are enabled in mobile device
- USB Debugging is enabled in mobile device

Note: 
  'Eribank.apk' can be downloaded from 'http://code.google.com/p/eribank/downloads/list'

Video Session covers below topics:
- Visual Studio

Adding Webdriver, JSON.net and Appium to the references.
- Webdriver 
- JSON.net
- Appium

- Inspecting the locators/elements in the mobile device app(.apk)

Watch Demo

Sample Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System.Threading;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;

namespace ERiBankTest
{
    class Program
    {
        static void Main(string[] args)
        {
            AppiumDriver driver;
            Console.WriteLine("Executing Appium Script");

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability("deviceName", "Test");
            capabilities.SetCapability("platformVersion", "4.4.4");
            capabilities.SetCapability("platformName", "Android");

            capabilities.SetCapability("appPackage", "com.experitest.ExperiBank");
            capabilities.SetCapability("appActivity", ".LoginActivity");

            driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);

            //userName - com.experitest.ExperiBank:id/usernameTextField            driver.FindElement(By.Id("com.experitest.ExperiBank:id/usernameTextField")).SendKeys("company");

            //pwd- com.experitest.ExperiBank:id/passwordTextField      driver.FindElement(By.Id("com.experitest.ExperiBank:id/passwordTextField")).SendKeys("company");

            //login- com.experitest.ExperiBank:id/loginButton
            driver.FindElement(By.Id("com.experitest.ExperiBank:id/loginButton")).Click();

            //logout - com.experitest.ExperiBank:id/logoutButton
            driver.FindElement(By.Id("com.experitest.ExperiBank:id/logoutButton")).Click();

            Thread.Sleep(5000);
            driver.Quit();
        }
    }
}

2 comments:

  1. Error im getting at line:
    driver = new AndroidDriver(new Uri ("http://127.0.0.1:4723/wd/hub"), capabilities);

    Error:
    Failed to start an Appium session, err was: Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity.

    ReplyDelete
    Replies
    1. Verify 'eribank' app is already installed in your android mobile device, after 'eribank' app is installed verify the 'appPackage' and 'appActivity' name of the 'eribank' app using the 'Apk Info' app.

      Delete