After several projects using Cucumber and Appium/Calabash I end up with kind of golden standard for the skeleton of tests. Nothing really special, but still it allows you to stop thinking about boilerplate and jump right into writing actual tests. The tree looks like this:
.
|__apk\
|__features\
| |__step_definitions\
| |__support\
| | |__app.rb
| | |__env.rb
|__Gemfile
|__Gemfile.lock
|__lib\
| |__page_object.rb
| |__page_objects\
And the content of these files is as follows:
# features/support/env.rb
Bundler.require :default
require_relative 'app'
require_relative '../../lib/page_object'
CAPABILITIES = { caps: { deviceName: 'Nexus',
platformName: 'android',
app: File.join(Dir.pwd, 'apk', 'AnApp.apk'),
newCommandTimeout: 300
},
appium_lib: { wait: 1 } }
Appium::Driver.new(CAPABILITIES)
Appium.promote_appium_methods([App, PageObject])
World(App)
wait_true
# features/support/app.rb
module App
def on(page_object_class)
if block_given?
yield page_object_class.new
else
page_object_class.new
end
end
end
on(LoginPage).login_with login, password
# lib/page_object.rb
module PageObject
end
Pathname('lib/page_objects').each_child { |file| require file.expand_path }
PageObject
module has to be included in every page object (those must be located in lib/page_objects
)Pathname('lib/page_objects')...
automatically requires every page object file. Has to be slightly improved in case page_objets has subdirectories.