-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
135 lines (98 loc) · 3.48 KB
/
Rakefile
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Prep ENV
require 'json'
require 'rest-client'
ENV['BROWSERSTACK_USER'] = "mohammedk1"
ENV['BROWSERSTACK_ACCESSKEY'] = "spBCpUJaVTnvxxssFtEJ"
# Automate - Single Test
task :single do
system "ruby web/single.rb"
end
# Automate - Parallel Tests
browser_list = File.read('web/browsers/browsers.json')
browsers = JSON.parse(browser_list)['browsers']
parallel_tests = Array.new
def run_parallel_test(browser)
command = "os=\"#{browser['os']}\" "
command += "os_version=\"#{browser['os_version']}\" "
command += "browser=\"#{browser['browser']}\" "
command += "browser_version=\"#{browser['browser_version']}\" "
command += "ruby web/parallel.rb"
system command
end
browsers.each_with_index do |browser, i|
eval "parallel_tests << :parallel_test_#{i}"
eval "task :parallel_test_#{i} do run_parallel_test(#{browser}) end"
end
multitask :parallel => parallel_tests
# Automate - Local Test
task :local do
system "ruby web/local.rb"
end
# Automate - Failed Test with API marker
task :fail do
system 'ruby web/fail.rb'
end
# Automate - Mobile Web tests
device_list = File.read('web/browsers/devices.json')
devices = JSON.parse(device_list)['devices']
mobile_tests = Array.new
def run_mobile_test(device)
command = "device=\"#{device['device']}\" "
command += "os_version=\"#{device['os_version']}\" " if device['os_version']
command += "ruby web/mobile.rb"
system command
end
devices.each_with_index do |device, i|
eval "mobile_tests << :mobile_test_#{i}"
eval "task :mobile_test_#{i} do run_mobile_test(#{device}) end"
end
multitask :mobile => mobile_tests
task :check_for_app_upload do
puts "Checking for uploaded apps..."
prev_uploads = RestClient.get "https://#{ENV["BROWSERSTACK_USER"]}:#{ENV["BROWSERSTACK_ACCESSKEY"]}@api.browserstack.com/app-automate/recent_apps/DemoApp"
prev_uploads = JSON.parse(prev_uploads)
if prev_uploads.class != Array || prev_uploads.size == 0
puts "No previous apps found. Uploading app..."
puts RestClient.post(
"https://#{ENV["BROWSERSTACK_USER"]}:#{ENV["BROWSERSTACK_ACCESSKEY"]}@api.browserstack.com/app-automate/upload",
{
file: File.new("./app/apps/WikipediaSample.apk", 'rb'),
data: {"custom_id": "DemoApp"}.to_json
}
)
else
puts "Using Previously Uploaded App:\n" + prev_uploads.last.to_s
end
end
# App Automate - Android Appium Test
task appium: :check_for_app_upload do
system 'ruby app/appium.rb'
end
# App Automate - Android Appium Parallel Tests
devices_list = File.read('app/devices/devices.json')
devices = JSON.parse(devices_list)['devices']
appium_parallel_tests = Array.new
def run_appium_parallel_test(device)
command = "device=\"#{device['device']}\" "
command += "os_version=\"#{device['os_version']}\" "
command += "project=\"#{device['project']}\" "
command += "build=\"#{device['build']}\" "
command += "name=\"#{device['name']}\" "
command += "ruby app/appium_parallel.rb"
system command
end
devices.each_with_index do |device, i|
eval "appium_parallel_tests << :appium_parallel_test_#{i}"
eval "task appium_parallel_test_#{i}: :check_for_app_upload do
run_appium_parallel_test(#{device})
end"
end
multitask :appium_parallel => appium_parallel_tests
# App Automate - Android Espresso Test
task :espresso do
system 'ruby app/espresso.rb'
end
# App Automate - iOS XCUITest Test
task :xcuitest do
system 'ruby app/xcuitest.rb'
end