Skip to content

Commit

Permalink
Merge pull request appium#2466 from DylanLacey/update_docs
Browse files Browse the repository at this point in the history
Update sauce example
  • Loading branch information
Dylan Lacey committed May 3, 2014
2 parents 28ac080 + 03dbf95 commit f0a00fa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions sample-code/examples/ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ source "https://www.rubygems.org"

gem 'appium_lib'
gem "rest-client"
gem "rspec"
gem "cucumber"
gem "rspec-expectations"
64 changes: 40 additions & 24 deletions sample-code/examples/ruby/sauce_example.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,78 @@
# This is an example test for Sauce Labs and Appium.
# It expects SAUCE_USERNAME and SAUCE_ACCESS_KEY to be set in your environment.
# GETTING STARTED
# -----------------
# This documentation is intended to show you how to get started with a
# simple Appium & Sauce Labs test. This example is written with rspec and
# appium_lib, but you can use any Selenium client and test framework you like.
#
# Before this test will work, you may need to do:
#
# gem install rspec selenium-webdriver rest-client
# This example expects SAUCE_USERNAME and SAUCE_ACCESS_KEY to be set in your
# environment.
#
# INSTALLING RVM
# --------------
# We're assuming you've got rvm installed, but if not, from a terminal
# run the following line (removing the ""'s):
#
# "\curl -L https://get.rvm.io | bash -s stable --ruby"
#
# INSTALLING GEMS
# ---------------
# Then, change to the example directory:
# "cd appium-location/sample-code/examples/ruby"
#
# and install the required gems with bundler by doing:
# "bundle install"
#
# RUNNING TESTS
# -------------
# Run with:
#
# rspec sauce_example.rb
# bundle exec rspec sauce_example.rb
require 'rspec'
require 'selenium-webdriver'
require 'appium_lib'
require 'json'
require 'rest_client'

APP_PATH = 'http://appium.s3.amazonaws.com/TestApp6.0.app.zip'
SAUCE_USERNAME = ENV['SAUCE_USERNAME']
SAUCE_ACCESS_KEY = ENV['SAUCE_ACCESS_KEY']

# This is the test itself
describe "Computation" do
before(:each) do
@driver = Selenium::WebDriver.for(
:remote,
:desired_capabilities => desired_caps,
:url => server_url
)
Appium::Driver.new(caps: desired_caps).start_driver
Appium.promote_appium_methods RSpec::Core::ExampleGroup
end

after(:each) do
# Get the success by checking for assertion exceptions,
# and log them against the job, which is exposed by the session_id
job_id = @driver.send(:bridge).session_id
job_id = driver.send(:bridge).session_id
update_job_success(job_id, example.exception.nil?)
@driver.quit
driver_quit
end

it "should add two numbers" do
values = [rand(10), rand(10)]
expected_sum = values.reduce(&:+)
elements = @driver.find_elements(:tag_name, 'textField')
# Standard selectors work to find elements
elements = find_elements :class_name, 'UIATextField'

elements.each_with_index do |element, index|
element.send_keys values[index]
end

@driver.find_elements(:tag_name, 'button')[0].click
@driver.find_elements(:tag_name, 'staticText')[0].text.should eq expected_sum.to_s
button(1).click
first_s_text.text.should eq expected_sum.to_s
end
end

def desired_caps
{
'browserName' => '',
'platform' => 'Mac 10.8',
'version' => '6.1',
'device' => 'iPhone Simulator',
'app' => APP_PATH,
'name' => 'Ruby Example for Appium',
'appium-version' => '1.0.0-beta.2',
'platformName' => 'iOS',
'platformVersion' => '7.1',
'deviceName' => 'iPhone Simulator',
'app' => 'http://appium.s3.amazonaws.com/TestApp6.0.app.zip',
'name' => 'Ruby Example for Appium'
}
end

Expand Down

0 comments on commit f0a00fa

Please sign in to comment.