Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/jakartaee/faces/issues/1722: Adding ported Selenium Ajax Tests #1732

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tck/faces22/ajax/src/main/webapp/issue1957.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
<script type="text/javascript">
var statusUpdate = function statusUpdate(data) {
var statusArea = document.getElementById("statusArea");
var text = statusArea.value;
var text = statusArea.innerHTML;
text = text + "Name: "+data.source.id;
if (data.type === "event") {
text = text +" Event: "+data.status+" ";
}
statusArea.value = text;
statusArea.innerHTML = text;
}

</script>

<h:form id="form">
Expand All @@ -45,13 +46,13 @@
<h:outputText value="I am in a panel group"/>
</h:panelGroup>

<h:messages/>

</h:form>

<p>
<h3> Status:</h3>
<textarea id="statusArea" cols="40" rows="10" readonly="readonly" />
<div id="statusArea" />

</p>

</h:body>
Expand Down
6 changes: 3 additions & 3 deletions tck/faces22/ajax/src/main/webapp/issue2179-page2.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
<script type="text/javascript">
var statusUpdate = function statusUpdate(data) {
var statusArea = document.getElementById("statusArea");
var text = statusArea.value;
var text = statusArea.innerHTML;
text = text + "Name: "+data.source.id;
if (data.type === "error") {
text = text + " Error: "+data.status+" "+data.errorMessage;
}
statusArea.value = text;
statusArea.innerHTML = text;
}
</script>

Expand All @@ -53,7 +53,7 @@

<p>
<h3> Status:</h3>
<textarea id="statusArea" cols="40" rows="10" readonly="readonly" />
<div id="statusArea" />
</p>

</h:body>
Expand Down
7 changes: 7 additions & 0 deletions tck/faces22/ajax/src/main/webapp/issue3020Negative.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@
</h:panelGroup>
</h:form>

<div id="windowError"></div>
<script type="text/javascript">
window.addEventListener("error", event => {
let el = document.getElementById("windowError");
el.innerHTML = el.innerHTML + " Type: " + event.type + "Message" + event.message;
});
</script>
</h:body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package ee.jakarta.tck.faces.test.servlet30.ajax_new;


import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import ee.jakarta.tck.faces.test.util.selenium.WebPage;
import jakarta.faces.component.behavior.AjaxBehavior;
import jakarta.faces.context.PartialViewContext;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static org.junit.Assert.assertEquals;

public class Issue1284IT extends BaseITNG {

/**
* @see AjaxBehavior
* @see PartialViewContext#getEvalScripts()
* @see https://github.com/eclipse-ee4j/mojarra/issues/1289
*/
@Test
public void testCdataEscape5() throws Exception {
WebPage page = getPage("issue1284.xhtml");
assertEquals("", page.findElement(By.id("form1:out1")).getText());
assertEquals("", page.findElement(By.id("form1:in1")).getAttribute("value"));

WebElement in1 = page.findElement(By.id("form1:in1"));
in1.sendKeys("[");

// Submit the ajax request
WebElement button1 = page.findElement(By.id("form1:button1"));
button1.click();
Thread.sleep(3000);

// Check that the ajax request succeeds
assertEquals("[", page.findElement(By.id("form1:out1")).getText());
}

/**
* @see AjaxBehavior
* @see PartialViewContext#getEvalScripts()
* @see https://github.com/eclipse-ee4j/mojarra/issues/1289
*/
@Test
public void testCdataEscape6() throws Exception {
WebPage page = getPage("issue1284.xhtml");
assertEquals("", page.findElement(By.id("form1:out1")).getText());
assertEquals("", page.findElement(By.id("form1:in1")).getAttribute("value"));

WebElement in1 = page.findElement(By.id("form1:in1"));
in1.sendKeys("var a=[");

// Submit the ajax request
WebElement button1 = page.findElement(By.id("form1:button1"));
button1.click();
Thread.sleep(3000);

// Check that the ajax request succeeds
assertEquals("var a=[", page.findElement(By.id("form1:out1")).getText());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package ee.jakarta.tck.faces.test.servlet30.ajax_new;

import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import ee.jakarta.tck.faces.test.util.selenium.WebPage;
import jakarta.faces.component.behavior.AjaxBehavior;
import jakarta.faces.component.html.HtmlSelectOneRadio;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static org.junit.Assert.assertTrue;

/**
* @author Manfred Riem ([email protected])
*/
public class Issue1533IT extends BaseITNG {

/**
* @see AjaxBehavior
* @see HtmlSelectOneRadio
* @see https://github.com/eclipse-ee4j/mojarra/issues/1537
*/
@Test
public void testIssue1533() throws Exception {
WebPage page = getPage("issue1533.xhtml");
WebElement input = page.findElement(By.id("form:vip:0"));
input.click();
Thread.sleep(3000);
assertTrue(page.getPageSource().indexOf("form:vip-true") != -1);
input = page.findElement(By.id("form:vip:1"));
input.click();
Thread.sleep(3000);
assertTrue(page.getPageSource().indexOf("form:vip-false") != -1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package ee.jakarta.tck.faces.test.servlet30.ajax_new;

import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import ee.jakarta.tck.faces.test.util.selenium.WebPage;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static org.junit.Assert.assertEquals;


public class Issue1581IT extends BaseITNG {

/**
* This test verifies correct function of SelectManyCheckbox in a Composite
* Component over Ajax.
*/
@Test
public void testSelectManyCheckboxInComposite() throws Exception {
WebPage page = getPage("issue1581.xhtml");

// This will ensure JavaScript finishes before evaluating the page.
page.waitReqJs();
assertCheckBoxes(getCheckboxes(page), false, false, false, false);

getCheckboxes(page).get(0).click();
page.waitReqJs();
assertCheckBoxes(getCheckboxes(page), true, false, false, false);

getCheckboxes(page).get(1).click();
page.waitReqJs();
assertCheckBoxes(getCheckboxes(page), true, true, false, false);

getCheckboxes(page).get(2).click();
page.waitReqJs();
assertCheckBoxes(getCheckboxes(page), true, true, true, false);

getCheckboxes(page).get(3).click();
page.waitReqJs();
assertCheckBoxes(getCheckboxes(page), true, true, true, true);
}


private void assertCheckBoxes(List<WebElement> checkboxes, boolean... expectedValues) {
for (int cnt = 0; cnt < checkboxes.size(); cnt++) {
WebElement checkbox = checkboxes.get(cnt);
//label assertion, the gettext of the parent returns the label only
assert (checkbox.findElement(By.xpath("..")).getText()).equals("JAVASERVERFACES-" + (cnt + 1));
boolean assertionValue = expectedValues[cnt];
assertEquals(checkbox.isSelected(), assertionValue);
}
}

private List<WebElement> getCheckboxes(WebPage page) {


List<WebElement> checkBoxes = new ArrayList<>();

List<WebElement> elements = page.findElements(By.tagName("input"));
for (Iterator<WebElement> it = elements.iterator(); it.hasNext(); ) {
WebElement elem = it.next();
if (elem.getAttribute("type").equals("checkbox")) {
checkBoxes.add(elem);
}
}

return checkBoxes;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package ee.jakarta.tck.faces.test.servlet30.ajax_new;

import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import ee.jakarta.tck.faces.test.util.selenium.WebPage;
import jakarta.faces.component.behavior.ClientBehaviorHolder;
import jakarta.faces.component.html.HtmlBody;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class Issue1781IT extends BaseITNG {

/**
* Test attaching a ClientBehaviorHolder to h:body. Note the current 2.1
* spec does not allow using f:ajax outside of a form so this will throw
* a script error which we are going to ignore.
*
* @see ClientBehaviorHolder
* @see HtmlBody
* @see https://github.com/eclipse-ee4j/mojarra/issues/1785
*/
@Test
public void testAjaxToOnBody() throws Exception {
// we stick with the webclient for simple http checks
// the selenium drivers cannot do it, that easily
WebPage page = getPage("body.xhtml");

//waitForCondition((webDriver) -> super.page.getResponseStatus() != -1, Duration.ofMillis(3000));
assertEquals(page.getResponseStatus(), 200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package ee.jakarta.tck.faces.test.servlet30.ajax_new;

import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import ee.jakarta.tck.faces.test.util.selenium.WebPage;
import jakarta.faces.component.behavior.AjaxBehavior;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertTrue;

public class Issue1817IT extends BaseITNG {

/**
* @see AjaxBehavior
* @see com.sun.faces.facelets.component.UIRepeat
* @see https://github.com/eclipse-ee4j/mojarra/issues/1821
*/
@Test
public void testAjaxUIRepeat() throws Exception {
WebPage page = getPage("issue1817.xhtml");
final List<WebElement> elements = page.findElements(By.tagName("a"));
List<String[]> ids = elements.stream().map(element -> new String[]{element.getAttribute("id"), element.getText()})
.collect(Collectors.toList());
for (String[] id : ids) {
WebElement anchor = page.findElement(By.id(id[0]));
anchor.click();
String expectedText = "Triggered item: " + id[1];
WebElement body = page.findElement(By.tagName("body"));
page.waitForCondition(ExpectedConditions.textToBePresentInElement(body, expectedText), Duration.ofMillis(3000));
assertTrue(page.getPageSource().contains(expectedText));
}
}
}
Loading