forked from bitbar/test-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_appium.rb
More file actions
71 lines (59 loc) · 2.15 KB
/
Copy pathsetup_appium.rb
File metadata and controls
71 lines (59 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'fileutils'
class SetupAppium
@@screenshot_dir = './target/reports/screenshots/'
app_file_android = Dir.glob 'application.apk'
app_file_ios = Dir.glob 'application.ipa'
app_path = Dir.pwd
@@app_file_android = File.join(app_path, app_file_android)
@@app_file_ios = File.join(app_path, app_file_ios)
@@udid = ENV['IOS_UDID']
def self.screenshot_dir
# Return the value of this variable
@@screenshot_dir
end
def log(msg)
puts "#{Time.now}: #{msg}"
end
def get_android_driver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['automationName'] = 'Appium'
desired_caps['appPackage'] = 'com.bitbar.testdroid'
desired_caps['appActivity'] = '.BitbarSampleApplicationActivity'
desired_caps['deviceName'] = 'Android device'
desired_caps['app'] = "#{@@app_file_android}"
server_url = 'http://localhost:4723/wd/hub'
@driver = Appium::Driver.new({:caps => desired_caps, :appium_lib => {:server_url => server_url}, :global_driver => true})
@driver.start_driver()
# Wait max 30 seconds for elements
@driver.set_implicit_wait(30)
log("WebDriver response received")
return @driver
end
def get_ios_driver
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['automationName'] = 'XCUITest'
desired_caps['bundleId'] = 'com.bitbar.testdroid.BitbarIOSSample'
desired_caps['deviceName'] = 'iPhone device'
desired_caps['udid'] = "auto" # Use #{@@udid} if desired fixed udid
desired_caps['app'] = "#{@@app_file_ios}"
server_url = 'http://localhost:4723/wd/hub'
@driver = Appium::Driver.new({:caps => desired_caps, :appium_lib => {:server_url => server_url}, :global_driver => true})
@driver.start_driver()
# Wait max 30 seconds for elements
@driver.set_implicit_wait(30)
log("WebDriver response received")
return @driver
end
def quit_driver
@driver.driver_quit
end
def set_screenshot_dir
log("Will save screenshots at: #{@@screenshot_dir}")
unless File.directory?(@@screenshot_dir)
log('Creating directory %s' % @@screenshot_dir)
FileUtils.mkdir_p(@@screenshot_dir)
end
end
end