Skip to content

Instantly share code, notes, and snippets.

@whitneyimura
Last active December 25, 2015 13:19
Show Gist options
  • Save whitneyimura/6983137 to your computer and use it in GitHub Desktop.
Save whitneyimura/6983137 to your computer and use it in GitHub Desktop.
Sample Env.rb file for Appium Android
require 'rubygems'
require 'appium_lib'
# Start Android driver
apk = {
device: :android,
app_path: (true && ENV['apk']) || (ENV['PWD'] + '/../App/build/apk/foo.apk'),
app_package: (true && ENV['package']) || 'com.google.foo',
app_activity: (true && ENV['activity']) || '.fooActivity',
app_wait_activity: (true && ENV['activity']) || 'foo.BarActivity',
}
Appium::Driver.new(apk).start_driver
Appium.promote_appium_methods Object
log = Logger.new(STDOUT)
case ENV['log']
when 'WARN'
log.level = Logger::WARN
when 'DEBUG'
log.level = Logger::DEBUG
when 'INFO'
log.level = Logger::INFO
when 'ERROR'
log.level = Logger::ERROR
when 'FATAL'
log.level = Logger::FATAL
when 'UNKNOWN'
log.level = Logger::UNKNOWN
else
log.level = Logger::DEBUG
end
log.debug('starting suite')
Before do
@test_env = {
device: driver,
main_activity: (true && ENV['main_activity']) || apk[:app_wait_activity],
logger: log
}
end
After ('@rate_limit') do |scenario|
log = @test_env[:logger]
device = @test_env[:device]
if scenario.failed?
begin
wait = Selenium::WebDriver::Wait.new :timeout => 1
wait.until { device.alert_accept }
log.debug('cleared rate limit dialog')
rescue
log.error("dialog didn't pop.")
end
end
log.debug('rate_limit finished')
end
After ('@network_connection') do |scenario|
log = @test_env[:logger]
device = @test_env[:device]
if scenario.failed?
begin
wait = Selenium::WebDriver::Wait.new :timeout => 1
wait.until { device.alert_accept }
log.debug('cleared network connection issue')
rescue
log.error("dialog didn't pop.")
end
end
log.debug('network_connection finished')
end
After ('@needs_back_button') do
@activity.click_back
end
Before ('@needs_login') do
@fragment = LoginActivity.new(@test_env)
@fragment.load_login_home
@fragment.input_username
@fragment.input_password
@fragment = BaseActivity.new(@test_env)
@fragment.click_back
@fragment = LoginActivity.new(@test_env)
@fragment.sign_in_button.click
@fragment.login_activity_fragment
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment