Thursday, November 6, 2014

Getting started with Appium, The hybrid application automation

You have to have Java,android installed in your PC before continuing below steps.
And an android device or emulator should be connect to your PC.
try adb device on a command prompt and if any thing is there you are good to go.


Download the latest appium appication from there web site.
Unzip and run the exe.



As you can there are nothing on this screen.
I dint check any of the text boxes.
Below is my general settings.
I just the keeping the default settings as it is.


Click on the play button to start the server.

As on the image you will only ;

> Checking if an update is available
> Update not available
> Starting Node Server

For now stop the server. :) 

I will be starting the test as a CodedUI test and passing all the parameters using c# code.
Open a visual studio and create a new CodedUI project.
Add references as on the below image.



below is my setup method ofr appium.
From the code user have to pass parameters to appium interface.

         

Important :

Switching to webview_0. (Use  consol.writelin(driver.WindowHandles) to identify what the the windows currently application is having).
If hybrid like phonegap you have to switch to webview.

To get the app package name : aapt dump badging droid.apk command to get the package name.
(Nacigate to sdk\build-tools\XXXXX copy your apk file and run the above command on  command line)

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using Microsoft.VisualStudio.TestTools.UITesting;
using System.Windows.Forms;
using System.Threading;
using NUnit.Framework;

namespace AppiumTest
{

    class DriverSetup
    {
        private static  RemoteWebDriver driver;

        
        public void AppiumSetupMethod()
        {


            string appPAth = @"**************.apk";
            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability(CapabilityType.BrowserName, "");
            capabilities.SetCapability(CapabilityType.Version, "4.4.2");
            capabilities.SetCapability(CapabilityType.IsJavaScriptEnabled, "true");
            // capabilities.SetCapability("automationName", "selendroid");
            capabilities.SetCapability("deviceName", "Xperia Z");
            capabilities.SetCapability("platformName", "Android");
            capabilities.SetCapability("autoWebview", "true");
            capabilities.SetCapability("sessionOverride", "true");

            capabilities.SetCapability("app", appPAth);

            capabilities.SetCapability("appPackage", "xx.xx.xx");
            //  capabilities.SetCapability("appActivity", "com.dtz.sg.DTZMobility");

            try
            {
                driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);
            }
            catch (Exception e )
            {

                MessageBox.Show(e.Message);
            }
            
            Thread.Sleep(4000);
            
            driver.SwitchTo().Window("WEBVIEW_0");

        }
        public static RemoteWebDriver _driver
            {
                get { return driver; }
                set { driver = value; }

            }

    }
   
    
}

Start the appium server by clicking the play button.

Now run your codedUI project.

Check what is happening on your appium interface.

Our connected android device should install the application which you mention in the code. :D

Trouble shooooting.

 Failed to start an Appium session, err was: Error: Command failed: error: cannot bind to socket
OR
forward tcp:8080 tcp:8080

> info: [debug] Cleaning up appium session
OR
> error: Couldn't start Appium REST http interface listener. Requested port is already in use. Please make sure there's no other instance of Appium running already.

That means you have to kill everything which are runing on port 8080.


netstat -a -n -o | find "<port ID>"
taskkill /PID 2052 /F  - 2052 means the process ID

Now server is ready start writing test scripts like you testing a web page... Wish you all good luck




No comments:

Post a Comment