module WDA::Debug

Public Instance Methods

accessibility_tree(opts = {}) click to toggle source

Get accessibility tree

# 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() { || ... } click to toggle source
# 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) click to toggle source

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

# 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() click to toggle source
# File lib/wda_lib/debug.rb, line 47
def get_source
  response = source
  response['value']['children']
end
get_window(window_number = 0) click to toggle source

def get_window_statusbar

source['value']['children'][-3]

end

# File lib/wda_lib/debug.rb, line 56
def get_window(window_number = 0)
  source['value']['children'][window_number]
end
source(opts = {}) click to toggle source

Get all elements on current screen @param session_id [String], not_fetch_inaccessible [Boolean], not_fetch_invisible [Boolean], timeout [Integer] 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 @return [Hash]

# 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