lib/calabash/android/device.rb in calabash-2.0.0.pre2 vs lib/calabash/android/device.rb in calabash-2.0.0.pre3
- old
+ new
@@ -20,10 +20,11 @@
def change_server(new_server)
super(new_server)
port_forward(new_server.endpoint.port, new_server.test_server_port)
end
+ # @!visibility private
def self.default_serial
serials = list_serials
if Environment::DEVICE_IDENTIFIER
index = serials.index(Environment::DEVICE_IDENTIFIER)
@@ -44,10 +45,11 @@
serials.first
end
end
+ # @!visibility private
def self.list_serials
output = ADB.command('devices')
lines = output.lines
index = lines.index{|line| line.start_with?('List of devices attached')}
@@ -60,16 +62,18 @@
device_lines.collect do |line|
line.match(/([^\s]+)/).captures.first
end
end
+ # @!visibility private
def installed_packages
adb.shell('pm list packages').lines.map do |line|
line.sub('package:', '').chomp
end
end
+ # @!visibility private
def installed_apps
adb.shell('pm list packages -f').lines.map do |line|
# line will be package:<path>=<package>
# e.g. "package:/system/app/GoogleEars.apk=com.google.android.ears"
info = line.sub("package:", "")
@@ -78,35 +82,39 @@
{package: app_id, path: app_path}
end
end
+ # @!visibility private
def test_server_responding?
begin
http_client.get(HTTP::Request.new('ping'), retries: 1).body == 'pong'
rescue HTTP::Error => _
false
end
end
+ # @!visibility private
def test_server_ready?
begin
http_client.get(HTTP::Request.new('ready')).body == 'true'
rescue HTTP::Error => _
false
end
end
+ # @!visibility private
def port_forward(host_port, test_server_port = nil)
if test_server_port.nil?
test_server_port = server.test_server_port
end
adb_forward_cmd = ['forward', "tcp:#{host_port}", "tcp:#{test_server_port}"]
adb.command(*adb_forward_cmd)
end
+ # @!visibility private
def make_map_parameters(query, map_method_name, *method_args)
converted_args = []
method_args.each do |arg|
if arg.is_a?(Hash)
@@ -170,10 +178,11 @@
end
Calabash::QueryResult.create(result['results'], query)
end
+ # @!visibility private
def perform_action(action, *arguments)
@logger.log "Action: #{action} - Arguments: #{arguments.join(', ')}"
parameters = {command: action, arguments: arguments}
request = HTTP::Request.new('/', params_for_request(parameters))
@@ -195,14 +204,16 @@
end
result
end
+ # @!visibility private
def enter_text(text)
perform_action('keyboard_enter_text', text)
end
+ # @!visibility private
def md5_checksum(file_path)
result = adb.shell("#{md5_binary} '#{file_path}'")
captures = result.match(/(\w+)/).captures
if captures.length != 1
@@ -232,19 +243,22 @@
end
result['result']
end
+ # @!visibility private
def go_home
adb.shell("input keyevent 3")
end
+ # @!visibility private
def set_location(location)
perform_action('set_gps_coordinates',
location[:latitude], location[:longitude])
end
+ # @!visibility private
def resume_app(path_or_application)
application = parse_path_or_app_parameters(path_or_application)
if app_running?(application)
main_activity = nil
@@ -261,10 +275,11 @@
end
true
end
+ # @!visibility private
def resume_activity(package, activity)
if package_running?(package)
if info[:sdk_version] >= 11
begin
perform_action('resume_application', package)
@@ -277,16 +292,18 @@
else
raise "The app '#{package}' is not running"
end
end
+ # @!visibility private
def app_running?(path_or_application)
application = parse_path_or_app_parameters(path_or_application)
package_running?(application.identifier)
end
+ # @!visibility private
def current_focus
# Example: mFocusedApp=AppWindowToken{42c52610 token=Token{42b5d048 ActivityRecord{42a7bcc8 u0 com.example/.MainActivity t3}}}
result = adb.shell('dumpsys window windows')
grep_words = ['mCurrentFocus', 'mFocusedApp']
@@ -312,9 +329,10 @@
end
raise "Unexpected output from `dumpsys window windows`"
end
+ # @!visibility private
def evaluate_javascript_in(query, javascript)
parameters =
{
query: Query.new(query),
operation: {method_name: 'execute-javascript'},