GKTCS Innovations Pvt. Ltd.

Ruby, Appium, Android, Rspec, , Automation Testing

Surendra Panpaliya

Director, GKTCS Innovations Pvt. Ltd, Pune.

16 + Years of Experience ( MCA, PGDCS, BSc. [Electronics] , CCNA) Director , GKTCS Innovations Pvt. Ltd. Pune [ Nov 2009 – Till date ] IT Manager and Consultant at Rolta India Ltd, Mumbai [ April 2007 – Oct 2009 ] Associate Professor at Sinhgad Institute , Pune [Jan 2002 – April 2007] Instructor , ITM Bangalore [ May 2000 – Jan 2002 ] Project Trainee, DSYS Software Group, Bangalore [ Jan 1999 to April 2000] Skills ❑ Ruby, Rail,Appium, Python, Jython, Django, Android , PHP, LAMP ❑ Data Communication & Networking, CCNA ❑ UNIX /Linux Shell Scripting, System Programming ❑ CA Siteminder, Autosys, SSO, Service Desk, Service Delivery Author of 4 Books National Paper Presentation Awards at BARC Mumbai 2 Agenda ( Day 1)

• Introduction • Ruby installation • What’s New in Ruby • Ruby Data Types/ Data Structure • Ruby Comparison with Other Language ( Java/C+ + ) • Ruby Demo Script • Appium Introduction • Appium Installation Setup • Discussion

3 Agenda ( Day 2)

• Android adb commands • About Android AVD • About Appium Architecture • Appium Features • Using Appium to test Android Emulator/ Physical Device • Writing Ruby Scripts to Automate app through Appium • Discussion

4 Agenda ( Day 3)

• Manual Testing to Automation using Ruby • Execute and Automate Test • Rspec Introduction • Rspec Installation • Rspec for Automation • Rspec Demo • Pry Introduction • Debugging using Pry • Pry Demo • Discussion

5 Introduction

• What is Ruby? • What is difference between Scripting language and ? • What’s New in Ruby? • Ruby Installation • irb • Ruby Script execution.

6 Appium Introduction

What is Appium? • Appium is a mobile UI testing framework supporting cross-platform testing of native, hybrid and mobile-web apps for iOS and Android. • Appium enables you to execute your tests on mobile device irrespective of the device OS. • Framework is basically a wrapper that translates Selenium Webdriver commands into UIAutomation (iOS) or UIAutomator (Android) commands depending on the device type.

7 Appium Introduction

• What languages can I use to write the TestScripts? • You can write TestScripts in any language that Selenium WebDriver dependency is available for. This includes C#, Closure, Java, JavaScript with Node.js, Obj-C, Perl, Python, Ruby. • Appium is an open-source tool that can be used to automate your mobile applications. Just like the Selenium WebDriver - which is an open-source tool used to automate web browsers. • Appium is an automation library used to drive your mobile applications, and even the web browser within the mobile simulator, emulator or real device.

8 Advantages of using Appium

• It allows you to write tests against multiple mobile platforms using the same API. • You can write and run your tests u s i n g a n y l a n g u a g e o r t e s t framework. • It is an open-source tool that you can easily contribute to.

9 Limitations using APPIUM

• Appium does not support testing of Android Version lower than 4.2 • Limited support for hybrid app testing. eg: not possible to test the switching action of application from the web app to native and vice- versa. • No support to run Appium Inspector on Microsoft Windows.

10 APPIUM PHILOSOPHY

• Appium was designed to meet mobile automation needs according to a philosophy outlined by the following four tenets: • You shouldn’t have to recompile your app or modify it in any way in order to automate it. • You shouldn’t be locked into a specific language or framework to write and run your tests. • A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs. • A mobile automation framework should be open source, in spirit and practice as well as in name!

11 APPIUM Architecture APPIUM Architecture

• Appium runs on real devices and emulators. • It takes the Selenium commands from your test code and translates them into a readable format for UIAutomator, using the WebDriver JSON Wire Protocol. • WebDriver (aka "Selenium WebDriver") specifies a client- server protocol (known as the JSON Wire Protocol). • Given this client-server architecture, a client written in any language can be used to send the appropriate HTTP requests to the server. • The client libraries are simply HTTP clients and can be mixed into your code any way you please. • In other words, Appium & WebDriver clients are not technically "test frameworks" -- they are "automation libraries". Appium Concepts

