JS tests: fixed waiting to finish qunit tests in SeleniumTest.
This commit is contained in:
+10
-5
@@ -17,13 +17,14 @@ public fun waitFor(maxMillis: Long, sleepMillis: Long = 100, predicate: () -> Bo
|
|||||||
}
|
}
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
if (now >= end) break
|
if (now >= end) break
|
||||||
val delta = end - now
|
|
||||||
val delay = sleepMillis
|
val delay = sleepMillis
|
||||||
Thread.sleep(delay)
|
Thread.sleep(delay)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val TIMEOUT: Long = 5000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to find QUnit tests using Selenium
|
* Helper class to find QUnit tests using Selenium
|
||||||
*/
|
*/
|
||||||
@@ -33,12 +34,16 @@ public class SeleniumQUnit(val driver: WebDriver) {
|
|||||||
* Returns all the test cases found in the current driver's page
|
* Returns all the test cases found in the current driver's page
|
||||||
*/
|
*/
|
||||||
public fun findTests(): List<WebElement> {
|
public fun findTests(): List<WebElement> {
|
||||||
var resultsElement: WebElement? = null
|
val qunitContainer = driver.findElement(By.id("qunit"))!!
|
||||||
waitFor(5000) {
|
|
||||||
resultsElement = driver.findElement(By.id("qunit-tests"))
|
val success = waitFor(TIMEOUT) {
|
||||||
resultsElement != null
|
qunitContainer.getAttribute("class") == "done"
|
||||||
}
|
}
|
||||||
|
assertTrue(success, "Tests timed out after $TIMEOUT milliseconds.")
|
||||||
|
|
||||||
|
var resultsElement = driver.findElement(By.id("qunit-tests"))
|
||||||
assertNotNull(resultsElement, "No qunit test elements could be found in ${driver.getCurrentUrl()}")
|
assertNotNull(resultsElement, "No qunit test elements could be found in ${driver.getCurrentUrl()}")
|
||||||
|
|
||||||
return resultsElement!!.findElements(By.xpath("li"))?.filterNotNull() ?: arrayListOf<WebElement>()
|
return resultsElement!!.findElements(By.xpath("li"))?.filterNotNull() ?: arrayListOf<WebElement>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,19 +18,11 @@
|
|||||||
package tests;
|
package tests;
|
||||||
|
|
||||||
import org.jetbrains.kotlin.js.qunit.SeleniumQUnit;
|
import org.jetbrains.kotlin.js.qunit.SeleniumQUnit;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
import org.openqa.selenium.firefox.FirefoxProfile;
|
import org.openqa.selenium.firefox.FirefoxProfile;
|
||||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@@ -48,8 +40,8 @@ public class SeleniumFireFox extends SeleniumTest {
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SeleniumFireFox(WebElement element) {
|
public SeleniumFireFox(WebElement element, String name) {
|
||||||
super(element);
|
super(element, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package tests;
|
package tests;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||||
import org.jetbrains.kotlin.js.qunit.SeleniumQUnit;
|
import org.jetbrains.kotlin.js.qunit.SeleniumQUnit;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -24,12 +25,10 @@ import org.junit.runners.Parameterized;
|
|||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,13 +50,9 @@ public class SeleniumTest {
|
|||||||
protected static SeleniumQUnit tester = new SeleniumQUnit(driver);
|
protected static SeleniumQUnit tester = new SeleniumQUnit(driver);
|
||||||
|
|
||||||
private final WebElement element;
|
private final WebElement element;
|
||||||
private String name;
|
|
||||||
|
|
||||||
public SeleniumTest(WebElement element) {
|
public SeleniumTest(WebElement element, String name) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.name = tester.findTestName(element);
|
|
||||||
|
|
||||||
System.out.println("Test name: " + name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -65,23 +60,17 @@ public class SeleniumTest {
|
|||||||
tester.runTest(element);
|
tester.runTest(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Parameterized.Parameters(name = "{1}")
|
||||||
public String toString() {
|
|
||||||
return "test " + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Parameterized.Parameters
|
|
||||||
public static List<Object[]> findTestElements() throws IOException, InterruptedException {
|
public static List<Object[]> findTestElements() throws IOException, InterruptedException {
|
||||||
String uri = "../kotlin-js-tests/src/test/web/index.html" + testQueryString;
|
String uri = "../kotlin-js-tests/src/test/web/index.html" + testQueryString;
|
||||||
File file = new File(uri);
|
File file = new File(uri);
|
||||||
driver.get("file://" + file.getCanonicalPath());
|
driver.get("file://" + file.getCanonicalPath());
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
List<WebElement> tests = tester.findTests();
|
List<WebElement> tests = tester.findTests();
|
||||||
// System.out.println("TESTS are: " + tests);
|
|
||||||
|
|
||||||
List<Object[]> list = new ArrayList<Object[]>();
|
List<Object[]> list = new ArrayList<Object[]>();
|
||||||
for (WebElement test : tests) {
|
for (WebElement test : tests) {
|
||||||
Object[] args = new Object[] { test };
|
Object[] args = new Object[] { test, tester.findTestName(test) };
|
||||||
list.add(args);
|
list.add(args);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -16,5 +16,12 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="qunit"></div>
|
<div id="qunit"></div>
|
||||||
<div id="qunit-fixture">test markup</div>
|
<div id="qunit-fixture">test markup</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById("qunit").className = "running";
|
||||||
|
QUnit.done(function () {
|
||||||
|
document.getElementById("qunit").className = "done"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user