Friday 8 January 2016

Appium with multiple device android

The following code will help you.
//Running multiple emulators from single appium server



public class Test{

    WebDriver driver = null;
    int timeOut=180;
    int port=-1;

    Test(int port){
        this.port=port;
    }

    public void testEmulator(int p) throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
        capabilities.setCapability(CapabilityType.VERSION, "4.3");
        capabilities.setCapability(CapabilityType.PLATFORM, "Windows");

        capabilities.setCapability("udid","emulator-"+p);

        capabilities.setCapability("app-package", "your.app.pkg");
        capabilities.setCapability("app-activity",
            "your.app.pkg.Activity");
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:"+this.port+"/wd/hub"),
        capabilities);
        driver.manage().timeouts().implicitlyWait(timeOut, TimeUnit.SECONDS);
        Thread.sleep(50000);
    }

    public void tearDown() {
        if (driver != null)
            driver.quit();
    }

    public void runTest() {
        try {
            testEmulator(5554);     // for emulator on port 5554
            tearDown();
            testEmulator(5556);     // for emulator on port 5556
            tearDown();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        new Test(4723).runTest();       // appium server port 4723
    }
}

Wednesday 6 January 2016

appium windows setup

1. Install JAVA (jdk 6 or more)

2. Set java in the class path, its weird but strictly follow this:
For Windows 7: my computer ->right click--> properties--> advanced system settings-->environment variable--> create a new variable under system variable [not user variable], name it 'JAVA_HOME' and give path till java's directory
example: C:\Program Files\Java\jdk1.6.0_27
now open 'path' variable and add @ end of it ';%JAVA_HOME%\bin'
Test it : go to cmd and type 'java' or 'jvm', it should echo some message but not 'command not found'

3. Download android sdk for Android
Adt: http://developer.android.com/sdk/index.html 4. Set the adb path in class path,
For Windows : like java, create a new variable under system variable, name it "ANDROID_HOME" and give path till adb
example: D:\Software\Android\android-sdk\
now open 'path' variable and add @ end of it ';%ANDROID_HOME%\platform-tools' same for tools
Test it : go to cmd and type 'adb', it should echo some message but not 'command not found'

5. Download Appium
For windows: AppiumForWindows-1.2.0.1.zip from https://bitbucket.org/appium/appium.app/downloads/



6. If using eclipse open it and add adt plugin
Top menu--> Help--> install new software --> add with name 'ADT' and site 'http://dl-ssl.google.com/android/eclipse/'
and set the sdk path in eclipse in preferences-->Android [ which we had downloaded ]