• Client/Server Architecture • Appium is at its heart a webserver that exposes a REST API. It receives connections from a client, listens for commands, executes those commands on a mobile device, and responds with an HTTP response representing the result of the command execution. • The fact that we have a client/server architecture opens up a lot of possibilities: we can write our test code in any language that has a http client API, but it is easier to use one of the Appium client libraries. • We can put the server on a different machine than our tests are running on. • We can write test code and rely on a cloud service like Sauce Labs to receive and interpret the commands. Appium Concepts

• Session • Automation is always performed in the context of a session. Clients initiate a session with a server in ways specific to each library, but they all end up sending a POST /session request to the server, with a JSON object called the 'desired capabilities' object. • At this point the server will start up the automation session and respond with a session ID which is used for sending further commands. Appium Concepts

• Desired Capabilities • Desired capabilities are a set of keys and values (i.e., a map or hash) sent to the Appium server to tell the server what kind of automation session we're interested in starting up. • There are also various capabilities which can modify the behavior of the server during automation. • For example, we might set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android one. Or we might set the safariAllowPopups capability to true in order to ensure that, during a Safari automation session, we're allowed to use JavaScript to open up new windows. • http://appium.io/slate/en/master/?ruby#appium-server- capabilities • Appium Server • Appium is a server written in Node.js. It can be built and installed from source or installed directly from NPM. Appium Concepts

• Appium Clients • There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium's extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client. You can view the full list of libraries here.

• Appium.app, Appium.exe • There exist GUI wrappers around the Appium server that can be downloaded. These come bundled with everything required to run the Appium server, so you don't need to worry about Node. They also come with an Inspector, which enables you to check out the hierarchy of your app. This can come in handy when writing tests. workflow workflow Architecture workflow

• We have a UIAutomator/Selendroid in place of Apple instruments and bootstrap.jar in place of the bootstrap.js file. • Appium supports Android versions greater than or equal to 17; for earlier versions, it uses the Selendroid framework. • When we execute the test scripts, Appium sends the command to the UIAutomator or Selendroid on the basis of the Android version. • Here, bootstrap.jar plays the role of a TCP server, which we can use to send the test command in order to perform the action on the Android device using UIAutomator/Selendroid. Prerequisite

