Need to capture adb logs and push output to file using java

Hi All,

Currently i am using TestNG framework.

Question
1 Need to capture the adb logs and write it some file.
2. validate the Tags present or not in the output file using Shell script.

Plz help to resolve it

Thanks & Regards
Shashi Kumar JB

Check this out to get adb log:

		String filter = "adb logcat -d <filterName>:V *:S";
		Process p = Runtime.getRuntime().exec(
				(<ADB_Path>).concat(filter));

After this save it to file and validate through java code whether particular tags are present or not

If you are after logcat, appium gives you a mechanism for grabbing them. It’s not very flexible; we just grab all of them. Here’s an example in Ruby. I’ll have to hope you get the general idea and can translate it into Java

appium_driver.driver.manage.logs.get(“logcat”)

1 Like
  @Test
	public void launchAVD() throws InterruptedException, IOException {
		ProcessBuilder pbEmulator = new ProcessBuilder("emulator", "-avd", "EmulatorAndroidName");
		Process pcEmulator = pbEmulator.start();
		pcEmulator.waitFor();
		
		ProcessBuilder pbADB = new ProcessBuilder("adb", "devices");
		Process pcADB = pbADB.start();
		pcADB.waitFor();
		
		InputStream is = pcADB.getInputStream();
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		String line;
		String adb = new String();
		
		while ((line = br.readLine()) != null) {
		    if (line.length()>0)
			line += br.readLine();
		    System.out.println(line);
		}
	
		if (adb.contains("emulator-5554") && (!adb.contains("offline"))) {
			System.out.println("Device is connected");	
		}
	}

Hi Amit,

Using above code I m not able to capture the logs…

Please help to capture the ADB logs and write to file