Created
January 21, 2013 21:53
-
-
Save bootstraponline/4589830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
@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
Cool! The regex has to be changed a bit though since the activity can be shown in one of these three ways:
I think this would work
[\.\/]([^.\/\}]+)
.By using Enumerable.grep and including
mFocusedApp
we can do all the grepping in one line:I think it more general
focused_activty
would be useful but a helper method like youris_focused_activity?
is a good helper