lib/calabash-android/operations.rb in calabash-android-0.5.0.pre2 vs lib/calabash-android/operations.rb in calabash-android-0.5.0
- old
+ new
@@ -5,23 +5,25 @@
require 'rubygems'
require 'json'
require 'socket'
require 'timeout'
require 'calabash-android/helpers'
-require 'calabash-android/wait_helpers'
+require 'calabash-android/text_helpers'
require 'calabash-android/touch_helpers'
+require 'calabash-android/wait_helpers'
require 'calabash-android/version'
require 'calabash-android/env'
require 'retriable'
require 'cucumber'
module Calabash module Android
module Operations
- include Calabash::Android::WaitHelpers
+ include Calabash::Android::TextHelpers
include Calabash::Android::TouchHelpers
+ include Calabash::Android::WaitHelpers
def current_activity
`#{default_device.adb_command} shell dumpsys window windows`.each_line.grep(/mFocusedApp.+[\.\/]([^.\s\/\}]+)/){$1}.first
end
@@ -57,12 +59,13 @@
def perform_action(action, *arguments)
@removed_actions = File.readlines(File.join(File.dirname(__FILE__), 'removed_actions.txt')) unless @removed_actions
@removed_actions.map! &:chomp
if @removed_actions.include?(action)
- puts "Error: The action '#{action}' was removed in calabash-android x.x.x"
- puts 'For more information visit: https://github.com/calabash-android/foo/bar'
+ puts "\e[31mError: The action '#{action}' was removed in calabash-android 0.5\e[0m"
+ puts 'Solutions that do not require the removed action can be found on:'
+ puts "\e[36mhttps://github.com/calabash/calabash-android/blob/master/migrating_to_calabash_0.5.md\##{action}\e[0m"
end
default_device.perform_action(action, *arguments)
end
@@ -160,10 +163,14 @@
end
end
map(uiquery,:query,*converted_args)
end
+ def flash(query_string)
+ map(query_string, :flash)
+ end
+
def each_item(opts={:query => "android.widget.ListView", :post_scroll => 0.2}, &block)
uiquery = opts[:query] || "android.widget.ListView"
skip_if = opts[:skip_if] || lambda { |i| false }
stop_when = opts[:stop_when] || lambda { |i| false }
check_element_exists(uiquery)
@@ -499,11 +506,10 @@
end
env_options = {:target_package => package_name(@app_path),
:main_activity => main_activity(@app_path),
:test_server_port => @test_server_port,
- :debug => false,
:class => "sh.calaba.instrumentationbackend.InstrumentationBackend"}
env_options = env_options.merge(options)
cmd_arr = [adb_command, "shell am instrument"]
@@ -722,85 +728,14 @@
screenshot_embed
end
raise(msg)
end
- def has_text?(text)
- !query("* {text CONTAINS[c] '#{text}'}").empty?
- end
-
- def assert_text(text, should_find = true)
- raise "Text \"#{text}\" was #{should_find ? 'not ' : ''}found." if has_text?(text) ^ should_find
-
- true
- end
-
- def double_tap(uiquery, options = {})
- center_x, center_y = find_coordinate(uiquery)
-
- perform_action("double_tap_coordinate", center_x, center_y)
- end
-
- # Performs a "long press" operation on a selected view
- # Params:
- # +uiquery+: a uiquery identifying one view
- # +options[:length]+: the length of the long press in milliseconds (optional)
- #
- # Examples:
- # - long_press("* id:'my_id'")
- # - long_press("* id:'my_id'", {:length=>5000})
- def long_press(uiquery, options = {})
- center_x, center_y = find_coordinate(uiquery)
- length = options[:length]
- perform_action("long_press_coordinate", center_x, center_y, *(length unless length.nil?))
- end
-
- def touch(uiquery, options = {})
- center_x, center_y = find_coordinate(uiquery)
-
- perform_action("touch_coordinate", center_x, center_y)
- end
-
- def keyboard_enter_text(text, options = {})
- perform_action('keyboard_enter_text', text)
- end
-
- def keyboard_enter_char(character, options = {})
- keyboard_enter_text(character[0,1], options)
- end
-
- def enter_text(uiquery, text, options = {})
- tap_when_element_exists(uiquery, options)
- sleep 0.5
- keyboard_enter_text(text, options)
- end
-
- def clear_text(query_string, options={})
- result = query(query_string, setText: '')
-
- raise "No elements found. Query: #{query_string}" if result.empty?
-
- true
- end
-
def hide_soft_keyboard
perform_action('hide_soft_keyboard')
end
- def find_coordinate(uiquery)
- raise "Cannot find nil" unless uiquery
-
- element = execute_uiquery(uiquery)
-
- raise "No elements found. Query: #{uiquery}" if element.nil?
-
- center_x = element["rect"]["center_x"]
- center_y = element["rect"]["center_y"]
-
- [center_x, center_y]
- end
-
def execute_uiquery(uiquery)
if uiquery.instance_of? String
elements = query(uiquery)
return elements.first unless elements.empty?
@@ -852,30 +787,10 @@
combined_query_string = "#{container_class} descendant #{menu_item_query_string}"
touch(combined_query_string)
end
- def tap_when_element_exists(query_string, options={})
- options.merge!({action: lambda {|q| touch(q)}})
-
- if options[:scroll] == true
- scroll_to(query_string, options)
- else
- when_element_exists(query_string, options)
- end
- end
-
- def long_press_when_element_exists(query_string, options={})
- options.merge!({action: lambda {|q| long_press(q)}})
-
- if options[:scroll] == true
- scroll_to(query_string, options)
- else
- when_element_exists(query_string, options)
- end
- end
-
def swipe(dir,options={})
ni
end
def cell_swipe(options={})
@@ -941,11 +856,16 @@
element = query(all_query_string).first
raise "No elements found. Query: #{all_query_string}" if element.nil?
element_center_y = element['rect']['center_y']
- scroll_view_query_string = "#{all_query_string} parent android.widget.ScrollView index:0"
+ if element.has_key?('html')
+ scroll_view_query_string = element['webView']
+ else
+ scroll_view_query_string = "#{all_query_string} parent android.widget.ScrollView index:0"
+ end
+
scroll_element = query(scroll_view_query_string).first
raise "Could not find parent scroll view. Query: #{scroll_view_query_string}" if element.nil?
scroll_element_y = scroll_element['rect']['y']
@@ -1065,10 +985,9 @@
end
def make_http_request(options)
default_device.make_http_request(options)
end
-
end
end end