• ANDROID SDK • JDK (Java Development Kit) • TestNG • Eclipse • Selenium Server JAR • Webdriver Language Binding Library • APPIUM For Windows • APK App Info On Google Play • Node.js (Not Required - Whenever Appium server is installed, it by default comes with "Node.exe" & NPM. It's included in Current version of Appium.) Installation Steps

• 1. Install Java JDK • Edit your .bash_profile with "." before to update your environment to point correctly to java • $ cd • $ open -a TextEdit .bash_profile • If the file doesn't exist you will get the error:

• The file /Users/???/.bash_profile does not exist. • Then • $ touch .bash_profile • $ open -a TextEdit .bash_profile Installation Steps

• Insert into .bash_profile and save • export JAVA_HOME=$(/usr/libexec/java_home) • Restart the terminal to include the new configurations. In terminal type: • $ source .bash_profile • or just quit and reopen terminal • To test in terminal • $ java -version • For Older Mac OSX • Same as above but hardcode path and replace ?.?.? with your version • export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/?.?.?.jdk/Contents/Home • echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home Installation Steps

Surendras-MBP:~ SurendraMac$ .bash_profile export JAVA_HOME=/Library/Java/JavaVirtualMachines/ jdk1.8.0_60.jdk/Contents/Home export ANDROID_HOME=/Users/SurendraMac/Library/Android/sdk export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/tools:$PATH export PATH=$JAVA_HOME/:$PATH

# added by Anaconda 2.3.0 installer export PATH="/Users/SurendraMac/anaconda/bin:$PATH" Installation Steps

• 2. Install Android Studio/SDK

• Install all SDK tools and emulators • Select "Configure" • Select "SDK Manager" • Install all available packages Installation Steps

• 2. Install Android Studio/SDK Installation Steps

• 2. Install Android Studio/SDK • Edit your .bash_profile with "." before to update your environment to point correctly to Android • $ cd • $ pwd • the result will be /Users/???, Copy ??? for ANDROID_HOME below • $ open -a TextEdit .bash_profile • Insert into .bash_profile and save • export ANDROID_HOME=/Users/???/Library/Android/sdk • export ANDROID_SDK=$ANDROID_HOME • PATH=$PATH:$ANDROID_HOME/build-tools • PATH=$PATH:$ANDROID_HOME/tools • PATH=$PATH:$ANDROID_HOME/platform-tools • export PATH Installation Steps

• 2. Install Android Studio/SDK • Restart the terminal to include the new configurations. In terminal type: • $ source .bash_profile • or just quit and reopen terminal • $ echo $ANDROID_HOME Installation Steps

• 3. Install Xcode • Open App Store • Search for Xcode • Click Install (This can take a while) Installation Steps

• 4. Install Appium.dmg (Currently using 1.4.13) • Download appium 1.4.13 dmg • Open and Authorize • Update General Settings • UnCheck - "Check for updates" Installation Steps

• 4. Install Appium.dmg (Currently using 1.4.13) • Run Appium Doctor • Select Appium Doctor • Fix it "Y" • Yes to install "Command Line Tools Installation" • Fix it "Y" Installation Steps

• 5. Install Homebrew • Homebrew helps install the things you need for your Mac and it makes the following installations significantly easier. • copy "ruby -e .." from homebrew.sh page • open terminal and paste • $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/ Homebrew/install/master/install)" • $ brew doctor • $ brew update Installation Steps

Surendras-MBP:~ SurendraMac$ ruby -e "$(curl -fsSL https:// raw.githubusercontent.com/Homebrew/install/master/install)" It appears Homebrew is already installed. If your intent is to reinstall you should do the following before running this installer again: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/ Homebrew/install/master/uninstall)" The current contents of /usr/local are bin Cellar CODEOFCONDUCT.md CONTRIBUTING.md etc include join_air_data lib Library LICENSE.txt mysql mysql-5.6.26-osx10.8-x86_64 mysql-connector-python- cext-2.1.3 opt README.md share SUPPORTERS.md .git .gitignore Surendras-MBP:~ SurendraMac$ Installation Steps

6. Install ideviceinstaller (Needed for IOS applications)

Open terminal $ brew install --HEAD ideviceinstaller

7. Install ios-webkit-debug-proxy (Needed for IOS mobile web)

Open terminal $ brew install ios-webkit-debug-proxy

Installation Steps

Surendras-MBP:~ SurendraMac$ brew install --HEAD ideviceinstaller ==> Installing dependencies for ideviceinstaller: autoconf, automake, lib ==> Installing ideviceinstaller dependency: autoconf ==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.yosemite.bott ######################################################################## 100.0% ==> Pouring autoconf-2.69.yosemite.bottle.4.tar.gz ==> Caveats Lisp files have been installed to: /usr/local/share/emacs/site-lisp/autoconf ==> Summary � /usr/local/Cellar/autoconf/2.69: 70 files, 3.1M ==> Installing ideviceinstaller dependency: automake ==> Downloading https://homebrew.bintray.com/bottles/automake-1.15.yosemite.bott ######################################################################## 100.0% ==> Pouring automake-1.15.yosemite.bottle.2.tar.gz � /usr/local/Cellar/automake/1.15: 130 files, 3.2M ==> Installing ideviceinstaller dependency: libtool ..

Surendras-MBP:~ SurendraMac$ brew install ios-webkit-debug-proxy ==> Downloading https://homebrew.bintray.com/bottles/ios-webkit-debug-proxy-1.6. ######################################################################## 100.0% ==> Pouring ios-webkit-debug-proxy-1.6.yosemite.bottle.tar.gz � /usr/local/Cellar/ios-webkit-debug-proxy/1.6: 18 files, 396K Surendras-MBP:~ SurendraMac$ Installation Steps

