/** Verify that the required validator works for SelectOne */ public void testSelectOneNoValue() throws Exception { HtmlPage page = getPage("/faces/jsp/selectOneNoValue.jsp"); List list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class); HtmlSubmitInput button = (HtmlSubmitInput) list.get(0); page = (HtmlPage) button.click(); assertTrue(-1 != page.asText().indexOf("equired")); }
public static HtmlPage trainStrength(HtmlPage page, int amount) throws IOException { System.out.println("Training " + amount + " strength..."); for (DomNode n : page.getElementById("divStrength").getDescendants()) { // System.out.println(n.toString()); HtmlTextInput textInput; HtmlSubmitInput submitInput; if (n.toString() .contains("HtmlTextInput[<input type=\"text\" value=\"1\" id=\"t\" name=\"t\">]")) { textInput = (HtmlTextInput) n; textInput.setValueAttribute(Integer.toString(amount)); System.out.println(textInput.toString()); } else if (n.toString() .contains("HtmlSubmitInput[<input type=\"submit\" value=\"Train\">]")) { submitInput = (HtmlSubmitInput) n; page = submitInput.click(); System.out.println(submitInput.toString()); } } /* System.out.println(this.user.getUsername()+"-"+"Training "+amount+" strength..."); HtmlTextInput amountInput = (HtmlTextInput) page.getByXPath("/html/body/div[4]/table/tbody/tr/td[2]/center/div[2]/div/div[2]/div[3]/div[1]/div[1]/div[2]/form/table/tbody/tr/td[1]/input[1]").get(0); amountInput.setValueAttribute(Integer.toString(amount)); HtmlElement e = (HtmlElement) page.getByXPath("/html/body/div[4]/table/tbody/tr/td[2]/center/div[2]/div/div[2]/div[3]/div[1]/div[1]/div[2]/form/table/tbody/tr/td[3]/input").get(0); e.click(); */ System.out.println(page.asText()); return page; }
public void testAjaxTagEvent() throws Exception { getPage("/faces/ajax/ajaxTagEvent.xhtml"); System.out.println("Start ajax tag event test"); // First we'll check the first page was output correctly checkTrue("countForm:out1", "0"); checkTrue("out2", "1"); // Submit the ajax request HtmlSubmitInput button1 = (HtmlSubmitInput) lastpage.getHtmlElementById("countForm:button1"); lastpage = (HtmlPage) button1.click(); // Check that the ajax request succeeds checkTrue("countForm:out1", "2"); // Check that the request did NOT update the rest of the page. checkTrue("out2", "1"); HtmlSubmitInput error = (HtmlSubmitInput) lastpage.getHtmlElementById("countForm:error"); lastpage = (HtmlPage) error.click(); // Check that events were written to the page. String statusArea = "Name: countForm:button1 Event: begin "; statusArea = statusArea + "Name: countForm:button1 Event: complete "; statusArea = statusArea + "Name: countForm:button1 Event: success "; statusArea = statusArea + "Name: countForm:error Event: begin "; statusArea = statusArea + "Name: countForm:error Event: complete "; statusArea = statusArea + "Name: countForm:error Event: success "; // System.out.println(statusArea); // System.out.println(getText("statusArea"); checkTrue("statusArea", statusArea); }
public void testCompositeInsertChildrenNested() throws Exception { HtmlPage page = getPage("/faces/composite/compositeInsertChildrenNesting.xhtml"); List<HtmlSpan> spans = new ArrayList<HtmlSpan>(); getAllElementsOfGivenClass(page, spans, HtmlSpan.class); String[] expectedItems = { "Before Insert A(1)", "Before Nested compcomp (3)", "Before Insert B(1)", "Inside nested Component (4)", "After Insert B(2)", "After Nested compcomp(5)", "After Insert A(2)" }; assertTrue(spans.size() == expectedItems.length); for (int i = 0, len = expectedItems.length; i < len; i++) { assertTrue(expectedItems[i].equals(spans.get(i).asText())); } HtmlSubmitInput input = (HtmlSubmitInput) getInputContainingGivenId(page, "form:submit"); assertNotNull(input); page = input.click(); spans = new ArrayList<HtmlSpan>(); getAllElementsOfGivenClass(page, spans, HtmlSpan.class); assertTrue(spans.size() == expectedItems.length); for (int i = 0, len = expectedItems.length; i < len; i++) { assertTrue(expectedItems[i].equals(spans.get(i).asText())); } }
@Test public void testStable() throws Exception { String inputValue1 = "value=" + '"' + "1" + '"'; String inputValue2 = "value=" + '"' + "2" + '"'; String idText3 = "id=" + '"' + "text3" + '"'; /* * Make sure the three dynamically added input components are in their proper place. */ HtmlPage page = webClient.getPage(webUrl + "faces/stable.xhtml"); assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(inputValue1)); assertTrue(page.asXml().indexOf(inputValue1) < page.asXml().indexOf(inputValue2)); assertTrue(page.asXml().indexOf(inputValue2) < page.asXml().indexOf(idText3)); assertTrue(page.asXml().indexOf("text3") < page.asXml().indexOf("encodeEnd")); /** * After clicking make sure the added component is still in its proper place. Also verify the * validation required error message appears as the third input component has required attribute * set to true. */ HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); assertTrue(page.asXml().contains("text3: Validation Error: Value is required.")); assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(inputValue1)); assertTrue(page.asXml().indexOf(inputValue1) < page.asXml().indexOf(inputValue2)); assertTrue(page.asXml().indexOf(inputValue2) < page.asXml().indexOf(idText3)); assertTrue(page.asXml().indexOf("text3") < page.asXml().indexOf("encodeEnd")); }
// ------------------------------------------------- Individual Test Methods public void testConverter() throws Exception { HtmlPage page = getPage("/faces/converter03.jsp"); List list; list = getAllElementsOfGivenClass(page, null, HtmlTextInput.class); // set the initial value to be 1 for all input fields ((HtmlTextInput) list.get(0)).setValueAttribute("1111111111"); ((HtmlTextInput) list.get(1)).setValueAttribute("1111111111"); ((HtmlTextInput) list.get(2)).setValueAttribute("1111111111"); ((HtmlTextInput) list.get(3)).setValueAttribute("1111111111"); ((HtmlTextInput) list.get(4)).setValueAttribute("99"); ((HtmlTextInput) list.get(5)).setValueAttribute("4"); ((HtmlTextInput) list.get(6)).setValueAttribute("12"); ((HtmlTextInput) list.get(7)).setValueAttribute("7"); ((HtmlTextInput) list.get(8)).setValueAttribute("10"); list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class); HtmlSubmitInput button = (HtmlSubmitInput) list.get(0); page = (HtmlPage) button.click(); assertTrue(-1 != page.asText().indexOf("text1 was converted to Object")); assertTrue(-1 != page.asText().indexOf("text1 was converted to String")); assertTrue(-1 != page.asText().indexOf("text2 was converted to Object")); assertTrue(-1 != page.asText().indexOf("text2 was converted to String")); assertTrue(-1 != page.asText().indexOf("text3 was converted to Object")); assertTrue(-1 != page.asText().indexOf("text3 was converted to String")); assertTrue(-1 != page.asText().indexOf("text4 was converted to Object")); assertTrue(-1 != page.asText().indexOf("text4 was converted to String")); assertTrue( -1 != page.asText().indexOf("text5: '99' could not be understood as a time. Example:")); assertTrue(-1 != page.asText().indexOf("4.0")); assertTrue(-1 != page.asText().indexOf("12.0")); assertTrue(-1 != page.asText().indexOf("7.0")); assertTrue(-1 != page.asText().indexOf("10")); }
public void testValidators() throws Exception { try { getPage( "/faces/setApplicationMapProperty.xhtml?name=javax.faces.VALIDATE_EMPTY_FIELDS&value=true"); HtmlPage page = getPage("/faces/composite/validator.xhtml"); HtmlSubmitInput submit = (HtmlSubmitInput) getInputContainingGivenId(page, "form:submit"); assertNotNull(submit); page = submit.click(); final String[] inputIds = { "form:c0:input", "form:c1:nesting:aw1:input", "form:c2:nesting:aw2:input", "form:c3:nesting:aw3:nesting:aw1:input", "form:c4:nesting:aw4:nesting:aw1:input" }; String pageText = page.asText(); for (String inputId : inputIds) { String message = "validator invoked: " + inputId; assertTrue(pageText.contains(message)); } } finally { getPage("/faces/clearApplicationMapProperty.xhtml?name=javax.faces.VALIDATE_EMPTY_FIELDS"); } }
public void testNesting03() throws Exception { HtmlPage page = getPage("/faces/composite/nesting03.xhtml"); HtmlSubmitInput input = (HtmlSubmitInput) getInputContainingGivenId(page, "commandButton"); assertNotNull(input); page = input.click(); assertEquals("Navigation Result", page.getTitleText()); }
// ------------------------------------------------------------ Test Methods public void testNoViewParamsWithJsp() throws Exception { HtmlPage page = getPage("/faces/view1.jsp"); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form:refreshWithRedirectParams"); page = button.click(); assertTrue(page.asText().contains("PAGE 2 OUTPUT")); }
/** * This test verifies that an attribute nameed 'value' can be successfully updated from a partial * response (over Ajax). */ @Test public void testScript() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/script.xhtml"); assertTrue(page.asXml().contains("SCRIPT EXECUTED!")); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button1"); page = button.click(); assertTrue(page.asXml().contains("SCRIPT EXECUTED!")); }
@Test public void testRowRemoved() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/repeatRemoved.xhtml"); assertNotNull(page.getHtmlElementById("f:r:0:i")); HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("f:r:0:b"); page = button.click(); assertNull(page.getElementById("f:r:0:i")); }
/** * Cancel changes made by clicking the cancel button * * @return {@link AlbumListPage} */ public AlbumListPage cancelChanges() { HtmlSubmitInput cancelButton = (HtmlSubmitInput) page.getElementById("cancelButton"); try { cancelButton.click(); } catch (IOException e) { e.printStackTrace(); } return new AlbumListPage(webClient); }
@Test public void testConverterInstallation() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue1660.xhtml"); assertTrue(page.asXml().matches("(?s).*Simple\\s+value\\s+is\\s+VALUE1.*")); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); assertTrue(page.asXml().matches("(?s).*Simple\\s+value\\s+is\\s+VALUE1.*")); }
/** * Saves changes made by clicking the save button * * @return {@link AlbumPage} */ public AlbumPage saveChanges() { HtmlSubmitInput saveButton = (HtmlSubmitInput) page.getElementById("saveButton"); try { saveButton.click(); } catch (IOException e) { e.printStackTrace(); } return this; }
@Override protected String getCallbackUrlForCancel(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlSubmitInput submit = form.getInputByValue("Cancel"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
/** * Added for issue 212. Ensure no exception when restoring state containing transient components. * * @throws Exception */ public void testComponentTransienceRestoration() throws Exception { HtmlPage page = getPage("/faces/component02.jsp"); HtmlSubmitInput submit = (HtmlSubmitInput) getInputContainingGivenId(page, "submit"); try { submit.click(); } catch (Exception ioe) { fail("No exception should have been thrown: " + ioe.getMessage()); } }
@Test public void testIssue1825() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue1825.xhtml"); HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("form:button"); page = button.click(); assertEquals(200, page.getWebResponse().getStatusCode()); button = (HtmlSubmitInput) page.getHtmlElementById("form:button"); page = button.click(); assertEquals(200, page.getWebResponse().getStatusCode()); }
private HtmlPage doRefreshWithRedirectParamsButton(HtmlPage page, int storyNum) throws Exception { // click the "refreshWithRedirectParams" button and make sure we're still // on the same page. HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("refreshWithRedirectParams"); page = (HtmlPage) button.click(); String pageText = page.asText(); assertTrue(-1 != pageText.indexOf(getTitleContains(storyNum))); assertTrue(-1 != pageText.indexOf(getContentContains(storyNum))); return page; }
public void testAjaxTagKeywords() throws Exception { getPage("/faces/ajax/ajaxTagKeywords.xhtml"); System.out.println("Start ajax tag Keyword test"); checkTrue("out1", "0"); checkTrue("out2", "1"); checkTrue("button3", "2"); checkTrue("out3", "3"); // Submit the ajax request HtmlSubmitInput button1 = (HtmlSubmitInput) lastpage.getHtmlElementById("button1"); lastpage = (HtmlPage) button1.click(); checkTrue("out1", "4"); checkTrue("out2", "5"); checkTrue("button3", "6"); checkTrue("out3", "7"); // Submit the ajax request HtmlSubmitInput button2 = (HtmlSubmitInput) lastpage.getHtmlElementById("button2"); lastpage = (HtmlPage) button2.click(); checkTrue("out1", "8"); checkTrue("out2", "9"); checkTrue("button3", "10"); checkTrue("out3", "7"); // Submit the ajax request HtmlSubmitInput button3 = (HtmlSubmitInput) lastpage.getHtmlElementById("button3"); lastpage = (HtmlPage) button3.click(); checkTrue("out1", "8"); checkTrue("out2", "9"); checkTrue("button3", "11"); checkTrue("out3", "7"); // Submit the ajax request HtmlSubmitInput button4 = (HtmlSubmitInput) lastpage.getHtmlElementById("button4"); lastpage = (HtmlPage) button4.click(); checkTrue("out1", "8"); checkTrue("out2", "9"); checkTrue("button3", "11"); checkTrue("out3", "7"); // Submit the ajax request HtmlSubmitInput button5 = (HtmlSubmitInput) lastpage.getHtmlElementById("button5"); lastpage = (HtmlPage) button5.click(); checkTrue("out1", "8"); checkTrue("out2", "12"); checkTrue("button3", "11"); checkTrue("out3", "7"); }
/** * Test to validate empty fields. * * <p>Note: this test is excluded on Tomcat because the included EL parser requires a System * property for this test to work, which would cause problems with other tests. See * http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html and look for COERCE_TO_ZERO */ @Test public void testValidateEmptyFields() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/index.xhtml"); if (page.getWebResponse().getResponseHeaderValue("Server") == null || !page.getWebResponse().getResponseHeaderValue("Server").startsWith("Apache-Coyote")) { page = webClient.getPage(webUrl + "faces/validateEmptyFields.xhtml"); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form:submitButton"); page = button.click(); assertTrue(page.asXml().contains("We got called!")); } }
/** * This test verifies that an attribute named 'readonly' can be successfully updated from a * partial response (over Ajax). */ @Test public void testUpdateAttributeNamedReadonly() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/attributeNameIsReadonly.xhtml"); HtmlTextInput input = (HtmlTextInput) page.getElementById("form1:foo"); assertTrue(input.isReadOnly() == false); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button"); page = button.click(); webClient.waitForBackgroundJavaScript(60000); input = (HtmlTextInput) page.getElementById("form1:foo"); assertTrue(input.isReadOnly() == true); }
/** Verify that the conversion error works for SelectMany */ public void testSelectManyMismatchValue() throws Exception { HtmlPage page = getPage("/faces/jsp/selectManyMismatchValue.jsp"); List list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class); HtmlSubmitInput button = (HtmlSubmitInput) list.get(0); list = getAllElementsOfGivenClass(page, null, HtmlSelect.class); HtmlSelect options = (HtmlSelect) list.get(0); String chosen[] = {"one", "three"}; options.fakeSelectedAttribute(chosen); page = (HtmlPage) button.click(); assertTrue(-1 != page.asText().indexOf("one three")); assertTrue(-1 != page.asText().indexOf("#{test3.selection}")); }
@JsfTest(value = JSF_2_2_0) @Test public void testViewScopedLogging() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/viewScoped01.xhtml"); HtmlElement e = (HtmlElement) page.getElementById("initMessage"); long flowInitTime = Long.valueOf(e.asText()); HtmlSubmitInput returnButton = (HtmlSubmitInput) page.getElementById("viewScoped02"); page = returnButton.click(); e = (HtmlElement) page.getElementById("destroyMessage"); long flowDestroyTime = Long.valueOf(e.asText()); assertTrue(flowInitTime < flowDestroyTime); }
private HtmlPage doRefreshButton(HtmlPage page, int storyNum) throws Exception { String pageText = null; // Click the "refresh" button, ensure the page refreshes properly HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("refresh"); page = (HtmlPage) button.click(); pageText = page.asText(); assertTrue(-1 != pageText.indexOf(getTitleContains(storyNum))); assertTrue(-1 != pageText.indexOf(getContentContains(storyNum))); return page; }
@JsfTest(value = JSF_2_2_0) @Test public void testSessionLogging() throws Exception { HtmlPage page = webClient.getPage(webUrl); HtmlElement e = (HtmlElement) page.getElementById("initMessage"); long sessionInitTime = Long.valueOf(e.asText()); HtmlSubmitInput invalidateButton = (HtmlSubmitInput) page.getElementById("invalidateSession"); page = invalidateButton.click(); e = (HtmlElement) page.getElementById("destroyMessage"); long sessionDestroyTime = Long.valueOf(e.asText()); assertTrue(sessionInitTime < sessionDestroyTime); }
/** * This test verifies that an attribute named 'checked' can be successfully updated from a partial * response (over Ajax). */ @Test public void testUpdateAttributeNamedChecked() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/attributeNameIsChecked.xhtml"); HtmlCheckBoxInput cbox = (HtmlCheckBoxInput) page.getElementById("form1:foo"); assertTrue(cbox.isChecked() == false); assertTrue(page.asXml().contains("foo")); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button"); page = button.click(); webClient.waitForBackgroundJavaScript(60000); cbox = (HtmlCheckBoxInput) page.getElementById("form1:foo"); assertTrue(cbox.isChecked() == true); }
// Submit the form with no modifications public void testFormInput02_submit01() throws Exception { checkFormInput00(); HtmlPage page = getFormInput02(); checkFormInput02(page, formInput02_pristine); HtmlForm form = getFormById(page, formInput02_name); assertNotNull("form exists", form); HtmlSubmitInput submit = (HtmlSubmitInput) form.getInputByName(formInput02_name + NamingContainer.SEPARATOR_CHAR + "submit"); page = (HtmlPage) submit.click(); checkFormInput02(page, formInput02_pristine); }
private HtmlPage doHomeKeepSelectionButton(HtmlPage page, int storyNum) throws Exception { String pageText = null; // Click the "homeKeepSelection" button, ensure you get back // to the home page with the proper story number HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("homeRememberSelection"); page = (HtmlPage) button.click(); pageText = page.asText(); assertOnHomePage(pageText); assertTrue(-1 == pageText.indexOf("You just looked at story #" + storyNum + ".")); return page; }
private HtmlPage clickButtonReturnPage(Object tempsubmit) throws IOException { HtmlSubmitInput htmlsubmit; HtmlButton htmlbutton; // a = ""; if (tempsubmit.getClass().getName().contains("HtmlButton")) { htmlbutton = (HtmlButton) tempsubmit; return htmlbutton.click(); // .getWebResponse().getContentAsString(); } else if (tempsubmit.getClass().getName().contains("HtmlSubmitInput")) { htmlsubmit = (HtmlSubmitInput) tempsubmit; return htmlsubmit.click(); // .getWebResponse().getContentAsString(); } return null; }
@Test public void testAjaxViewScope() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue2754.xhtml"); HtmlTextInput input = (HtmlTextInput) page.getHtmlElementById("input"); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); webClient.waitForBackgroundJavaScript(60000); assertTrue(page.asText().contains("input: Validation Error: Value is required")); input.type("hello"); webClient.waitForBackgroundJavaScript(60000); page = button.click(); webClient.waitForBackgroundJavaScript(60000); assertTrue(!page.asText().contains("input: Validation Error: Value is required")); }