How to accesses android logcat logs with appium? – pCloudy – Question and Answers
Home >> Appium Tricks and Tricks >> How to accesses android logcat logs with ...

How to accesses android logcat logs with appium?


Code Snippet:

// inspect available log types
Set logtypes = driver.manage().logs().getAvailableLogTypes();
System.out.println("suported log types: " + logtypes.toString()); // [logcat, bugreport, server, client]

// print first and last 10 lines of logs
LogEntries logs = driver.manage().logs().get("logcat");
System.out.println("First and last ten lines of log: ");
StreamSupport.stream(logs.spliterator(), false).limit(10).forEach(System.out::println);
System.out.println("...");
StreamSupport.stream(logs.spliterator(), false).skip(logs.getAll().size() - 10).forEach(System.out::println);

// wait for more logs
try { Thread.sleep(5000); } catch (Exception ign) {} // pause to allow visual verification

// demonstrate that each time get logs, we only get new logs which were generated since the last time we got logs
LogEntries secondCallToLogs = driver.manage().logs().get("logcat");
System.out.println("\nFirst ten lines of next log call: ");
StreamSupport.stream(secondCallToLogs.spliterator(), false).limit(10).forEach(System.out::println);

Assert.assertNotEquals(logs.iterator().next(), secondCallToLogs.iterator().next());

Leave a Reply

Your email address will not be published. Required fields are marked *