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/pull/1732: Selenium tests for the ajax TCK (master branch) #1770

Merged
merged 11 commits into from
Jan 18, 2023
Merged
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: 8 additions & 1 deletion tck/faces22/ajax/src/main/webapp/issue3020Negative.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
</ui:repeat>
</h:panelGroup>
</h:form>

<!-- needed for selenium -->
<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,24 @@
package ee.jakarta.tck.faces.test.servlet30.ajax_selenium;


import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import org.junit.Test;

import static org.junit.Assert.assertEquals;


public class DemoTestIT extends BaseITNG {

@Test
public void test1() {
assertEquals(true, true);
}

@Test
public void runMainPage() {
int statusCode = getStatusCode("index.xhtml");
System.out.println(statusCode);
assertEquals(200, statusCode);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ee.jakarta.tck.faces.test.servlet30.ajax_selenium;

import ee.jakarta.tck.faces.test.util.selenium.BaseITNG;
import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquillianSuiteDeployment;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.spec.WebArchive;

/**
* Given Arquilian has no single deployment testsuite
* mechanism we have to rely on a third party library.
* This improves the performance in a major area
*/
@ArquillianSuiteDeployment
public class Deployments {
@Deployment(testable = false)
public static WebArchive createDeployment() {
return BaseITNG.createDeployment();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* 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_selenium;

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.assertTrue;

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");
assertTrue(page.findElement(By.id("form1:out1")).getText().equals(""));
assertTrue(page.findElement(By.id("form1:in1")).getText().equals(""));

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

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


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

/**
* @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");
assertTrue(page.findElement(By.id("form1:out1")).getText().equals(""));
assertTrue(page.findElement(By.id("form1:in1")).getText().equals(""));

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();
page.waitReqJs();


// Check that the ajax request succeeds
assertTrue(page.findElement(By.id("form1:out1")).getText().equals("var a=["));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* 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_selenium;

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 static org.junit.Assert.assertTrue;


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

/**
* @see AjaxBehavior
* @see WebElementOneRadio
* @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();
page.waitReqJs();

assertTrue(page.getPageSource().indexOf("form:vip-true") != -1);
input = page.findElement(By.id("form:vip:1"));
input.click();
page.waitReqJs();

assertTrue(page.getPageSource().indexOf("form:vip-false") != -1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* 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_selenium;

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,43 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* 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_selenium;

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 {
WebPage page = getPage("body.xhtml");
assertEquals(200, page.getResponseStatus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* 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_selenium;

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.TimeoutException;
import org.openqa.selenium.WebElement;

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

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

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();
page.waitReqJs();
String expectedText = "Triggered item: " + id[1];
WebElement body = page.findElement(By.tagName("body"));
try {

page.waitForCondition(wd -> page.isInPage(expectedText), WebPage.STD_TIMEOUT);
} catch(TimeoutException ex) {
// test failing. The text of triggered item shows now number
fail("Expected Text:" + expectedText +" not found");
}
assertTrue(page.isInPage(expectedText));
}
}
}

Loading