I am using Monkeyrunner (automation) to test an app on an Android device (Samsung S2), and since it does not allow me to see image patterns on the screen, I have to rely on the adb logcat (using Windows) to look for specific messages in order to know when the next page has loaded for my automation script.
And in order to look for specific (unique) messages in the logcat, for my monkeyrunner script, I have to CLEAR out ALL the adb logs, then perform the search.
Is there a way to clear out only the line(s) that match a specific tag, message, text, or whatever(!), within the logcat log? Instead of clearing out everything?
Does the command line adb functionality allow you to clear specific lines, or is it an all or nothing kinda thing?
Clearing out all the logcat longs works, but it would be nice to ONLY clear out certain messages so that if/when there is an app crash, or some event where I need details for troubleshooting, I can see all the logs leading up to the crash (or significant event). Because if everything is cleared out, there is no way for me to see the logcat logs to troubleshoot whatever.
::: MORE INFORMATION :::
Here is the function I currently use to clear out all the logs.
def clearAdb():
p = subprocess.Popen("adb logcat -v time", shell=True, cwd="C:\Users\<USERNAME>AppData\Local\Android\sdk\platform-tools", stdout=subprocess.PIPE)
subprocess.Popen("adb logcat -c", shell=True, cwd="C:\Users\<USERNAME>AppData\Local\Android\sdk\platform-tools", stdout=subprocess.PIPE)
print("::: ADB cleared :::")
..and here's an example of how I am looking for the logcat log. This adb function waits indefinitely for a specific adb message, and process when seen.
def adb(message):
p = subprocess.Popen("adb logcat -v time", shell=True, cwd="C:\Users\<USERNAME>\AppData\Local\Android\sdk\platform-tools", stdout=subprocess.PIPE)
for line in p.stdout:
if message in line:
print("Got 'em")
break
else:
continue
...and this is how I currently use the functions together...
clearAdb()
adb("identifyGamePackage. com.tfg.nameofapplication")
To limit logcat
output to messages which happened after certain moment you do not have to clear the log. Instead use logcat -T <timestamp>
filter. Supported timestamp formats depend on the Android version - see -T
paragraph in logcat -h
output.