Android - How to get Logcat logs for specified actions - android

I am doing set of steps using Android UIAutomator. I just want to collect logs during these steps.
Now am starting the adb logcat in terminal and running the ui automator seperately. Save the current logs to file before starting another test case.
Is there a way to collect logs for a particular time and clear the logs and start the next test case and collect logs for that test case.
Thanks in advance

You can filter by configurable log tags.
Log.d(TAG, message);
Specify separate tags for your groups in your tests and then you can easily grab just the ones you want at a time.
adb logcat -s "TAGNAME"
Run your test through fully so all logs are in the logcat then add the logs to a text file in their groupings by iterating through your tags in a script. Pseudo code:
for (TAG in MYTAGS) {
abd logcat -s TAG >> mylogfile
}

Add custom tag in your UI Automator script:
private static final String TAG = "Script_Name";
Log.d(TAG, "message");
Write a simple batch script to collect logs and start it before you run your script:
adb logcat -c //To clear previous logs
adb logcat -s Script_Name > Log.txt //Saves your Script specific logs into Log.txt

Related

Can a specified message or row be cleared in the adb logcat instead of clearing all?

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.

Is it possible to start app without starting test server?

I need to start app before running tests in order to initialize some folders in /data/data/appName/files/ and then I want to use adb command to push some files there.
If I use start_test_server_in_background, it will start tests also...
#I can't do this, bcs it will run my tests before I have data in there
start_test_server_in_background
shutdown_test_server
#I tried something like this, I am not sure how it should be written
http("/ready")
http("/kill")
#Pushing files to created folders afterwards
system("#{default_device.adb_command} push /someFolder/someFiles /data/data/appName/files")
I was able to start app like this:
pn = package_name(ENV['APP_PATH'])
cmd = "#{default_device.adb_command} shell monkey -p \"#{pn}\" -c android.intent.category.LAUNCHER 1"
result = `#{cmd}`
But in the end it was not the problem I got, so my question was misleading

Code to Get Data from type error in logcat programmatically

I have gone through many tutorials, but I haven't found how to get the error logs.
I found one link:
http://www.helloandroid.com/tutorials/reading-logs-programatically
and gone through it. I want only error logs, I don't know which command must write to show error logs. My requirement is to send the logs through email, I don't want any adb command. I want the command to write in java to read the logs of error/debug/info.
Example: to dump a file, they have written code like
Process process = Runtime.getRuntime().exec("logcat -d");
To print only error logs, what command should I write?
Gone through Andorid Developers Blog: http://developer.android.com/tools/debugging/debugging-log.html
Process process = Runtime.getRuntime().exec("logcat -d *:E");
If you want an error log, just write: Log.e("MyClass", "This is an error");
And if you want to display errors only, just change the log level in Android Studio like this:

Filter application in adb logcat terminal

For debugging android applications I want to run logcat in a terminal (adb logcat). I've been using short tags for logging ([Class].class.getSimpleName()) to distinguish between the entries them more easily. However, adb logcat only lets me filter by tag, not by application (like the ADT plugin in Eclipse allows).
The only solution I could come up with is to pipe the logcat through grep [PID] but that isn't much help, since the app gets a new PID whenever I run it.
Can anyone offer an idea what might work?
you can try pidcat to filter by application , and it's colored output, then just run
pidcat yourpackagename
Just create a new filter in logcat, and in application name, put you app name (Package name from manifest), this will create a new filter for you which will only list message thrown by your app in logcat.

Dalvik Debug Monitor not showing all logs

In my Dalvik Debug Monitor new log messages which have different tag than previous log message are displaying after erasing all previous log messages. That means log is clearing itself all the time and only showing a few lines. What will i do to view all Log messages??
This happens a lot to me too. As far as I know there's no easy way around it but have a look at this python script which I modified (for full disclosure this is the original colored logcat script
- I changed the formatting and tweaked it a bit)
or you could just use the command line:
adb lolcat
or if you're interested in a specific tag, and using unix (or cygwin as I noticed you're on the PC):
adb lolcat | grep TextToFind
P.S. yes I know I'm using lolcat, instead of logcat - both will work. lolcat is just for the lulz
* EDIT *
You can also use logcat filtering to get the data you want from logcat. For example I ususally use this combination:
adb logcat MyAppTag:* *:E
this gives me all the logs which has a tag of MyAppTag and all other error and fatal messages. This is, imo, a better way of doing it than using grep.

Categories

Resources