version used:
appium: 1.15.1
cucumber: 3.1.2
ruby: 2.3.7
My project structure and files:
<my_project>/features/support/
appium.txt
env.rb
<my_project>/features/step_definitions
onboarding.rb
appium.txt:
[caps]
platformName = “iOS”
deviceName = “iPhone 7”
platformVersion = “12.2”
noReset = “true”
app = “/Users/lay.mui/Library/Developer/Xcode/DerivedData/Desk-eattgqttrmcniuchonszxzbtembb/Build/Products/Debug-iphonesimulator/Desk.app”
[appium_lib]
sauce_username = false
sauce_access_key = false
env.rb:
#ruby frameworks to require
require ‘rspec/expectations’
require ‘appium_lib’
#require ‘cucumber/ast’
require ‘rubygems’
Create a custom World class so we don’t pollute Object
with Appium methods
class AppiumWorld
end
#creating an array from the data in the YML file
#appLoginDetails = YAML.load_file(“features/support/appLoginDetails.yml”)
#this environment variable to choose which device we would do our automated tests on
case ENV[‘DEVICE_NAME’]
when ‘ipad simulator’
caps = Appium.load_appium_txt file: File.expand_path("/Users/lay.mui/Desktop/ERP-mobile/features/support/appium.txt", FILE), verbose: true
when ‘iphone simulator’
caps = Appium.load_appium_txt file: File.expand_path("/Users/lay.mui/Desktop/ERP-mobile/features/support/appium.txt", FILE), verbose: true
end
#this environment variable to choose the orientation that iOS device would be in for the automated tests.
case ENV[‘DEVICE_ORIENTATION’]
when ‘portrait’
caps[:caps].merge!(orientation:“PORTRAIT”)
when ‘landscape’
caps[:caps].merge!(orientation:“LANDSCAPE”)
end
#Display caps to make sure we are working wth the right ones
puts caps
Start the driver
$driver = Appium::Driver.new(caps)
Appium.promote_appium_methods AppiumWorld
World do
AppiumWorld.new
end
#before and after Cucumber hooks
Before do
$driver.start_driver
end
After do
$driver.driver_quit
end
onboarding.rb:
Given(“I open the app”) do
Aappium server is started
end
When(“I tap on the {string} button”) do |string|
puts string
find_element(:accessiblity_id, “Let’s Start”).click
#find_elements(:accessibility_id, “~Let’s Start”).tap
end
Then(“I should see the What do we call you screen”) do
end
When(“I tap the first name field and enter {string}”) do |string|
end
When(“I tap on the last name field and enter {string}”) do |string|
end
Then(“I should see the End-User License Agreement screen”) do
end
When(“I tap on the Accept”) do
end
Then(“I should see the Let’s get you started screen”) do
end
When(“I tap on the Mobile Number field and enter {string}”) do |string|
end
When(“I tap Send OTP button”) do
end
Then(“I should see the Confirm your number with One Time Password screen”) do
end
When I run the test:
cannot find element by :accessiblity_id. Available finders are [:class, :class_name, :css, :id, :link, :link_text, :name, :partial_link_text, :tag_name, :xpath, :accessibility_id, :image, :custom, :uiautomator, :viewtag, :data_matcher, :uiautomation, :predicate, :class_chain, :windows_uiautomation, :tizen_uiautomation]. (ArgumentError)