Skip to content

Commit 1ff8175

Browse files
committed
specify multiple apks connected
1 parent 0a43a44 commit 1ff8175

File tree

7 files changed

+83
-30
lines changed

7 files changed

+83
-30
lines changed

bin/kraken-mobile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ end
3838
def user_entered_apk_path
3939
return nil if ARGV.first.nil?
4040

41-
File.expand_path(ARGV.first)
41+
first_argument = ARGV.first
42+
return nil if first_argument.start_with?('--') # Is argument parameter not apk
43+
44+
File.expand_path(first_argument)
4245
end
4346

4447
#-------------------------------

bin/kraken_mobile_calabash_android.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@
66
'calabash-android-features-skeleton'
77
)
88

9-
def handle_calabash_android(configuration, properties_path)
9+
def handle_calabash_android(config_path, properties_path)
1010
require 'kraken-mobile/constants'
1111
require 'calabash-android/helpers'
12-
#options = {}
13-
#if configuration
14-
# ensure_configuration_is_valid File.expand_path(configuration)
15-
# options[:config_path] = File.expand_path(configuration)
16-
#else
17-
# ensure_apk_is_specified
18-
# options[:apk_path] = ARGV.first
19-
#end
12+
2013
kraken = KrakenApp.new(
2114
apk_path: user_entered_apk_path,
22-
properties_path: format_properties(properties_path)
15+
properties_path: format_properties(properties_path),
16+
config_path: format_config(config_path)
2317
)
2418
kraken.start
2519
end
@@ -34,3 +28,12 @@ def format_properties(properties_path)
3428

3529
properties_absolute_path
3630
end
31+
32+
def format_config(config_path)
33+
return if config_path.nil?
34+
35+
config_absolute_path = File.expand_path(config_path)
36+
ensure_configuration_is_valid(config_absolute_path)
37+
38+
config_absolute_path
39+
end

lib/kraken-mobile/mobile/mobile_process.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,39 @@ def execution_command
3838
#{feature_path} --tags @user#{id}"
3939
end
4040

41+
#-------------------------------
42+
# Helpers
43+
#-------------------------------
44+
4145
def apk_path
42-
@test_scenario&.kraken_app&.apk_path_for_process_id(@id)
46+
return config_apk_path if @test_scenario.requires_predefined_devices?
47+
48+
path = @test_scenario&.kraken_app&.apk_path
49+
raise 'ERROR: Invalid APK file path' if path.nil?
50+
51+
path
52+
end
53+
54+
def config_json
55+
config_absolute_path = File.expand_path(ENV[K::CONFIG_PATH])
56+
file = open(config_absolute_path)
57+
content = file.read
58+
JSON.parse(content)[@id.to_s] || {}
59+
end
60+
61+
def config_apk_path
62+
device_config_json = config_json
63+
return if device_config_json['config'].nil?
64+
return if device_config_json['config']['apk_path'].nil?
65+
66+
absolute_config_apk_path = File.expand_path(
67+
device_config_json['config']['apk_path']
68+
)
69+
70+
raise 'ERROR: Invalid config apk path' unless File.file?(
71+
absolute_config_apk_path
72+
)
73+
74+
absolute_config_apk_path
4375
end
4476
end

lib/kraken-mobile/steps/mobile/kraken_steps.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ def handle_property(property)
119119
end
120120

121121
def all_user_properties_as_json
122-
raise 'ERROR: No properties file found' if ENV['PROPERTIES_PATH'].nil?
122+
raise 'ERROR: No properties file found' if ENV[K::PROPERTIES_PATH].nil?
123123

124-
properties_aboslute_path = File.expand_path(ENV['PROPERTIES_PATH'])
124+
properties_absolute_path = File.expand_path(ENV[K::PROPERTIES_PATH])
125125
raise 'ERROR: Properties file not found' unless File.file?(
126-
properties_aboslute_path
126+
properties_absolute_path
127127
)
128128

129-
file = open(properties_aboslute_path)
129+
file = open(properties_absolute_path)
130130
content = file.read
131131
JSON.parse(content)
132132
end

lib/kraken-mobile/test_scenario.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def self.ready_to_finish?
9191
end
9292
end
9393

94+
def requires_predefined_devices?
95+
!ENV[K::CONFIG_PATH].nil?
96+
end
97+
9498
private
9599

96100
def start_process_for_user_id_in_device(user_id, device)
@@ -120,6 +124,8 @@ def start_web_process_for_user_id_in_device(user_id, device)
120124
end
121125

122126
def sample_devices
127+
return predefined_devices if requires_predefined_devices?
128+
123129
(sample_mobile_devices + sample_web_devices).flatten
124130
end
125131

@@ -161,4 +167,18 @@ def delete_all_web_inboxes
161167
File.delete(file)
162168
end
163169
end
170+
171+
def predefined_devices
172+
config_absolute_path = File.expand_path(ENV[K::CONFIG_PATH])
173+
file = open(config_absolute_path)
174+
content = file.read
175+
devices_json = JSON.parse(content).values
176+
177+
devices_json.map do |device_json|
178+
AndroidDevice.new(
179+
id: device_json['id'],
180+
model: device_json['model']
181+
)
182+
end
183+
end
164184
end

lib/kraken-mobile/utils/k.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module K
1212
MONKEY_DEFAULT_TIMEOUT = 5 unless defined? MONKEY_DEFAULT_TIMEOUT
1313
WEB_DEVICE = 'WEB_DEVICE' unless defined? WEB_DEVICE
1414
ANDROID_DEVICE = 'ANDROID_DEVICE' unless defined? ANDROID_DEVICE
15+
PROPERTIES_PATH = 'PROPERTIES_PATH' unless defined? PROPERTIES_PATH
16+
CONFIG_PATH = 'CONFIG_PATH' unless defined? CONFIG_PATH
1517

1618
unless defined? DEFAULT_START_TIMEOUT_SECONDS
1719
DEFAULT_START_TIMEOUT_SECONDS = 600 # 10.minutes

lib/kraken_mobile.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,23 @@ class KrakenApp
1515
#-------------------------------
1616
# Constructors
1717
#-------------------------------
18-
def initialize(apk_path:, properties_path: nil)
18+
def initialize(apk_path:, properties_path: nil, config_path: nil)
1919
@apk_path = apk_path
2020
@scenarios_queue = []
21-
build_scenarios_queue
22-
2321
save_path_in_environment_variable_with_name(
24-
name: 'PROPERTIES_PATH',
25-
path: properties_path
22+
name: K::PROPERTIES_PATH, path: properties_path
23+
)
24+
save_path_in_environment_variable_with_name(
25+
name: K::CONFIG_PATH, path: config_path
2626
)
27+
28+
build_scenarios_queue
2729
end
2830

2931
def start
3032
execute_next_scenario
3133
end
3234

33-
#-------------------------------
34-
# Helpers
35-
#-------------------------------
36-
def apk_path_for_process_id(_process_id)
37-
raise 'ERROR: Invalid APK file path' if @apk_path.nil?
38-
39-
@apk_path
40-
end
41-
4235
#-------------------------------
4336
# Observers
4437
#-------------------------------

0 commit comments

Comments
 (0)