8. Install Ruby with rbenv (Version 2.2.1 is Stable)

Open terminal $ brew install rbenv ruby-build $ rbenv install 2.2.1 $ rbenv local 2.2.1 $ rbenv global 2.2.1 $ rbenv rehash Installation Steps

Edit your .bash_profile with "." before to update your environment to point correctly to java $ cd $ open -a TextEdit .bash_profile Insert into .bash_profile and save

# Initialize rbenv if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

Restart the terminal to include the new configurations. In terminal type: $ source .bash_profile or just quit and reopen terminal Open terminal $ ruby --version Installation Steps

9. Install Bundler Bundler is a tool that helps manage your Ruby gems dependencies. Bundler website.

Opern terminal $ gem install bundler Appium Mobile Automation on Real Android Device with Chrome Browser

References: https://github.com/dentedghost/appium-training-matrix- mobile-web/commit/ bc6267617af00f1205b31f6a46c64be0b3bebbbd http://dentedghost.blogspot.in/2015/05/appium-step-by- step-installation.html http://dentedghost.blogspot.in/2015/05/appium-android- browser-emulator-simple.html http://www.androidcentral.com/android-201-10-basic-terminal-commands-you-should-know Appium Mobile Automation on Real Android Device with Chrome Browser

Tools Used: Mac Appium.dmg (>1.3.6) Android Studio (>1.2) Android SDK Manager (>24.2) Emulator64-arm Terminal TextEdit Chrome Browser (>42.0.2311) User-Agent Switcher (>1.8.6) Appium Mobile Automation on Real Android Device with Chrome Browser

Let's Begin Open Appium.dmg

Open Terminal

Open Android Studio

Open Chrome Appium Mobile Automation on Real Android Device with Chrome Browser

Code the Ruby/Appium automation At the command prompt in terminal "$". Don't type $

Setup the folder structure $ pwd You should see /Users/??? with ??? being your user or computer name. My suggestion is to create a folder called appium_ruby to store the examples but you can put it anywhere you want. If the directory doens't exist $ mkdir appium_ruby $ cd appium_ruby Next create a directory for this training example $ mkdir android-browser-emulator-simple $ cd android-browser-emulator-simple Appium Mobile Automation on Real Android Device with Chrome Browser

Setup Gemfiles We need to tell our automation program which version of appium_lib we want to use. We also need to do this for each automation we create. More Gemfile information is available at http://bundler.io/gemfile.html

Let's first check out the most current stable gem version of appium_lib at https://rubygems.org/gems/appium_lib/versions/ as of today the most current version is 8.0.0 as seen below: All versions of appium_lib

99 VERSIONS SINCE MARCH 22, 2013: 8.0.0 - October 8, 2015 (2.92 MB) 7.0.0 - May 8, 2015 (2.92 MB) 6.0.0 - January 26, 2015 (2.91 MB) 5.0.1 - December 30, 2014 (2.91 MB) 5.0.0 - December 23, 2014 (2.91 MB) Appium Mobile Automation on Real Android Device with Chrome Browser

Next we need to create the Gemfile and Gemfile.lock in the empty android-chrome-real-device-simple folder

First we need to make sure we have the correct TextEdit preferences or we can get some weird errors. Open TextEdit Open Preferences Update as seen below Select Plain Text Uncheck Smart copy/past Uncheck Smart quotes Uncheck Smart dashes Uncheck Smart links Appium Mobile Automation on Real Android Device with Chrome Browser Appium Mobile Automation on Real Android Device with Chrome Browser

Gemfile is the configuration file that will tell Bundler what and which version we need to have installed. Bundler will install what we ask and all the required dependencies.

$ bundle init $ ls You should see Gemfile $ open -a TextEdit Gemfile You should see:

# A sample Gemfile source "https://rubygems.org"

#gem "rails" gem ‘appium_lib' # insert this line Appium Mobile Automation on Real Android Device with Chrome Browser

Gemfile is the configuration file that will tell Bundler what and which version we need to have installed. Bundler will install what we ask and all the required dependencies.

$ bundle init $ ls You should see Gemfile $ open -a TextEdit Gemfile You should see:

