Paste the following into Terminal. If you're not using RVM, you may have to prefix gem commands with sudo.
gem update --system ;\
gem update bundler
gem uninstall -aIx app_lib ;\
gem uninstall -aIx ruby_console ;\
gem install --no-rdoc --no-ri ruby_console
To update appium
from source (assuming node.js requires sudo):
Clone appium if you haven't already.
git clone [email protected]:appium/appium.git
then in the appium
folder:
git pull ;\
sudo ./reset.sh ; ./reset.sh
You should uninstall the ap
gem because it breaks awesome_print.
gem uninstall -aIx ap
The arc
command starts Appium Ruby Console.
Ruby 1.9.3 and Appium from GitHub are required. Run Appium from source.
node server.js -V --fast-reset
For OS X, export the path to your .app bundle MyApp.app
or zipped app bundle MyApp.app.zip
export APP_PATH="../MyApp.app"
For Android:
export APP_PATH="/path/to/my.apk" ;\
export APP_PACKAGE="com.my.Pkg" ;\
export APP_ACTIVITY="MyActivity"
You may want to define the environment variables in ~/.bash_profile
so you don't have to export them again.
Reset Appium after pulling the latest changes.
$ ./reset.sh
- find_elements returns an empty array [] when no elements are found.
- iOS UI Automation Example use
@driver.execute_script "UIATarget.localTarget().frontMostApp().mainWindow().rect()"
- Android UIAutomator
- Ruby selenium-webdriver
- Appium
- Appium extension
- mechanic names of elements
- All methods supported by Appium
- Appium's mobile gesture docs
Example use of Appium's mobile gesture.
@driver.execute_script 'mobile: tap', :x => 0, :y => 500
console.rb
uses some code from simple_test.rb and is released under the same license as Appium. The Accessibility Inspector is helpful for discovering button names and textfield values.
--
Tag Name | UIA --:|:-- button | UIAButton textfield | UIATextField secure | UIASecureTextField text | UIAStaticText
--
source
Prints a JSON view of the current page.
--
(void) alert_accept
Accept the alert.(String) alert_accept_text
Get the text of the alert's accept button.(void) alert_click(value)
iOS only Tap the alert button identified by value.(void) alert_dismiss
Dismiss the alert.(String) alert_dismiss_text
Get the text of the alert's dismiss button.(String) alert_text
Get the alert message text.
(Button) button(text, number = 0)
Find a button by text and optionally number.(Button) button_include(text)
Get the first button that includes text.(Array<String>, Array<Buttons>) buttons(text = nil)
Get an array of button texts or button elements if text is provided.(Array<Button>) buttons_include(text)
Get all buttons that include text.(Button) first_button
Get the first button element.(Button) last_button
Get the last button element.
(Array<Textfield>) e_textfields
Get an array of textfield elements.(Textfield) first_textfield
Get the first textfield element.(Textfield) last_textfield
Get the last textfield element.(Textfield) textfield(text)
Get the first textfield that matches text.(Textfield) textfield_include(text)
Get the first textfield that includes text.(Array<String>) textfields
Get an array of textfield texts.
(Array<Text>) e_texts
Get an array of text elements.(Text) first_text
Get the first text element.(Text) last_text
Get the last text element.(Text) text(text)
Get the first element that matches text.(Text) text_include(text)
Get the first textfield that includes text.(Array<String>) texts
Get an array of text texts.
(Object) window_size
Get the window's size.
--
e.name # button, text
e.value # secure, textfield
e.type
e.tag_name # calls .type (patch.rb)
e.text
e.size
e.location
e.rel_location
e.click
e.send_keys 'keys to send'
e.set_value 'value to set' # ruby_console specific
# alert example without helper methods
alert = $driver.switch_to.alert
alert.text
alert.accept
alert.dismiss
# Secure textfield example.
#
# Find using default value
s = secure 'Password'
# Enter password
s.send_keys 'hello'
# Check value
s.value == password('hello'.length)
routing.js lists not yet implemented end points.
--
driver
will restart the driver.
x
will quit the driver and exit Pry.
execute_script
calls $driver.execute_script
find_element
calls $driver.find_element
find_elements
calls $driver.find_elements
mobile :swipe, endX: 100, endY: 100, duration: 0.01
calls $driver.execute_script 'mobile: swipe', endX: 100, endY: 100, duration: 0.01
.click to tap an element. .send_keys to type on an element.
execute_script "au.lookup('button')[0].tap()"
is the same as
execute_script 'UIATarget.localTarget().frontMostApp().buttons()[0].tap()'
See app.js for more au methods. Note that raw UIAutomation commands are not offically supported.
Advanced au.
In this example we lookup two tags, combine the results, wrap with $, and then return the elements.
s = %(
var t = au.lookup('textfield');
var s = au.lookup('secure');
var r = $(t.concat(s));
au._returnElems(r);
)
execute_script s
See #194 for details.
find_element :xpath, 'button'
find_elements :xpath, 'button'
find_element :xpath, 'button[@name="Sign In"]'
find_elements :xpath, 'button[@name="Sign In"]'
find_element :xpath, 'button[contains(@name, "Sign In")]'
find_elements :xpath, 'button[contains(@name, "Sign")]'
find_element :xpath, 'textfield[@value="Email"]'
find_element :xpath, 'textfield[contains(@value, "Email")]'
find_element :xpath, 'text[contains(@name, "Reset")]'
find_elements :xpath, 'text[contains(@name, "agree")]'
Reset after each test and when done report the result to Sauce after quiting the driver.
require 'rest_client' # https://github.com/archiloque/rest-client
require 'json' # for .to_json
$passed = true
After do |scenario|
$driver.execute_script 'mobile: reset'
if $passed
$passed = false if scenario.failed?
end
end
at_exit do
ID = $driver.send(:bridge).session_id
$driver.quit
if !SAUCE_USERNAME.nil? && !SAUCE_ACCESS_KEY.nil?
URL = "https://#{SAUCE_USERNAME}:#{SAUCE_ACCESS_KEY}@saucelabs.com/rest/v1/#{SAUCE_USERNAME}/jobs/#{ID}"
# Keep trying until passed is set correctly. Give up after 30 seconds.
wait do
response = RestClient.put URL, { 'passed' => $passed }.to_json, :content_type => :json, :accept => :json
response = JSON.parse(response)
# Check that the server responded with the right value.
response['passed'] == $passed
end
end
end