Skip to content

Instantly share code, notes, and snippets.

@DominikDary
Created September 20, 2013 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikDary/6633764 to your computer and use it in GitHub Desktop.
Save DominikDary/6633764 to your computer and use it in GitHub Desktop.
public static void driverLogs(WebDriver driver, String className, String methodName) {
LogEntries logs;
try {
logs = driver.manage().logs().get("logcat");
} catch (Exception e) {
return;
} catch (OutOfMemoryError e) {
System.out.println("failed to get logcat due to OOM current max memory:" + Runtime.getRuntime().maxMemory() +
" current free memory: " + Runtime.getRuntime().freeMemory() );
return;
}
String outputFolder = "target/artifacts/device_logs";
File outputDir = new File(outputFolder);
String outputFileName = outputFolder + "/" + methodName + "_logcat.txt";
File outputFile = new File(outputFileName);
PrintWriter writer = null;
outputDir.mkdirs();
try {
writer = new PrintWriter(outputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("saving logs to: " + outputFile.getAbsolutePath());
String formatedUrl = JENKINS_URL;
if (JENKINS_URL.contains("%s")) {
formatedUrl = String.format(formatedUrl, className);
}
System.out.println("If on Jenkins view at: " + formatedUrl + outputFileName);
for (LogEntry log : logs) {
writer.println(log.getMessage());
}
writer.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment