Skip to content

Commit

Permalink
Merge Issue4332IT into Spec1396IT
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Feb 18, 2024
1 parent 9ea30a9 commit b4d8cd5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 100 deletions.
2 changes: 1 addition & 1 deletion tck/faces23/websocket/src/main/webapp/issue4332.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<script>
function onmessageFunction(message) {
document.getElementById("message").value = message;
document.getElementById("message").innerHTML = message;
}
</script>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
import ee.jakarta.tck.faces.test.util.selenium.WebPage;
import jakarta.faces.component.UIWebsocket;

/**
* NOTE: all websocket related tests must be executed from a SINGLE test class.
* Otherwise the push will seem to hang/freeze when executed in a next class. This is probably a selenium webdriver bug.
*/
public class Spec1396IT extends BaseITNG {

/**
Expand Down Expand Up @@ -102,17 +106,46 @@ public void testViewScopedWebsocket() throws Exception {
waitUntilWebsocketIsPushed(getWebDriver(), page);
}

/**
* @see UIWebsocket
* @see https://github.com/eclipse-ee4j/mojarra/issues/4332
*/
@Test
public void testWebsocketAfterPostback() throws Exception {
WebPage page = getPage("issue4332.xhtml");

String pageSource = page.getPageSource();
assertTrue(pageSource.contains("faces.push.init("));
assertTrue(pageSource.contains("/jakarta.faces.push/push?"));

waitUntilWebsocketIsOpened(getWebDriver(), page);

WebElement postback = page.findElement(By.id("form:postback"));
postback.click();

pageSource = page.getPageSource();
assertTrue(pageSource.contains("faces.push.init("));
assertTrue(pageSource.contains("/jakarta.faces.push/push?"));

waitUntilWebsocketIsOpened(getWebDriver(), page);

WebElement button = page.findElement(By.id("form:button"));
button.click();

waitUntilWebsocketIsPushed(getWebDriver(), page);
}

/**
* HtmlUnit is not capable of waiting until WS is opened. Hence this work around.
*/
static void waitUntilWebsocketIsOpened(WebDriver browser, WebPage page) throws Exception {
private static void waitUntilWebsocketIsOpened(WebDriver browser, WebPage page) throws Exception {
new WebDriverWait(browser, ofSeconds(3)).until($ -> "yes".equals(page.findElement(By.id("opened")).getText()));
}

/**
* HtmlUnit is not capable of waiting until WS is pushed. Hence this work around.
*/
static void waitUntilWebsocketIsPushed(WebDriver browser, WebPage page) throws Exception {
private static void waitUntilWebsocketIsPushed(WebDriver browser, WebPage page) throws Exception {
new WebDriverWait(browser, ofSeconds(3)).until($ -> "pushed!".equals(page.findElement(By.id("message")).getText()));
}

Expand Down

0 comments on commit b4d8cd5

Please sign in to comment.