# A sample Gemfile source "https://rubygems.org"

#gem "rails" gem ‘appium_lib' # insert this line Appium Mobile Automation on Real Android Device with Chrome Browser

Save: File -> Save (⌘S) Close: File -> Close (⌘W)

Now run bundler to install our file and all of it's dependencies. $ bundle install $ ls You should see Gemfile Gemfile.lock Appium Mobile Automation on Real Android Device with Chrome Browser

Surendras-MBP:appium_ruby SurendraMac$ cat Gemfile.lock GEM remote: https://rubygems.org/ specs: appium_lib (8.0.0) awesome_print (~> 1.6) json (~> 1.8) nokogiri (~> 1.6.6) selenium-webdriver (~> 2.48) toml (~> 0.0) awesome_print (1.6.1) blankslate (2.1.2.4) childprocess (0.5.7) ffi (~> 1.0, >= 1.0.11) ffi (1.9.10) json (1.8.3) mini_portile (0.6.2) multi_json (1.11.2) Appium Mobile Automation on Real Android Device with Chrome Browser

nokogiri (1.6.6.2) mini_portile (~> 0.6.0) parslet (1.5.0) blankslate (~> 2.0) rubyzip (1.1.7) selenium-webdriver (2.48.1) childprocess (~> 0.5) multi_json (~> 1.0) rubyzip (~> 1.0) websocket (~> 1.0) toml (0.1.2) parslet (~> 1.5.0) websocket (1.2.2)

PLATFORMS ruby

DEPENDENCIES appium_lib

BUNDLED WITH 1.10.6 Surendras-MBP:appium_ruby SurendraMac$ Appium Mobile Automation on Real Android Device with Chrome Browser

Code Appium/Ruby automation $ touch simple.rb $ open -a TextEdit simple.rb Include the needed gems: require 'rubygems' require ‘appium_lib'

Next we need to configure our call to the Appium Server. More information is available at http://appium.io/slate/en/master/?ruby#appium-server-capabilities. desired_caps = { caps: { platformName: 'Android', platfromVersion: '5.1', deviceName: 'Nexus_5_API_22', browserName: 'Browser', } } Appium Mobile Automation on Real Android Device with Chrome Browser

Create a new Appium driver. More information at http://www.rubydoc.info/github/appium/ruby_lib/Appium/Driver:initialize

Appium specific driver with helpers available.

@appium_driver = Appium::Driver.new(desired_caps)

Standard Selenium driver without any Appium methods.

@selenium_driver = @appium_driver.start_driver

Appium.promote_appium_methods Object

