mirror of
https://github.com/appium/appium.git
synced 2026-05-03 00:41:07 -05:00
Merge pull request #2466 from DylanLacey/update_docs
Update sauce example
This commit is contained in:
@@ -2,5 +2,6 @@ source "https://www.rubygems.org"
|
||||
|
||||
gem 'appium_lib'
|
||||
gem "rest-client"
|
||||
gem "rspec"
|
||||
gem "cucumber"
|
||||
gem "rspec-expectations"
|
||||
|
||||
@@ -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:
|
||||
# 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"
|
||||
#
|
||||
# gem install rspec selenium-webdriver rest-client
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user