Monday, October 14, 2013

Appium on windows - Android automation using ruby

Prerequisite -

  1. Android SDK with API level 17 and above is available.
  2. Ruby 1.9 and selenium - webdriver gem is installed.
  3. OS variable ANDROID_HOME is pointing to SDK folder


Here are Quick Steps to Setup and Run Sample App using ruby selenium webdriver.


  1. Download latest Appium for Windows from https://bitbucket.org/appium/appium.app/ , unzip it.
  2. Start Emulator or Connect your Device using USB.
  3. Download ContactManager.apk from https://github.com/appium/appium/tree/master/sample-code/apps/ContactManager
  4. adb install ContactManager.apk.
  5. Click on Appium.exe from unzipped folder and Start Appium Server by clicking on Launch Button with Default parameters.
  6. Run below ruby code from cmd / irb 

------------------------------------------------------------



require 'selenium-webdriver'

capabilities = {
'device' => 'Android',
  'browserName' => '',
  'platform' => 'WINDOWS',
  'version' => '4.2.2',
  #'app' => 'http://localhost/ContactManager.apk',
'app-package' => 'com.example.android.contactmanager',
'app-activity' => 'ContactManager'
}

server_url = "http://127.0.0.1:4723/wd/hub"

@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)

btadd = @driver.find_element(:name, "Add Contact")
btadd.click()

textfields = @driver.find_elements(:tag_name,"textfield")
textfields[0].send_keys("Android_Appium")
textfields[2].send_keys("Android@Appium.com")
@driver.find_element(:name, "Save").click()

@driver.quit()


-----------------------------------------------




2 comments:

  1. Hello,
    I'm trying to do your thing but I've got this error : C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error).
    It's the first time I'm doing automation on Android device. Genymotion is runing, I can see the device with the command "adb devices"
    "List of devices attached
    192.168.56.101:5555 device"
    Appium.exe is running Node server.
    I'm in Rubymine. I've installed a good COntactmanager on the fake device, app is ok manually.
    I'm runing your script with this parameters :
    capabilities = {
    'deviceName' => 'Android',
    'browserName' => '',
    'platformName' => 'Android',
    'version' => '4.4.2',
    'app' => 'http://localhost/ContactManager.apk',
    'app-package' => 'com.example.android.contactmanager',
    'app-activity' => 'ContactManager'

    And TimeOut...
    I don't even know if I can reach my emulator.
    Can you help me on this ? It's been 10 days I'm trying, I'm completly lost !
    thanks a lot

    ReplyDelete
  2. can anyone explain it detail about installation

    ReplyDelete