Skip to content

Instantly share code, notes, and snippets.

@bootstraponline
Created January 21, 2013 21:53
Show Gist options
  • Save bootstraponline/4589830 to your computer and use it in GitHub Desktop.
Save bootstraponline/4589830 to your computer and use it in GitHub Desktop.
# Implement is focused app using dumpsys window windows
def is_focused_app app
output = `#{adb_command} shell dumpsys window windows`
return false if output.nil?
target = nil
output.each_line do |line|
if line.include? 'mFocusedApp'
target = line
break
end
end
return false if target.nil?
focused = target.match(/\/\.([^}]+)}/)
return false if focused.nil?
focused[1] == app
end
puts is_focused_app 'MyActivity'
@bootstraponline
Copy link
Author

@jonasmaturana I think your focused_activity is better. Then something like this can be written:

def wait_for_activity activity
  retriable :tries => 5, :interval => 2 do
    focused = focused_activity
    raise "Activity #{activity} not found. Current activity is #{focused}" if focused != activity
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment