Module: WDA::Debug
- Included in:
- WDA
- Defined in:
- lib/wda_lib/debug.rb
Instance Method Summary collapse
-
#accessibility_tree(opts = {}) ⇒ Object
Get accessibility tree.
- #exists ⇒ Object
-
#find_app(app_name) ⇒ Object
Had issue when there is app shortcut in SIRI search or Today’s extention, having duplication app text, have to find the visibile one Try to find app on current screen, if can’t find, click home button to get first page of springboard.
- #get_source ⇒ Object
-
#get_window(window_number = 0) ⇒ Object
def get_window_statusbar source[‘children’] end.
-
#source(opts = {}) ⇒ Hash
Get all elements on current screen When accessible is true, ignore all elements except for the main window for accessibility tree When accessible is false, and visible is true, ignore all invisible elements.
Instance Method Details
#accessibility_tree(opts = {}) ⇒ Object
Get accessibility tree
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wda_lib/debug.rb', line 34 def accessibility_tree(opts = {}) session_id = opts.fetch(:session_id, nil) timeout = opts.fetch(:timeout, 60) @timeout = timeout.to_i if !timeout.nil? url = '/wda/accessibleSource' url = @base_url + '/wda/accessibleSource' if session_id.nil? begin res = get(url, @timeout) rescue raise Error::NoSuchElementError, "Can't fetch current screen accessibility tree within #{@timeout}s" if res['status'].nil? end end |
#exists ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/wda_lib/debug.rb', line 84 def exists exists = true begin yield # search for element rescue exists = false # error means it's not there end exists end |
#find_app(app_name) ⇒ Object
Had issue when there is app shortcut in SIRI search or Today’s extention, having duplication app text, have to find the visibile one Try to find app on current screen, if can’t find, click home button to get first page of springboard
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/wda_lib/debug.rb', line 63 def find_app(app_name) max = 0 app_found = false app = nil while !app_found && max < 10 do icons(app_name).each do |e| app = e if e.displayed? app_found = true break end end break if app_found homescreen if max == 1 # Get back to first page if first try failed swipe(@win_x*4/5, 10, @win_y/2, @win_y/2) max += 1 end app.nil?? (fail "Can't find app :#{app_name}") : app end |
#get_source ⇒ Object
47 48 49 50 |
# File 'lib/wda_lib/debug.rb', line 47 def get_source response = source response['value']['children'] end |
#get_window(window_number = 0) ⇒ Object
def get_window_statusbar
source['value']['children'][-3]
end
56 57 58 |
# File 'lib/wda_lib/debug.rb', line 56 def get_window(window_number = 0) source['value']['children'][window_number] end |
#source(opts = {}) ⇒ Hash
Get all elements on current screen When accessible is true, ignore all elements except for the main window for accessibility tree When accessible is false, and visible is true, ignore all invisible elements
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wda_lib/debug.rb', line 13 def source(opts = {}) response_type = opts.fetch(:response_type, 'json') session_id = opts.fetch(:session_id, nil) # not_fetch_inaccessible = opts.fetch(:not_fetch_inaccessible, true) # not_fetch_invisible = opts.fetch(:not_fetch_invisible, true) timeout = opts.fetch(:timeout, 60) @timeout = timeout.to_i if !timeout.nil? url = '/source' + '?format=' + response_type url = @base_url + '/source' + '?format=' + response_type if session_id.nil? begin res = get(url, # { accessible: not_fetch_inaccessible, visible: not_fetch_invisible }, @timeout) rescue raise Error::NoSuchElementError, "Can't fetch current screen elements within #{@timeout}s" if res['status'].nil? end @timeout = @default_timeout res end |