Updating Cucumber example doc

This commit is contained in:
Dylan Lacey
2014-05-02 16:32:41 -07:00
parent ef641634e0
commit 6cd4ebdfcd
4 changed files with 45 additions and 38 deletions
+2 -1
View File
@@ -2,4 +2,5 @@ source "https://www.rubygems.org"
gem 'appium_lib'
gem "rest-client"
gem "cucumber"
gem "cucumber"
gem "rspec-expectations"
@@ -6,10 +6,14 @@
#
# The instructions in the step are then executed with those variables.
#
# In this example, we're using rspec's assertions to test that things are happening, but you can use any ruby code you want in the steps.
# In this example, we're using rspec's assertions to test that things are happening,
# but you can use any ruby code you want in the steps.
#
# The 'selenium' object is our webdriver, set up in the cucumber/support/env.rb
# The '$driver' object is the appium_lib driver, set up in the cucumber/support/env.rb
# file, which is a convenient place to put it as we're likely to use it often.
# This is a different use to most of the examples; Cucumber steps are instances
# of `Object`, and extending Object with Appium methods (through
# `promote_appium_methods`) is a bad idea.
#
# For more on step definitions, check out the documentation at
# https://github.com/cucumber/cucumber/wiki/Step-Definitions
@@ -17,18 +21,32 @@
# For more on rspec assertions, check out
# https://www.relishapp.com/rspec/rspec-expectations/docs
Given /^I have entered (\d+) into field (\d+) of the calculator$/ do |value, field|
elements = selenium.find_elements(:class_name, "UIATextField")
elements[field.to_i - 1].send_keys value
# Get a textfield by index
textfield = textfield(field.to_i)
textfield.send_keys value
end
Given /^I have entered (\d+) into a field of the calculator showing (\w+)$/ do |value, field|
# Get a textfield by string
textfield = textfield field
textfield.send_keys value
end
And /^I press button (\d+)$/ do |button_index|
button = selenium.find_elements(:class_name, "UIAButton")[button_index.to_i - 1 ]
# Find a button by index
button = button(button_index.to_i)
button.click
end
And /^I press a button labelled (\w+)$/ do |button_text|
# Find a button by text
button = button button_text
button.click
end
Then /^the result should be displayed as (\d+)$/ do |expected|
result = selenium.find_element(:class_name, "UIAStaticText")
# You can get just the first of a class of elements
result = first_s_text
result.attribute("value").should eq expected
end
@@ -0,0 +1,5 @@
[caps]
platformName = "ios"
device = "iPhone Simulator"
platformVersion = "7.1"
app = "../../../apps/TestApp/build/release-iphonesimulator/TestApp.app"
@@ -1,6 +1,3 @@
# WHAT THIS FILE IS
# -----------------
#
# This file provides setup and common functionality across all features. It's
# included first before every test run, and the methods provided here can be
# used in any of the step definitions used in a test. This is a great place to
@@ -8,35 +5,21 @@
# test with, and the setup of selenium.
require 'rspec/expectations'
require 'selenium-webdriver'
require 'appium_lib'
require 'cucumber/ast'
# Where our app lives, relative to this file
APP_PATH = '../../../../../apps/TestApp/build/release-iphonesimulator/TestApp.app'
# What we need as a capability --> iOS device, where our app is, ect.
def desired_caps
{
'browserName' => '',
'platform' => 'Mac',
'device' => 'iPhone Simulator',
'version' => '7.1',
'app' => absolute_app_path
}
end
# Make sure the path above is relative to this file
def absolute_app_path
File.join(File.dirname(__FILE__), APP_PATH)
# Create a custom World class so we don't pollute `Object` with Appium methods
class AppiumWorld
end
# The location of our selenium (or in this case, Appium) file
def server_url
"http://127.0.0.1:4723/wd/hub"
end
# Set up a driver or, if one exists, return it
def selenium
@driver ||= Selenium::WebDriver.for(:remote, :desired_capabilities => desired_caps, :url => server_url)
# Load the desired configuration from appium.txt, create a driver then
# Add the methods to the world
caps = Appium.load_appium_txt file: File.expand_path('./', __FILE__), verbose: true
Appium::Driver.new(caps).start_driver
Appium.promote_appium_methods AppiumWorld
World do
AppiumWorld.new
end
After { @driver.quit }
After { $driver.driver_quit }