Skip to content

Commit c484560

Browse files
committed
new version for 1.0.7
1 parent c700d92 commit c484560

25 files changed

+605
-131
lines changed

README.md

Lines changed: 165 additions & 59 deletions
Large diffs are not rendered by default.

bin/kraken-mobile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,22 @@ else
6262
when 'setup'
6363
KrakenSetup.new.run
6464
when 'gen'
65+
ensure_java_installed
66+
ensure_android_sdk_installed
67+
6568
scaffold_folder_structure
6669
when 'resign'
70+
ensure_java_installed
71+
ensure_android_sdk_installed
72+
6773
require 'calabash-android/helpers'
6874
puts 'Resigning APK with Calabash-Android'
6975
ensure_apk_is_specified
7076
resign_apk(user_entered_apk_path)
7177
when 'run'
78+
ensure_java_installed
79+
ensure_android_sdk_installed
80+
7281
require File.join(File.dirname(__FILE__), 'kraken_mobile_calabash_android')
7382
configuration = read_configuration
7483
user_entered_properties_path = read_user_entered_properties_path

bin/kraken_mobile_helpers.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,19 @@ def ensure_properties_is_valid(properties)
8989
puts 'The path of the properties file is not valid.'
9090
exit 1
9191
end
92+
93+
def ensure_android_sdk_installed
94+
return unless ENV['ANDROID_HOME'].nil?
95+
96+
puts 'To use Kraken you need to have installed Android SDK first. '\
97+
'Make sure you have the environment variable ANDROID_HOME configured'
98+
exit 1
99+
end
100+
101+
def ensure_java_installed
102+
return unless ENV['ANDROID_HOME'].nil?
103+
104+
puts 'To use Kraken you need to have installed Java first.'\
105+
'Make sure you have the environment variable JAVA_HOME configured'
106+
exit 1
107+
end

bin/kraken_mobile_setup.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
require 'io/console'
22
require 'tty-prompt'
3+
$LOAD_PATH << File.expand_path('../lib', __dir__)
4+
require 'kraken-mobile/utils/k.rb'
35

46
class KrakenSetup
57
WEB_IDENTIFIER = 'Web'.freeze
6-
IS_WEB_AVAILABLE_FOR_SELECTION = false
8+
IS_WEB_AVAILABLE_FOR_SELECTION = true
79

