From e59b089103b2f765371e8193c6fec4259ae81ee2 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 28 Jan 2016 15:34:10 +0100 Subject: [PATCH] dump js logs --- .../test/java/util/selenium/SeleneseTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/it/it-tests/src/test/java/util/selenium/SeleneseTest.java b/it/it-tests/src/test/java/util/selenium/SeleneseTest.java index d4d428dc916..a23cfb5828e 100644 --- a/it/it-tests/src/test/java/util/selenium/SeleneseTest.java +++ b/it/it-tests/src/test/java/util/selenium/SeleneseTest.java @@ -24,6 +24,7 @@ import com.sonar.orchestrator.selenium.Selenese; import java.io.File; import java.io.IOException; import java.net.URI; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; @@ -34,6 +35,9 @@ import org.jsoup.nodes.Element; import org.openqa.selenium.By; import org.openqa.selenium.NotFoundException; import org.openqa.selenium.WebElement; +import org.openqa.selenium.logging.LogEntries; +import org.openqa.selenium.logging.LogEntry; +import org.openqa.selenium.logging.LogType; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; @@ -70,13 +74,25 @@ public class SeleneseTest { String param1 = tr.child(1).text(); String param2 = tr.child(2).text(); - action(action, param1, param2); + try { + action(action, param1, param2); + } catch (AssertionError e) { + analyzeLog(driver); + throw e; + } } } } } } + private static void analyzeLog(SeleniumDriver driver) { + LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER); + for (LogEntry entry : logEntries) { + System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage()); + } + } + private static Document parse(File file) { try { return Jsoup.parse(file, UTF_8.name()); -- 2.39.5