Skip to content

Commit 0a43a44

Browse files
committed
properties connected again
1 parent b01ffaa commit 0a43a44

File tree

5 files changed

+100
-13
lines changed

5 files changed

+100
-13
lines changed

bin/kraken-mobile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def read_configuration
2222
configuration_command
2323
end
2424

25-
def read_properties
25+
def read_user_entered_properties_path
2626
properties_command = ARGV.select { |arg| arg.include?('--properties=') }.first
2727
return if properties_command.nil?
2828

@@ -68,8 +68,8 @@ else
6868
when 'run'
6969
require File.join(File.dirname(__FILE__), 'kraken_mobile_calabash_android')
7070
configuration = read_configuration
71-
properties = read_properties
72-
handle_calabash_android(configuration, properties)
71+
user_entered_properties_path = read_user_entered_properties_path
72+
handle_calabash_android(configuration, user_entered_properties_path)
7373
else
7474
print_usage
7575
end

bin/kraken_mobile_calabash_android.rb

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

9-
def handle_calabash_android(configuration, properties)
9+
def handle_calabash_android(configuration, properties_path)
1010
require 'kraken-mobile/constants'
1111
require 'calabash-android/helpers'
1212
#options = {}
@@ -17,12 +17,20 @@ def handle_calabash_android(configuration, properties)
1717
# ensure_apk_is_specified
1818
# options[:apk_path] = ARGV.first
1919
#end
20-
#if properties
21-
# ensure_properties_is_valid File.expand_path(properties)
22-
# options[:properties_path] = File.expand_path(properties)
23-
#end
2420
kraken = KrakenApp.new(
25-
apk_path: user_entered_apk_path
21+
apk_path: user_entered_apk_path,
22+
properties_path: format_properties(properties_path)
2623
)
2724
kraken.start
2825
end
26+
27+
private
28+
29+
def format_properties(properties_path)
30+
return if properties_path.nil?
31+
32+
properties_absolute_path = File.expand_path(properties_path)
33+
ensure_properties_is_valid(properties_absolute_path)
34+
35+
properties_absolute_path
36+
end

bin/kraken_mobile_helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def print_usage
2727
def print_devices
2828
puts 'List of devices attached'
2929
ADB.connected_devices.each_with_index do |device, index|
30-
puts "user#{index + 1} - #{device}"
30+
puts "user#{index + 1} - #{device.to_s.split(K::SEPARATOR).join(' - ')}"
3131
end
3232
end
3333

@@ -84,7 +84,7 @@ def ensure_configuration_is_valid(configuration)
8484
def ensure_properties_is_valid(properties)
8585
return if File.exist?(properties) &&
8686
File.file?(properties) &&
87-
!properties.end_with?('.json')
87+
properties.end_with?('.json')
8888

8989
puts 'The path of the properties file is not valid.'
9090
exit 1

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
require 'kraken-mobile/utils/K'
33
require 'kraken-mobile/models/android_device'
44

5+
ParameterType(
6+
name: 'property',
7+
regexp: /[^\"]*/,
8+
type: String,
9+
transformer: lambda do |string|
10+
if string_is_a_property?(string)
11+
string.slice!('<')
12+
string.slice!('>')
13+
handle_property(string)
14+
elsif string_is_a_faker?(string)
15+
handle_faker(string)
16+
else
17+
return string
18+
end
19+
end
20+
)
21+
522
Then(
623
/^I send a signal to user (\d+) containing "([^\"]*)"$/
724
) do |process_id, signal|
@@ -74,5 +91,46 @@
7491

7592
def current_process_id
7693
tag_process_id = @scenario_tags.grep(/@user/).first
77-
tag_process_id.delete_prefix('@user')
94+
process_id = tag_process_id.delete_prefix('@user')
95+
return 'ERROR: User not foud for scenario' if process_id.nil?
96+
97+
process_id
98+
end
99+
100+
def string_is_a_property?(string)
101+
string.start_with?('<') &&
102+
string.end_with?('>')
103+
end
104+
105+
def string_is_a_faker?(string)
106+
string.start_with?('$') || string.start_with?('$$')
107+
end
108+
109+
def handle_property(property)
110+
properties = all_user_properties_as_json
111+
process_id = current_process_id
112+
user_id = "@user#{process_id}"
113+
114+
if !properties[user_id] || !properties[user_id][property]
115+
raise "Property <#{property}> not found for @user#{current_process_id}"
116+
end
117+
118+
properties[user_id][property]
119+
end
120+
121+
def all_user_properties_as_json
122+
raise 'ERROR: No properties file found' if ENV['PROPERTIES_PATH'].nil?
123+
124+
properties_aboslute_path = File.expand_path(ENV['PROPERTIES_PATH'])
125+
raise 'ERROR: Properties file not found' unless File.file?(
126+
properties_aboslute_path
127+
)
128+
129+
file = open(properties_aboslute_path)
130+
content = file.read
131+
JSON.parse(content)
132+
end
133+
134+
def handle_faker(faker)
135+
nil
78136
end

lib/kraken_mobile.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ class KrakenApp
1515
#-------------------------------
1616
# Constructors
1717
#-------------------------------
18-
def initialize(apk_path:)
18+
def initialize(apk_path:, properties_path: nil)
1919
@apk_path = apk_path
2020
@scenarios_queue = []
2121
build_scenarios_queue
22+
23+
save_path_in_environment_variable_with_name(
24+
name: 'PROPERTIES_PATH',
25+
path: properties_path
26+
)
2227
end
2328

2429
def start
@@ -61,4 +66,20 @@ def execute_next_scenario
6166
scenario.run
6267
scenario
6368
end
69+
70+
def save_path_in_environment_variable_with_name(name:, path:)
71+
return if path.nil?
72+
73+
absolute_path = File.expand_path(path)
74+
save_value_in_environmant_variable_with_name(
75+
name: name,
76+
value: absolute_path
77+
)
78+
end
79+
80+
def save_value_in_environmant_variable_with_name(name:, value:)
81+
return if name.nil? || value.nil?
82+
83+
ENV[name] = value
84+
end
6485
end

0 commit comments

Comments
 (0)