Module: WDA::Debug

Included in:
WDA
Defined in:
lib/wda_lib/debug.rb

Instance Method Summary collapse

Instance Method Details

#existsObject



66
67
68
69
70
71
72
73
74
# File 'lib/wda_lib/debug.rb', line 66

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wda_lib/debug.rb', line 45

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_sourceObject



30
31
32
# File 'lib/wda_lib/debug.rb', line 30

def get_source
  get(@base_url + '/source')['value']['tree']['children']
end

#get_window(window_number = 0) ⇒ Object



38
39
40
# File 'lib/wda_lib/debug.rb', line 38

def get_window(window_number = 0)
  get(@base_url + '/source')['value']['tree']['children'][window_number]
end

#get_window_statusbarObject



34
35
36
# File 'lib/wda_lib/debug.rb', line 34

def get_window_statusbar
  get(@base_url + '/source')['value']['tree']['children'][2]
end

#source(session_id = nil, not_fetch_inaccessible = true, not_fetch_invisible = true, timeout = 60) ⇒ 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

Parameters:

  • session_id (String) (defaults to: nil)

    , not_fetch_inaccessible [Boolean], not_fetch_invisible [Boolean], timeout [Integer]

Returns:

  • (Hash)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wda_lib/debug.rb', line 13

def source(session_id = nil, not_fetch_inaccessible = true, not_fetch_invisible = true, timeout = 60)
  @timeout = timeout.to_i if !timeout.nil?
  begin
    if session_id.nil?
      res = post(@base_url + '/source', { accessible: not_fetch_inaccessible, visible: not_fetch_invisible }, @timeout)
    else
      res = post('/source', { accessible: not_fetch_inaccessible, visible: not_fetch_invisible }, @timeout)
    end
  rescue
    raise Error::NoSuchElementError, "Can't fetch current screen elements within #{@timeout}s" if res['status'].nil?
  end
  @timeout = @default_timeout
  res
end