@selenium_driver.get(“http://www.google.com/“) Appium Mobile Automation on Real Android Device with Chrome Browser

Now promote appium methods to class instance methods. More information at http://www.rubydoc.info/github/appium/ruby_lib/Appium.promote_appium_methods

Appium.promote_appium_methods Object

Without promoting we would need to make all calls with the @appium_driver, example:

@appium_driver.find_element(:id, 'lst-ib')

After promoting to a class instance method we can the method directly, example: find_element(:id, 'lst-ib') Next open the mobile version of the Google search.

@selenium_driver.get("http://www.google.com/") start Appium Server with Devices Capabilities. Appium Mobile Automation on Real Android Device with Chrome Browser

Deep dive on getting Appium Server Capabilities (Caps) Find platformVersion: On your Android device the platformVersion is the Android Version : Go to Settings -> About Phone Read Android Version If need truncate to one decimal place. i.e. 4.4.4 to 4.4 Example: platformVersion: ‘4.4' Appium Mobile Automation on Real Android Device with Chrome Browser Appium Mobile Automation on Real Android Device with Chrome Browser

Find browserName: Go to Settings -> Apps Read Browser Name Example: browserName: ‘Chrome' Appium Mobile Automation on Real Android Device with Chrome Browser

Find deviceName: Go to Settings -> About Phone -> Status Read Serial number Example: browserName: ‘TA96515UMI' Appium Mobile Automation on Real Android Device with Chrome Browser

Appium - Android Settings Select Platform Name in pull down: Android Select Automation Name in pull down: Appium Select Platform Version in pull down (Overwrite if necessary) Example: 4.4 KitKat (API Level 19) Check Device Name then enter Device Name Example: TA96515UM Appium Mobile Automation on Real Android Device with Chrome Browser Appium Mobile Automation on Real Android Device with Chrome Browser

Enable Developer Options on your Android Device Hidden away from the average user but easy to enable is Developer options.

First step, plug your device into your Mac via USB

You need to navigate to "Build Number" unfortunately it can be in different places on the Android Devices. Below are command locations to find it:

Stock Android: Settings -> About phone -> Build number Samsung Galaxy S5: Settings -> About device -> Build number LG G3: Settings -> About phone -> Software information -> Build number HTC One (M8): Settings -> About -> Software information -> More -> Build number Appium Mobile Automation on Real Android Device with Chrome Browser

Setting screen before Developer options is enabled: Appium Mobile Automation on Real Android Device with Chrome Browser

After finding the "Build number" then tap on the section 7 times. After two taps a notification pop should appear saying "you are now 'X' steps away from being a developer" then count down until after the 7th tap and it will say "You are now a developer!". A Developer options section will now be present. Appium Mobile Automation on Real Android Device with Chrome Browser

With Developer options enabled, now find and tap on Developer options so we can enable USB Debugging. Appium Mobile Automation on Real Android Device with Chrome Browser

With Developer options enabled, now find and tap on Developer options so we can enable USB Debugging. Appium Mobile Automation on Real Android Device with Chrome Browser

Check USB debugging OK "Allow USB debugging" OK "Allow USB debugging" for a computer with RSA Key Appium Mobile Automation on Real Android Device with Chrome Browser

Click "OK" to Allow USB debugging Appium Mobile Automation on Real Android Device with Chrome Browser

Click "OK" to Allow USB debugging for Mac computer Appium Mobile Automation on Real Android Device with Chrome Browser

Make Sure Device Is Connected Connect your device to your Mac via USB Open Terminal $ adb devices You should see the Device Name

Surendras-MBP:appium_ruby SurendraMac$ adb devices List of devices attached emulator-5554 device

Surendras-MBP:appium_ruby SurendraMac$ Appium Mobile Automation on Real Android Device with Chrome Browser

Lauching Appium The correct command line parameters for starting the Appium server which is shown after "Launching Appium with command:" The right Appium server: "Welcome to Appium v1.3.6" A green status 200 shown the Appium server is up and running. Appium Mobile Automation on Real Android Device with Chrome Browser Appium Mobile Automation on Real Android Device with Chrome Browser

Running the Ruby/Appium Automation After successfully launching the Appium server open Terminal in the directory with simple.rb. To run the automation: $ ruby simple.rb What to expect Appium server window will display a lot of information as it starts. Your device will open up Chrome Google.com will then be opened Appium Mobile Automation on Real Android Device with Chrome Browser

Finding Elements For mobile web, I prefer to using Chrome after changing the user agent. Inspect Element in Chrome Chrome extension for changing user- agents The unique identifiers for pages can be different between the web and mobile web version. So make sure to switch the user agent to what device you will be testing on.

Let's change the user agent to Android. Select User Agent Switcher (or Similar) Select Samsung Galaxy S3 (Headset) Select User Agent Switcher to close Appium Mobile Automation on Real Android Device with Chrome Browser

With Android User Agent select. open http://www.google.com You should see the mobile version. Now inspect the Search Box. Right mouse click above the Search Box -> Inspect Element Appium Mobile Automation on Real Android Device with Chrome Browser This will spawn the inspector Appium Mobile Automation on Real Android Device with Chrome Browser

The inspected details are:

When possible for finding mobile web elements use id. Capturing the id since it provide a unique id and provides the fastest time to be found on the page. id="lst-ib" Next Inspect the Search Button:

id=“tsbb" Appium Mobile Automation on Real Android Device with Chrome Browser

Add Code Automate Search We will add code after:

@selenium_driver.get("http://www.google.com/") $ open -a TextEdit simple.rb To ensure the page has time to load before we start add a pause

sleep(5)

Next we need to find the Search Box element on the page. If we are unable to find the element the automation will fail.

element = find_element(:id, 'lst-ib') Appium Mobile Automation on Real Android Device with Chrome Browser

Now we need to click in the Search Box before we can start to type our query.

element.click

Type our search command

element.send_keys 'Steven Miller Dentedghost Appium'

Add an extra pause for demonstration

sleep(2) Appium Mobile Automation on Real Android Device with Chrome Browser

Find the Search Button element on the page then click on it.

element = find_element(:id, 'tsbb') element.click

To ensure the page has time to load

sleep(5)

Properly close the driver and print Appium automation successful test pass message. Appium Mobile Automation on Real Android Device with Chrome Browser

Properly close the driver and print Appium automation successful test pass message.

driver_quit puts 'Tests Succeeded!'

Search results:

Appium Mobile Automation on Real Android Device with Chrome Browser

Execution Results:

$ ruby simple.rb Tests Succeeded

Code Summary Available at: https://github.com/dentedghost/ appium-training-matrix-mobile-web Appium Mobile Automation on Real Android Device with Chrome Browser http://dentedghost.blogspot.in/2015/06/appium-testers-perspective-for-ios.html Appium Troubleshooting Steps

Troubleshooting Steps

1. error:- The following desired capabilities are required, but were not provided:device Name, platformName

1. Add desired capabilities: device Name, platformName in APPIUM script. e.g:capabilities.setCapability("deviceName","Emulator"); capabilities.setCapability("platformName","Android");

2. error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path. 2. You probably need to set up SDK root directory path in system 'Environment Variables' in 'Path' column

3.error:org.openqa.selenium.SessionNotCreatedException: A new session could not be created.

3. You need to set a correct App path and restart the Appium server.

4. How to find DOM element or xPath in mobile application?

4. Use 'UIAutomatorviewer' to find DOM element for Android application. Surendras-MBP:appium_ruby SurendraMac$ adb shell pm list packages -f

/system/app/Calculator/Calculator.apk=com.android.calculator2 adb shell pm path com.example.someapp adb shell pm path com.android.calculator2

adb bugreport Surendras-MacBook-Pro:~ SurendraMac$ adb bugreport | grep 'calculator' 11-18 03:57:57.140 1304 1304 W PackageManager: Failure retrieving resources for com.android.calculator2: Resource ID #0x0 * Recent #3: TaskRecord{19d0f79 #29 A=com.android.calculator2 U=0 sz=0} affinity=com.android.calculator2 intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.calculator2/.Calculator} realActivity=com.android.calculator2/.Calculator 0 : com.android.calculator2 +10h24m37s950ms (2) 050 c0d8061a +top=u0a16:"com.android.calculator2" +10h38m43s374ms (3) 050 c0d8061a brightness=medium -top=u0a16:"com.android.calculator2" 3aaecf9f com.android.calculator2/.Calculator [com.android.calculator2] Package [com.android.calculator2] (249aca22): pkg=Package{37ca9cb3 com.android.calculator2} applicationInfo=ApplicationInfo{22757270 com.android.calculator2} dataDir=/data/data/com.android.calculator2 * com.android.calculator2 / u0a16 / v22:

Process com.android.calculator2 (unique, 3 entries): myID=37458723 mCommonProcess=37458723 mPackage=com.android.calculator2 * com.android.calculator2 / u0a16 / v22: * com.android.calculator2 / u0a16 / v22: Surendras-MacBook-Pro:~ SurendraMac$ adb bugreport | grep 'calculator'

Process com.android.calculator2 (unique, 3 entries): myID=33d31198 mCommonProcess=33d31198 mPackage=com.android.calculator2 * com.android.calculator2 / u0a16 / v22: package=com.android.calculator2 totalTime="14:05" lastTime="11/17/2015, 6:56 PM" time="11/17/2015, 6:42 PM" type=MOVE_TO_FOREGROUND package=com.android.calculator2 class=com.android.calculator2.Calculator time="11/17/2015, 6:56 PM" type=MOVE_TO_BACKGROUND package=com.android.calculator2 class=com.android.calculator2.Calculator package=com.android.calculator2 totalTime="14:05" lastTime="11/17/2015, 6:56 PM" 9,hsp,12,10016,"com.android.calculator2" pss,com.android.calculator2,10016,1nt:7:9470:9587:9887:6696:6786:7008,1ne: 5:7516:7628:7981:4988:5064:5140 package=com.android.calculator2 totalTime="14:05" lastTime="11/17/2015, 6:56 PM" time="11/17/2015, 6:42 PM" type=MOVE_TO_FOREGROUND package=com.android.calculator2 class=com.android.calculator2.Calculator time="11/17/2015, 6:56 PM" type=MOVE_TO_BACKGROUND package=com.android.calculator2 class=com.android.calculator2.Calculator package=com.android.calculator2 totalTime="14:05" lastTime="11/17/2015, 6:56 PM"

Surendras-MacBook-Pro:~ SurendraMac$ adb bugreport | grep ‘codePath' codePath=/data/app/com.example.surendramac.myapplication1-1 codePath=/data/app/com.example.surendramac.myapplication1.test-1 codePath=/system/app/Calculator codePath=/data/app/GestureBuilder codePath=/system/priv-app/VpnDialogs codePath=/system/app/Email codePath=/system/app/Music

Surendras-MacBook-Pro:~ SurendraMac$ adb shell pm list package package:com.android.smoketest package:com.example.android.livecubes package:com.android.providers.telephony package:io.appium.settings package:com.android.providers.calendar package:com.android.providers.media package:com.android.protips package:com.android.launcher package:com.android.documentsui

Package manager (pm) over adb shell to list packages: adb shell pm list packages and to display where the .apk file is: adb shell pm path com.king.candycrushsaga package:/data/app/com.king.candycrushsaga-1/base.apk

And adb pull to download the apk. adb pull data/app/com.king.candycrushsaga-1/base.apk

adb bugreport | grep 'package name="' | grep 'codePath="/data' | cut -d'"' -f4 Surendras-MacBook-Pro:~ SurendraMac$ adb bugreport | grep '/data/app' 11-18 03:57:53.701 1230 1230 W PackageParser: No actions in intent filter at /data/app/ ApiDemos/ApiDemos.apk Binary XML file line #3027 11-18 03:57:53.701 1230 1230 W PackageParser: No actions in intent filter at /data/app/ ApiDemos/ApiDemos.apk Binary XML file line #3033 11-18 03:57:53.851 1230 1230 D PackageManager: No files in app dir /data/app-private codePath=/data/app/SmokeTestApp resourcePath=/data/app/SmokeTestApp legacyNativeLibraryDir=/data/app/SmokeTestApp/lib codePath=/data/app/CubeLiveWallpapers resourcePath=/data/app/CubeLiveWallpapers legacyNativeLibraryDir=/data/app/CubeLiveWallpapers/lib codePath=/data/app/io.appium.settings-1 resourcePath=/data/app/io.appium.settings-1 legacyNativeLibraryDir=/data/app/io.appium.settings-1/lib codePath=/data/app/com.example.surendramac.myapplication1-1 resourcePath=/data/app/com.example.surendramac.myapplication1-1 legacyNativeLibraryDir=/data/app/com.example.surendramac.myapplication1-1/lib adb bugreport | grep ‘/system/app'

Surendras-MacBook-Pro:~ SurendraMac$ adb bugreport | grep '/system/app' 680K /system/app/LatinIME/LatinIME.apk 668K /system/app/Email/Email.apk 444K /system/app/DeskClock/DeskClock.apk 416K /system/app/Calendar/Calendar.apk 92K /system/app/PrintSpooler/PrintSpooler.apk 64K /system/app/Exchange2/Exchange2.apk Thanks

Surendra R Panpaliya, International Corporate Trainer and Consultant GKTCS Innovations Pvt. Ltd, Near Warje Flyover Bridge, Warje-Malwadi, Pune-411058 Email: Surendra R Panpaliya, Founder and Director, GKTCS Innovations Pvt. Ltd, 11, 4th Floor,Sneh Deep, Near Warje Flyover Bridge, Warje-Malwadi, Pune-411058 Email: [email protected] Web:www.gktcs.com

90