You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2018/05/25 11:59:49 UTC
[myfaces-tobago] branch master updated: improve wait for tests
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/master by this push:
new 429ba11 improve wait for tests
429ba11 is described below
commit 429ba116fe7102003fbb7d72c3a134f29a73cbf9
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri May 25 13:59:26 2018 +0200
improve wait for tests
* while waiting for the qunit test, a NoSuchElementException shouldn't
be thrown
* update dependency
---
tobago-example/tobago-example-demo/pom.xml | 2 +-
.../example/demo/qunit/AccessAllPagesTest.java | 17 ++------------
.../tobago/example/demo/qunit/SeleniumBase.java | 26 +++++++++++++++++-----
3 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/tobago-example/tobago-example-demo/pom.xml b/tobago-example/tobago-example-demo/pom.xml
index 94ba60a..a35f504 100644
--- a/tobago-example/tobago-example-demo/pom.xml
+++ b/tobago-example/tobago-example-demo/pom.xml
@@ -154,7 +154,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
- <version>23.0</version>
+ <version>25.0-jre</version>
</dependency>
</dependencies>
</dependencyManagement>
diff --git a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/AccessAllPagesTest.java b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/AccessAllPagesTest.java
index 2323ff5..cbe9ca0 100644
--- a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/AccessAllPagesTest.java
+++ b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/AccessAllPagesTest.java
@@ -25,8 +25,6 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
-import org.openqa.selenium.support.ui.ExpectedConditions;
-import org.openqa.selenium.support.ui.FluentWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +35,6 @@ import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.time.Duration;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@@ -61,14 +58,9 @@ class AccessAllPagesTest extends SeleniumBase {
final String path = "error/exception.xhtml";
setupWebDriver(portContextPath, path, true);
- WebElement qunitBanner = getWebDriver().findElement(By.id("qunit-banner"));
+ waitForQUnitBanner();
WebElement qunitTests = getWebDriver().findElement(By.id("qunit-tests"));
- new FluentWait(getWebDriver())
- .withTimeout(Duration.ofSeconds(90))
- .pollingEvery(Duration.ofSeconds(1))
- .until(ExpectedConditions.attributeToBeNotEmpty(qunitBanner, "class"));
-
List<WebElement> results = qunitTests.findElements(By.xpath("li"));
boolean testException = false;
for (final WebElement result : results) {
@@ -94,14 +86,9 @@ class AccessAllPagesTest extends SeleniumBase {
final String path = "error/404.xhtml";
setupWebDriver(portContextPath, path, true);
- WebElement qunitBanner = getWebDriver().findElement(By.id("qunit-banner"));
+ waitForQUnitBanner();
WebElement qunitTests = getWebDriver().findElement(By.id("qunit-tests"));
- new FluentWait(getWebDriver())
- .withTimeout(Duration.ofSeconds(90))
- .pollingEvery(Duration.ofSeconds(1))
- .until(ExpectedConditions.attributeToBeNotEmpty(qunitBanner, "class"));
-
List<WebElement> results = qunitTests.findElements(By.xpath("li"));
boolean test404 = false;
for (final WebElement result : results) {
diff --git a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/SeleniumBase.java b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/SeleniumBase.java
index e110078..7e85ad1 100644
--- a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/SeleniumBase.java
+++ b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/qunit/SeleniumBase.java
@@ -23,6 +23,7 @@ import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.openqa.selenium.By;
import org.openqa.selenium.MutableCapabilities;
+import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
@@ -92,17 +93,30 @@ abstract class SeleniumBase {
return webDriver;
}
+ /**
+ * Wait for the qunit-banner web element and return it.
+ * If the web element is available, the execution of qunit test should be done and it is safe to parse the results.
+ *
+ * @return qunit-banner web element
+ */
+ WebElement waitForQUnitBanner() {
+ final FluentWait<WebDriver> fluentWait = new FluentWait<>(webDriver)
+ .withTimeout(Duration.ofSeconds(90))
+ .pollingEvery(Duration.ofSeconds(1))
+ .ignoring(NoSuchElementException.class);
+
+ WebElement qunitBanner = fluentWait.until(driver -> driver.findElement(By.id("qunit-banner")));
+ fluentWait.until(ExpectedConditions.attributeToBeNotEmpty(qunitBanner, "class"));
+
+ return qunitBanner;
+ }
+
void parseQUnitResults(final Browser browser, final String portContextPath, final String path)
throws UnknownHostException {
- WebElement qunitBanner = webDriver.findElement(By.id("qunit-banner"));
+ WebElement qunitBanner = waitForQUnitBanner();
WebElement qunitTestResult = webDriver.findElement(By.id("qunit-testresult"));
WebElement qunitTests = webDriver.findElement(By.id("qunit-tests"));
- new FluentWait(webDriver)
- .withTimeout(Duration.ofSeconds(90))
- .pollingEvery(Duration.ofSeconds(1))
- .until(ExpectedConditions.attributeToBeNotEmpty(qunitBanner, "class"));
-
final List<WebElement> testCases = qunitTests.findElements(By.xpath("li"));
Assert.assertTrue("There must be at least one test case.", testCases.size() > 0);
--
To stop receiving notification emails like this one, please contact
hnoeth@apache.org.