810
attr_accessor :prompt
911
attr_accessor :devices_connected_id
@@ -85,6 +87,7 @@ def save_mobile_device_settings_for_user_with_id(
8587
@settings[user_id] = {
8688
id: device_id,
8789
model: device.model,
90+
type: K::ANDROID_DEVICE,
8891
config: {
8992
apk_path: apk
9093
}
@@ -96,6 +99,7 @@ def save_web_device_settings_for_user_with_id(user_id:)
9699
@settings[user_id] = {
97100
id: device.id,
98101
model: device.model,
102+
type: K::WEB_DEVICE,
99103
config: {}
100104
}
101105
end

docs/WEB_STEPS.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Kraken web steps
2+
3+
In this section we will list all available web steps in Kraken web.
4+
5+
## Navigation
6+
7+
Navigate to a specific website.
8+
9+
```ruby
10+
Then /^I navigate to page "([^\"]*)"$/
11+
```
12+
13+
## Clicking
14+
15+
Click on a view with id.
16+
17+
```ruby
18+
Then /^I click on element having id "(.*?)"$/
19+
```
20+
21+
## Entering text
22+
23+
Enter text in a specific input with id.
24+
25+
```ruby
26+
Then /^I enter "([^\"]*)" into input field having id "([^\"]*)"$/
27+
```
28+
29+
Enter text on a input with CSS selector.
30+
31+
```ruby
32+
Then /^I enter "([^\"]*)" into input field having css selector "([^\"]*)"$/
33+
```
34+
35+
## Waiting
36+
37+
Wait for a specific amount of time.
38+
39+
```ruby
40+
Then /^I wait for (\d+) seconds$/
41+
```
42+
43+
## Assertion
44+
45+
Assert that in current web page a text is present and visible.
46+
47+
```ruby
48+
Then /^I should see text "(.*?)"$/
49+
```
50+
51+
## Kraken Signaling
52+
53+
Send a signal to another device containing a specific content.
54+
55+
```ruby
56+
Then /^I send a signal to user (\d+) containing "([^\"]*)"$/
57+
```
58+
59+
Wait for a signal coming from another device and containing specific content.
60+
61+
```ruby
62+
Then /^I wait for a signal containing "([^\"]*)"$/
63+
```
64+
65+
Wait for a signal coming from another device, containing specific content and for maximum amount of time.
66+
67+
```ruby
68+
Then /^I wait for a signal containing "([^\"]*)" for (\d+) seconds$/
69+
```
70+
71+
## Kraken Monkey
72+
73+
Start Kraken monkey and run a specific amount of random events on the GUI.
74+
75+
```ruby
76+
Then /^I start a monkey with (\d+) events$/
77+
```

kraken-mobile.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
3131
s.add_dependency( 'tty-prompt', '0.18.1')
3232
s.add_development_dependency 'byebug', '~> 11.1'
3333
s.add_dependency( 'capybara', '3.31.0')
34-
s.add_dependency( 'selenium-webdriver', '3.142.7')
34+
s.add_dependency( 'selenium-webdriver', '3.14.0')
3535
s.add_dependency( 'faker', '2.10.0')
3636

3737
s.require_paths = ['lib']

lib/kraken-mobile/device_process.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'fileutils'
2+
13
# Abstract class
24
class DeviceProcess
35
attr_accessor :id
@@ -43,12 +45,40 @@ def register_process_to_directory
4345
end
4446
end
4547

48+
def unregister_process_from_directory
49+
File.open(K::DIRECTORY_PATH, 'r') do |f|
50+
File.open("#{K::DIRECTORY_PATH}.tmp", 'w') do |f2|
51+
f.each_line do |line|
52+
f2.write(line) unless line.start_with?(
53+
"#{id}#{K::SEPARATOR}#{device}"
54+
)
55+
end
56+
end
57+
end
58+
FileUtils.mv("#{K::DIRECTORY_PATH}.tmp", K::DIRECTORY_PATH)
59+
end
60+
4661
def notify_ready_to_start
4762
File.open(K::DIRECTORY_PATH, 'a') do |file|
4863
file.puts("#{id}#{K::SEPARATOR}#{device}")
4964
end
5065
end
5166

67+
def running_on_windows?
68+
RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
69+
end
70+
71+
def exporting_command_for_environment_variables(variables = {})
72+
commands = variables.map do |key, value|
73+
if running_on_windows?
74+
"(SET \"#{key}=#{value}\")"
75+
else
76+
"#{key}=#{value};export #{key}"
77+
end
78+
end
79+
commands.join(terminal_command_separator)
80+
end
81+
5282
def self.directory
5383
return [] unless File.exist?(K::DIRECTORY_PATH)
5484

@@ -91,4 +121,10 @@ def self.processes_in_state(state)
91121

92122
devices_ready || []
93123
end
124+
125+
def terminal_command_separator
126+
return ' & ' if running_on_windows?
127+
128+
';'
129+
end
94130
end

lib/kraken-mobile/helpers/kraken_faker.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'faker'
2-
require 'kraken-mobile/utils/k'
2+
require 'kraken-mobile/utils/k.rb'
33
require 'json'
44

55
class KrakenFaker
@@ -56,6 +56,7 @@ def dictionary_json
5656
absolute_dictionary_path = File.expand_path(K::DICTIONARY_PATH)
5757
file = open(absolute_dictionary_path)
5858
content = file.read
59+
file.close
5960
JSON.parse(content)
6061
end
6162

lib/kraken-mobile/helpers/reporter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def generate_general_report
2626
# Variables
2727
report_file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{KrakenMobile::Constants::REPORT_DEVICES_FILE_NAME}.json")
2828
content = report_file.read
29+
report_file.close
2930
@devices = JSON.parse(content)
3031
devices_report = report_by_devices(@devices)
3132
@features_report = fetures_from_report_by_devices devices_report
@@ -45,6 +46,7 @@ def generate_device_report device
4546
@apk_path = device.config["apk_path"] ? device.config["apk_path"] : @options[:apk_path]
4647
report_file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json")
4748
content = report_file.read
49+
report_file.close
4850
@features = JSON.parse(content)
4951
@total_scenarios = total_scenarios @features
5052
@device = device
@@ -70,6 +72,7 @@ def report_by_devices devices
7072
next if !File.exists?("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device['id']}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json")
7173
report_file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device['id']}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json")
7274
content = report_file.read
75+
report_file.close
7376
devices_report[device['user']] = JSON.parse(content)
7477
devices_report[device['user']].each do |d| d["device_model"] = device["model"] if !d["device_model"] end
7578
devices_report[device['user']].each do |d| d["device_id"] = device["id"] if !d["device_id"] end

lib/kraken-mobile/mobile/mobile_process.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'kraken-mobile/device_process.rb'
2-
require 'kraken-mobile/utils/k'
2+
require 'kraken-mobile/utils/k.rb'
33

44
class MobileProcess < DeviceProcess
55
#-------------------------------
@@ -11,6 +11,7 @@ def before_execute
1111
end
1212

1313
def after_execute
14+
unregister_process_from_directory
1415
device.delete_inbox
1516
end
1617

@@ -42,15 +43,32 @@ def apk_path
4243
private
4344

4445
def execution_command
46+
"|#{environment_variables_command}#{terminal_command_separator}"\
47+
"#{running_process_command}"
48+
end
49+
50+
def running_process_command
4551
feature_path = test_scenario.feature_file.file_path
4652
raise 'ERROR: Invalid feature file path' if feature_path.nil?
4753

4854
process_apk_path = apk_path
4955
raise 'ERROR: Invalid APK file path' if process_apk_path.nil?
5056

51-
"|ADB_DEVICE_ARG=#{device.id} calabash-android run #{process_apk_path} "\
52-
"#{feature_path} --tags @user#{id} --format pretty --format json -o "\
53-
"#{K::REPORT_PATH}/#{@test_scenario.execution_id}/#{device.id}/#{K::FILE_REPORT_NAME}" # TODO, folder to save all things
57+
"calabash-android run #{process_apk_path} \
58+
#{feature_path} --tags @user#{id} \
59+
--require features/support/env.rb \
60+
--require features/support/app_installation_hooks.rb \
61+
--require features/support/app_life_cycle_hooks.rb \
62+
--require features/step_definitions/mobile_steps.rb \
63+
--format pretty --format json -o \
64+
#{K::REPORT_PATH}/#{@test_scenario.execution_id}/#{device.id}/#{K::FILE_REPORT_NAME}"
65+
end
66+
67+
def environment_variables_command
68+
variables = {
69+
ADB_DEVICE_ARG: device.id
70+
}
71+
exporting_command_for_environment_variables(variables)
5472
end
5573

5674
#-------------------------------
@@ -61,6 +79,7 @@ def config_json
6179
config_absolute_path = File.expand_path(ENV[K::CONFIG_PATH])
6280
file = open(config_absolute_path)
6381
content = file.read
82+
file.close
6483
JSON.parse(content)[@id.to_s] || {}
6584
end
6685

0 commit comments

Comments
 (0)