<% if with_lib == 'true' -%> $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))

<% end -%> require 'rspec' <% if with_appium == 'false' and with_mohawk == 'false' -%> require 'page-object' require 'data_magic' <% end -%> <% if with_mohawk == 'true' -%> require 'mohawk' require 'win32/screenshot' <% end -%> <% if with_lib == 'true' -%> require 'require_all'

require_all 'lib' <% end -%>

<% if with_appium == 'true' -%> require 'appium_lib'

class AppiumWorld end

PROJECT_DIR = File.expand_path(File.dirname(__FILE__) + '../../..')

@desired_caps = {
         caps: {
             platformName: 'android',
             deviceName: ENV['DEVICE_NAME'],
             app: '<your_app>',
         },
         appium_lib: {
             port: 4723
         }
     }
Appium::Driver.new(@desired_caps).start_driver
Appium.promote_appium_methods Object

World do

AppiumWorld.new

end

at_exit do

driver_quit

end <% end -%> <% if with_appium == 'false' and with_mohawk == 'false' -%> World(PageObject::PageFactory) <% end -%> <% if with_mohawk == 'true' -%> World(Mohawk::Navigation) Mohawk.app_path = PATH_TO_EXECUTABLE

def capture_screenshot(name)

Dir.mkdir('screenshots') unless Dir.exist? 'screenshots'
now = Time.now.to_s.gsub(/\W+/, '.')
Win32::Screenshot::Take.of(:desktop).write("screenshots/#{now}.#{name}.png")

end

Before do

Mohawk.start

end

After do |scenario|

capture_screenshot(scenario.name.gsub(/\W+/,'_')) if scenario.failed?
Mohawk.stop

end <% end -%>