From 895b49d5094600631429c30ef77e647d846e28cc Mon Sep 17 00:00:00 2001 From: James Strachan Date: Sat, 16 Jun 2012 08:25:32 +0100 Subject: [PATCH] added better error messages and test case names for the JUnit running of QUnit tests --- .../kotlin/js/qunit/SeleniumQUnit.kt | 33 +++++++++++++++---- .../src/test/kotlin/tests/SeleniumTest.java | 2 ++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/libraries/tools/kotlin-js-tests-junit/src/main/kotlin/org/jetbrains/kotlin/js/qunit/SeleniumQUnit.kt b/libraries/tools/kotlin-js-tests-junit/src/main/kotlin/org/jetbrains/kotlin/js/qunit/SeleniumQUnit.kt index 08979b8ce0b..0ae0bfaf7d7 100644 --- a/libraries/tools/kotlin-js-tests-junit/src/main/kotlin/org/jetbrains/kotlin/js/qunit/SeleniumQUnit.kt +++ b/libraries/tools/kotlin-js-tests-junit/src/main/kotlin/org/jetbrains/kotlin/js/qunit/SeleniumQUnit.kt @@ -7,9 +7,9 @@ import org.openqa.selenium.WebDriver import org.openqa.selenium.WebElement /** - * Waits up to a *maxMills* time for a predicate to be true, sleeping for *sleepMillis* - * and retrying until the timeout fails - */ +* Waits up to a *maxMills* time for a predicate to be true, sleeping for *sleepMillis* +* and retrying until the timeout fails +*/ public fun waitFor(maxMillis: Long, sleepMillis: Long = 100, predicate: () -> Boolean): Boolean { val end = System.currentTimeMillis() + maxMillis while (true) { @@ -40,11 +40,17 @@ public class SeleniumQUnit(val driver: WebDriver) { resultsElement != null } assertNotNull(resultsElement, "No qunit test elements could be found in ${driver.getCurrentUrl()}") - return resultsElement!!.findElements(By.tagName("li")).filterNotNull() + return resultsElement!!.findElements(By.xpath("li")).filterNotNull() } public fun findTestName(element: WebElement): String { - return element.getAttribute("id") ?: "unknown test name for $element" + fun defaultName(name: String?) = name ?: "unknown test name for $element" + try { + val testNameElement = element.findElement(By.xpath("descendant::*[@class = 'test-name']")) + return defaultName(testNameElement!!.getText()) + } catch (e: Exception) { + return defaultName(element.getAttribute("id")) + } } public fun runTest(element: WebElement): Unit { @@ -53,6 +59,21 @@ public class SeleniumQUnit(val driver: WebDriver) { result = element.getAttribute("class") ?: "no result" !result.startsWith("run") } - assertEquals("pass", result, "test result for test case ${findTestName(element)}") + if ("pass" != result) { + var message: String? = null + try { + val messageElement = element.findElement(By.xpath("descendant::*[@class = 'test-message']"))!! + message = messageElement.getText() + } catch (e: Exception) { + // ignore + } + val testName = "${findTestName(element)} result: $result" + val fullMessage = if (message != null) { + testName + message + } else { + "test result for test case $testName" + } + fail(fullMessage) + } } } \ No newline at end of file diff --git a/libraries/tools/kotlin-js-tests-junit/src/test/kotlin/tests/SeleniumTest.java b/libraries/tools/kotlin-js-tests-junit/src/test/kotlin/tests/SeleniumTest.java index 16a95c3050a..f6be7c155b5 100644 --- a/libraries/tools/kotlin-js-tests-junit/src/test/kotlin/tests/SeleniumTest.java +++ b/libraries/tools/kotlin-js-tests-junit/src/test/kotlin/tests/SeleniumTest.java @@ -52,6 +52,8 @@ public class SeleniumTest { public SeleniumTest(WebElement element) { this.element = element; this.name = tester.findTestName(element); + + System.out.println("Test name: " + name); } @Test