honeydew 0.12.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +79 -8
- data/Rakefile +2 -2
- data/examples/cucumber/Gemfile +5 -0
- data/{example → examples/cucumber}/Rakefile +0 -0
- data/{example → examples/cucumber}/features/example.feature +0 -0
- data/{example → examples/cucumber}/features/step_definitions/honeydew_steps.rb +0 -0
- data/examples/rspec/spec/browse_spec.rb +16 -0
- data/examples/rspec/spec/spec_helper.rb +6 -0
- data/honeydew.gemspec +17 -17
- data/honeydew.iml +12 -18
- data/lib/honeydew.rb +1 -72
- data/lib/honeydew/device.rb +79 -44
- data/lib/honeydew/device_actions.rb +32 -100
- data/lib/honeydew/device_commands.rb +36 -23
- data/lib/honeydew/device_matchers.rb +29 -22
- data/lib/honeydew/dsl.rb +1 -1
- data/lib/honeydew/honeydew.rb +82 -0
- data/lib/honeydew/version.rb +1 -1
- data/{android-server → server}/.gitignore +0 -0
- data/{android-server → server}/pom.xml +16 -6
- data/{android-server → server}/repo/com/google/android/uiautomator/4.1.1.4/_maven.repositories +0 -0
- data/{android-server → server}/repo/com/google/android/uiautomator/4.1.1.4/uiautomator-4.1.1.4.jar +0 -0
- data/{android-server → server}/repo/com/google/android/uiautomator/4.1.1.4/uiautomator-4.1.1.4.pom +0 -0
- data/{android-server → server}/repo/com/jayway/maven/plugins/android/generation2/android-maven-plugin/3.5.2-SNAPSHOT/android-maven-plugin-3.5.2-SNAPSHOT.jar +0 -0
- data/{android-server → server}/repo/com/jayway/maven/plugins/android/generation2/android-maven-plugin/3.5.2-SNAPSHOT/android-maven-plugin-3.5.2-SNAPSHOT.pom +0 -0
- data/{android-server → server}/repo/com/jayway/maven/plugins/android/generation2/android-maven-plugin/3.5.2-SNAPSHOT/maven-metadata-local.xml +0 -0
- data/{android-server → server}/repo/commons-jxpath/commons-jxpath/1.4-SNAPSHOT/_maven.repositories +0 -0
- data/{android-server → server}/repo/commons-jxpath/commons-jxpath/1.4-SNAPSHOT/commons-jxpath-1.4-SNAPSHOT.jar +0 -0
- data/{android-server → server}/repo/commons-jxpath/commons-jxpath/1.4-SNAPSHOT/commons-jxpath-1.4-SNAPSHOT.pom +0 -0
- data/{android-server → server}/repo/commons-jxpath/commons-jxpath/1.4-SNAPSHOT/maven-metadata-local.xml +0 -0
- data/{android-server → server}/repo/commons-jxpath/commons-jxpath/maven-metadata-local.xml +0 -0
- data/server/repo/fi/iki/elonen/nanohttpd-webserver/2.0.3/nanohttpd-webserver-2.0.3.jar +0 -0
- data/server/repo/fi/iki/elonen/nanohttpd-webserver/2.0.3/nanohttpd-webserver-2.0.3.pom +9 -0
- data/server/repo/fi/iki/elonen/nanohttpd-webserver/maven-metadata-local.xml +12 -0
- data/server/repo/fi/iki/elonen/nanohttpd/2.0.3/nanohttpd-2.0.3.jar +0 -0
- data/server/repo/fi/iki/elonen/nanohttpd/2.0.3/nanohttpd-2.0.3.pom +9 -0
- data/server/repo/fi/iki/elonen/nanohttpd/maven-metadata-local.xml +12 -0
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/Action.java +13 -6
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/ActionsExecutor.java +3 -2
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/Command.java +6 -1
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/Result.java +7 -7
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/TestRunner.java +14 -6
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/Click.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/ClickAndWaitForNewWindow.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/DumpWindowHierarchy.java +5 -5
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/HasSettingsMenuItem.java +4 -5
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/InspectOptionInSettingsMenu.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/IsButtonPresent.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/IsChildCountEqualTo.java +4 -4
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/IsElementWithNestedTextPresent.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/IsOptionInSettingsMenuDisabled.java +1 -1
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/IsOptionInSettingsMenuEnabled.java +1 -1
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/IsTextPresent.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/LaunchApp.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/LaunchHome.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/LongClick.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/PressBack.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/PressEnter.java +4 -4
- data/server/src/main/java/com/amplify/honeydew_server/actions/ScrollToTextByIndex.java +27 -0
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/SelectFromAppsList.java +4 -4
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/SelectMenuInSettings.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/SetText.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/SetTextByIndex.java +2 -2
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/SetTextByLabel.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/Unlock.java +3 -3
- data/{android-server/src/main/java/com/uiautomator_cucumber/android_server → server/src/main/java/com/amplify/honeydew_server}/actions/WakeUp.java +4 -4
- data/server/src/main/java/com/amplify/honeydew_server/httpd/RemoteCommandReceiver.java +66 -0
- data/spec/honeydew/device_matchers_spec.rb +21 -42
- data/spec/honeydew/device_spec.rb +38 -36
- data/spec/spec_helper.rb +2 -25
- metadata +93 -92
- data/android-server/src/main/java/com/uiautomator_cucumber/android_server/httpd/NanoHTTPD.java +0 -1100
- data/android-server/src/main/java/com/uiautomator_cucumber/android_server/httpd/RemoteCommandReceiver.java +0 -64
- data/example/Gemfile +0 -5
- data/example/features/support/hooks.rb +0 -4
- data/lib/honeydew/hooks.rb +0 -0
- data/lib/honeydew/step_definitions.rb +0 -75
- data/lib/tasks/honeydew.rake +0 -7
- data/todo.md +0 -9
@@ -4,148 +4,80 @@ module Honeydew
|
|
4
4
|
module DeviceActions
|
5
5
|
include Honeydew::DeviceCommands
|
6
6
|
|
7
|
-
def
|
8
|
-
perform_action :
|
7
|
+
def scroll_to_text text, index = '0'
|
8
|
+
perform_action :scroll_to_text_by_index, :text => text, :index => index
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
perform_action :
|
11
|
+
def click_button button_text
|
12
|
+
perform_action :click, :text => button_text, :type => 'Button'
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
perform_action :
|
15
|
+
def click_button_and_wait button_text
|
16
|
+
perform_action :click_and_wait_for_new_window, :text => button_text, :type => 'Button'
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
perform_action :
|
19
|
+
def click_text text
|
20
|
+
perform_action :click, :text => text, :type => 'TextView'
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
perform_action :
|
23
|
+
def click_text_and_wait text
|
24
|
+
perform_action :click_and_wait_for_new_window, :text => text, :type => 'TextView'
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
perform_action :
|
27
|
+
def click_element element_description
|
28
|
+
perform_action :click, :description => element_description
|
29
|
+
end
|
30
|
+
|
31
|
+
def click_element_and_wait element_description
|
32
|
+
perform_action :click_and_wait_for_new_window, :description => element_description
|
29
33
|
end
|
30
34
|
|
31
35
|
def fill_in field_description, options = {with: ''}
|
32
|
-
perform_action :
|
36
|
+
perform_action :set_text, :description => field_description, :text => options[:with]
|
33
37
|
end
|
34
38
|
|
35
39
|
def fill_in_by_label field_label, options = {with: ''}
|
36
|
-
perform_action :
|
40
|
+
perform_action :set_text_by_label, :label => field_label, :text => options[:with]
|
37
41
|
end
|
38
42
|
|
39
43
|
def fill_in_by_index index, options = {with: ''}
|
40
|
-
perform_action :
|
44
|
+
perform_action :set_text_by_index, :index => index, :text => options[:with]
|
41
45
|
end
|
42
46
|
|
43
47
|
def launch_home
|
44
|
-
perform_action :
|
48
|
+
perform_action :launch_home
|
45
49
|
end
|
46
50
|
|
47
|
-
def launch_settings_app
|
48
|
-
perform_action :
|
51
|
+
def launch_settings_app app_name
|
52
|
+
perform_action :select_from_apps_list, :appName => app_name
|
49
53
|
end
|
50
54
|
|
51
|
-
def launch_application
|
52
|
-
perform_action :
|
55
|
+
def launch_application application_name
|
56
|
+
perform_action :launch_app, :appName => application_name
|
53
57
|
end
|
54
58
|
|
55
|
-
def long_click_element
|
56
|
-
perform_action :
|
59
|
+
def long_click_element element_description
|
60
|
+
perform_action :long_click, :description => element_description
|
57
61
|
end
|
58
62
|
|
59
|
-
def launch_settings_item
|
60
|
-
perform_action :
|
63
|
+
def launch_settings_item item_name
|
64
|
+
perform_action :select_menu_in_settings, :menuName => item_name
|
61
65
|
end
|
62
66
|
|
63
|
-
|
64
67
|
def press_back
|
65
|
-
perform_action :
|
68
|
+
perform_action :press_back
|
66
69
|
end
|
67
70
|
|
68
71
|
def press_enter
|
69
|
-
perform_action :
|
72
|
+
perform_action :press_enter
|
70
73
|
end
|
71
74
|
|
72
75
|
def unlock
|
73
|
-
perform_action :
|
76
|
+
perform_action :unlock
|
74
77
|
end
|
75
78
|
|
76
79
|
def wake_up
|
77
|
-
perform_action :
|
78
|
-
end
|
79
|
-
|
80
|
-
def perform_action(options)
|
81
|
-
ensure_tablet_ready
|
82
|
-
|
83
|
-
command = options.slice(:action, :arguments)
|
84
|
-
timeout = options[:retry_until]
|
85
|
-
attempts = options[:attempts]
|
86
|
-
|
87
|
-
response =
|
88
|
-
if timeout
|
89
|
-
retry_until_timeout(timeout, command)
|
90
|
-
elsif attempts
|
91
|
-
retry_until_success(attempts, command)
|
92
|
-
else
|
93
|
-
execute_command(command)
|
94
|
-
end
|
95
|
-
log_action(command, response)
|
96
|
-
raise "Device: #{serial} :Action #{options} failed." unless response['success']
|
97
|
-
response
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def retry_until_success(attempts, command)
|
103
|
-
completed = false
|
104
|
-
response = nil
|
105
|
-
tries = 0
|
106
|
-
until completed || (tries >= attempts) do
|
107
|
-
response = execute_command(command)
|
108
|
-
completed = response['success']
|
109
|
-
return response if completed
|
110
|
-
tries += 1
|
111
|
-
sleep 1
|
112
|
-
end
|
113
|
-
log_action(command, response)
|
114
|
-
raise "Device: #{serial} : All #{attempts} attempts failed while performing #{command[:action]}, with arguments: #{command[:arguments]}"
|
115
|
-
end
|
116
|
-
|
117
|
-
def retry_until_timeout(timeout, command)
|
118
|
-
completed = false
|
119
|
-
response = nil
|
120
|
-
Timeout.timeout(timeout.to_i) do
|
121
|
-
until completed do
|
122
|
-
sleep 1
|
123
|
-
response = execute_command(command)
|
124
|
-
completed = response['success']
|
125
|
-
end
|
126
|
-
end
|
127
|
-
return response
|
128
|
-
rescue Timeout::Error
|
129
|
-
log_action(command, response)
|
130
|
-
raise "Device: #{serial} :Timeout while performing #{command[:action]}, with arguments: #{command[:arguments]}"
|
131
|
-
end
|
132
|
-
|
133
|
-
def execute_command(command)
|
134
|
-
response = RestClient.get(device_endpoint, :params => stringify_keys(:command => command))
|
135
|
-
JSON.parse(response)
|
136
|
-
end
|
137
|
-
|
138
|
-
def log_action(command, response)
|
139
|
-
log "Device: #{serial} : executing command: #{command}"
|
140
|
-
log "Device: #{serial} : responded with: #{response}"
|
141
|
-
end
|
142
|
-
|
143
|
-
def stringify_keys(options)
|
144
|
-
JSON.parse(options.to_json)
|
145
|
-
end
|
146
|
-
|
147
|
-
def log(message)
|
148
|
-
puts message
|
80
|
+
perform_action :wake_up
|
149
81
|
end
|
150
82
|
end
|
151
83
|
end
|
@@ -1,12 +1,24 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
1
4
|
module Honeydew
|
2
5
|
module DeviceCommands
|
3
6
|
|
4
|
-
def
|
5
|
-
|
7
|
+
def is_app_installed?(package_name)
|
8
|
+
has_app_installed?(package_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def clear_directory(directory)
|
12
|
+
all_files_in_directory_path = [directory.chomp('/'), '/*'].join
|
13
|
+
adb "shell rm -r #{all_files_in_directory_path}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def device_endpoint action
|
17
|
+
URI.join("http://localhost:#{port}", action)
|
6
18
|
end
|
7
19
|
|
8
20
|
def dump_window_hierarchy(local_path)
|
9
|
-
path_in_device = perform_action(
|
21
|
+
path_in_device = perform_action('dump_window_hierarchy')['description']
|
10
22
|
adb "pull #{path_in_device} #{local_path}"
|
11
23
|
end
|
12
24
|
|
@@ -16,41 +28,39 @@ module Honeydew
|
|
16
28
|
adb "pull #{path_in_device} #{local_path}"
|
17
29
|
end
|
18
30
|
|
19
|
-
def
|
31
|
+
def start_honeydew_server
|
20
32
|
forwarding_port
|
21
|
-
|
22
|
-
log "Device: #{serial} : Starting server on the device"
|
33
|
+
terminate_honeydew_server
|
23
34
|
start_automation_server
|
24
35
|
end
|
25
36
|
|
26
|
-
def
|
27
|
-
log
|
28
|
-
|
29
|
-
rescue
|
37
|
+
def terminate_honeydew_server
|
38
|
+
log "terminating honeydew-server"
|
39
|
+
Net::HTTP.post_form device_endpoint('/terminate'), {}
|
40
|
+
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError
|
30
41
|
# Swallow
|
31
42
|
end
|
32
43
|
|
33
|
-
def
|
34
|
-
"
|
44
|
+
def honeydew_server_package
|
45
|
+
"honeydew-server-#{Honeydew::VERSION}.jar"
|
35
46
|
end
|
36
47
|
|
37
|
-
def
|
38
|
-
File.absolute_path(File.join(File.dirname(__FILE__), "../../
|
48
|
+
def honeydew_server_file
|
49
|
+
File.absolute_path(File.join(File.dirname(__FILE__), "../../server/target/#{honeydew_server_package}"))
|
39
50
|
end
|
40
51
|
|
41
52
|
def start_automation_server
|
53
|
+
log "starting honeydew-server on the device"
|
42
54
|
Thread.new do
|
43
|
-
adb "push #{
|
44
|
-
adb "shell uiautomator runtest #{
|
45
|
-
log "Device: #{serial} initiated the start of automation server"
|
55
|
+
adb "push #{honeydew_server_file} /data/local/tmp"
|
56
|
+
adb "shell uiautomator runtest #{honeydew_server_package} -c com.amplify.honeydew_server.TestRunner"
|
46
57
|
end
|
47
58
|
at_exit do
|
48
|
-
|
59
|
+
terminate_honeydew_server
|
49
60
|
end
|
50
61
|
end
|
51
62
|
|
52
63
|
def forwarding_port
|
53
|
-
log "Device: #{serial} : Forwarding port #{port} to device"
|
54
64
|
adb "forward tcp:#{port} tcp:7120"
|
55
65
|
end
|
56
66
|
|
@@ -76,9 +86,12 @@ module Honeydew
|
|
76
86
|
|
77
87
|
def adb(command)
|
78
88
|
adb_command = "adb -s #{serial} #{command}"
|
79
|
-
log "
|
80
|
-
`#{adb_command}`.tap
|
89
|
+
log "executing '#{adb_command}'"
|
90
|
+
`#{adb_command} 2>/dev/null`.tap do
|
91
|
+
if $?.exitstatus != 0
|
92
|
+
raise "ADB command '#{command}' failed"
|
93
|
+
end
|
94
|
+
end
|
81
95
|
end
|
82
|
-
|
83
96
|
end
|
84
|
-
end
|
97
|
+
end
|
@@ -1,36 +1,40 @@
|
|
1
1
|
module Honeydew
|
2
2
|
module DeviceMatchers
|
3
|
-
|
4
|
-
|
5
|
-
perform_action :action => 'is_text_present', :arguments => {:text => text}, :retry_until => timeout
|
3
|
+
def has_text?(text)
|
4
|
+
perform_assertion :is_text_present, :text => text
|
6
5
|
end
|
7
6
|
|
8
|
-
def has_element_with_description?(description
|
9
|
-
|
7
|
+
def has_element_with_description?(description)
|
8
|
+
perform_assertion :is_text_present, :description => description
|
10
9
|
end
|
11
10
|
|
12
|
-
def has_edit_text?(text
|
13
|
-
|
11
|
+
def has_edit_text?(text)
|
12
|
+
perform_assertion :is_text_present, :text => text, :type => 'EditText'
|
14
13
|
end
|
15
14
|
|
16
|
-
def has_textview_text?(text
|
17
|
-
|
15
|
+
def has_textview_text?(text)
|
16
|
+
perform_assertion :is_text_present, :text => text, :type => 'TextView'
|
18
17
|
end
|
19
18
|
|
20
|
-
def has_textview_with_text_and_description?(text, description
|
21
|
-
|
19
|
+
def has_textview_with_text_and_description?(text, description)
|
20
|
+
perform_assertion :is_text_present, :text => text, :description => description, :type => 'TextView'
|
22
21
|
end
|
23
22
|
|
24
|
-
def has_button?(button_text
|
25
|
-
|
23
|
+
def has_button?(button_text)
|
24
|
+
perform_assertion :is_button_present, :text => button_text
|
26
25
|
end
|
27
26
|
|
28
|
-
def has_child_count?(parent_element_description, child_element_description, child_count
|
29
|
-
|
27
|
+
def has_child_count?(parent_element_description, child_element_description, child_count)
|
28
|
+
perform_assertion :is_child_count_equal_to,
|
29
|
+
:parent_description => parent_element_description,
|
30
|
+
:child_description => child_element_description,
|
31
|
+
:child_count => child_count
|
30
32
|
end
|
31
33
|
|
32
|
-
def has_element_with_nested_text?(parent_description, child_text
|
33
|
-
|
34
|
+
def has_element_with_nested_text?(parent_description, child_text)
|
35
|
+
perform_assertion :is_element_with_nested_text_present,
|
36
|
+
:parent_description => parent_description,
|
37
|
+
:child_text => child_text
|
34
38
|
end
|
35
39
|
|
36
40
|
def has_app_installed?(package_name)
|
@@ -38,15 +42,18 @@ module Honeydew
|
|
38
42
|
end
|
39
43
|
|
40
44
|
def is_option_in_setting_enabled?(item_name, option_names)
|
41
|
-
|
45
|
+
perform_assertion :is_option_in_settings_menu_enabled,
|
46
|
+
:menuName => item_name, :optionNames => option_names
|
42
47
|
end
|
43
48
|
|
44
49
|
def is_option_in_setting_disabled?(item_name, option_names)
|
45
|
-
|
50
|
+
perform_assertion :is_option_in_settings_menu_disabled,
|
51
|
+
:menuName => item_name, :optionNames => option_names
|
46
52
|
end
|
47
53
|
|
48
|
-
def has_settings_menu_item?(item_name
|
49
|
-
|
54
|
+
def has_settings_menu_item?(item_name)
|
55
|
+
perform_assertion :has_settings_menu_item,
|
56
|
+
:menuName => item_name
|
50
57
|
end
|
51
58
|
end
|
52
|
-
end
|
59
|
+
end
|
data/lib/honeydew/dsl.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
require 'honeydew/version'
|
4
|
+
require 'honeydew/device'
|
5
|
+
|
6
|
+
module Honeydew
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :debug,
|
9
|
+
:server_timeout,
|
10
|
+
:timeout,
|
11
|
+
:port
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@port = 7120
|
15
|
+
@debug = true
|
16
|
+
@timeout = 5.seconds
|
17
|
+
@server_timeout = 30.seconds
|
18
|
+
end
|
19
|
+
|
20
|
+
def obtain_new_port
|
21
|
+
@port.tap { @port += 1 }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class <<self
|
26
|
+
attr_accessor :config
|
27
|
+
|
28
|
+
def config
|
29
|
+
return @config if @config
|
30
|
+
configure
|
31
|
+
@config
|
32
|
+
end
|
33
|
+
|
34
|
+
def configure
|
35
|
+
@config ||= Configuration.new
|
36
|
+
yield(@config) if block_given?
|
37
|
+
end
|
38
|
+
|
39
|
+
def attached_devices
|
40
|
+
@attached_devices ||= begin
|
41
|
+
`adb devices`.split("\n").drop(1).collect {|line| line.split[0].chomp}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_device_serial
|
46
|
+
attached_devices.first
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_device
|
50
|
+
@default_device ||= device[default_device_serial]
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_device
|
54
|
+
@current_device ||= default_device
|
55
|
+
end
|
56
|
+
|
57
|
+
def using_device(serial, &block)
|
58
|
+
original_device = current_device
|
59
|
+
use_device(serial || Honeydew.default_device_serial).tap do |device|
|
60
|
+
device.instance_eval(&block) if block_given?
|
61
|
+
end
|
62
|
+
ensure
|
63
|
+
@current_device = original_device
|
64
|
+
end
|
65
|
+
|
66
|
+
def devices
|
67
|
+
@devices
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def use_device(serial)
|
73
|
+
@current_device = device[serial]
|
74
|
+
end
|
75
|
+
|
76
|
+
def device
|
77
|
+
@devices ||= Hash.new do |hash, serial|
|
78
|
+
hash[serial] = Device.new(serial)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|