Last active
December 23, 2015 00:09
-
-
Save dbwest/6551886 to your computer and use it in GitHub Desktop.
An example script, and accompanying Gemfile, to use for automating the Chrome mobile browser on an Android device. Tested on OS X Mountain Lion. Appium installed using node for CLI. If you don't have a fast android emulator, try genymotion...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect your device or start your emulator before running this script | |
# make sure appium and chromedriver aren't started yet. | |
#`killall node` | |
`killall chromedriver` | |
#start appium server for chrome pkg and redirect stderr and stdout to keep terminal clean | |
#`appium --app-pkg com.android.chrome & > /dev/null 2>&1` | |
#prepare device | |
`adb kill-server` | |
`adb devices` | |
require 'fileutils' | |
require 'watir-webdriver' | |
require 'selenium-webdriver' | |
# The address and port of our Appium server | |
server_url = "http://localhost:4723/wd/hub/" | |
# Hash with information selenium webdriver needs | |
capabilities = | |
{ | |
'app' => 'chrome', | |
'device' => 'Android' | |
} | |
#Setup webdrivers to talk to Appium and mobile chrome and use implicit_waits to poll with long timeout to see if pages are loaded | |
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)#, :profile => profile) | |
browser = Watir::Browser.new driver | |
browser.driver.manage.timeouts.implicit_wait = 30 | |
puts "new ANDROID Watir browser object instantiated" | |
#automated browser code using Watir browser object and methods | |
browser.goto "http://saucelabs.com/test/guinea-pig" | |
browser.text_field(:id=>"fbemail").set '[email protected]' | |
sleep 1 | |
#screenshot code | |
%x(adb shell /system/bin/screencap -p /sdcard/screenshot.png) | |
time = Time.now.to_i.to_s | |
puts 'current directory is' + `pwd` | |
%x(adb pull /sdcard/screenshot.png ./images/screenshot.png) | |
FileUtils.mv('./images/screenshot.png', './images/screenshot' + time + '.png') | |
%x(adb shell rm /sdcard/screenshot.png) | |
`open images/.` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
gem 'watir-webdriver' | |
gem 'selenium-webdriver' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment