public void testMethodExpressionDefaults() throws Exception { HtmlPage page = getPage("/faces/composite/defaultAttributeMethodExpression.xhtml"); HtmlSubmitInput submit = (HtmlSubmitInput) getInputContainingGivenId(page, "def:form1:command"); page = submit.click(); assertTrue(page.asText().contains("Action invoked")); page = getPage("/faces/composite/defaultAttributeMethodExpression.xhtml"); submit = (HtmlSubmitInput) getInputContainingGivenId(page, "def:form2:command2"); page = submit.click(); assertTrue(page.asText().contains("ActionListener invoked")); page = getPage("/faces/composite/defaultAttributeMethodExpression.xhtml"); submit = (HtmlSubmitInput) getInputContainingGivenId(page, "def:form3:command3"); page = submit.click(); assertTrue(page.asText().contains("Custom action invoked")); page = getPage("/faces/composite/defaultAttributeMethodExpression.xhtml"); submit = (HtmlSubmitInput) getInputContainingGivenId(page, "def:form4:command"); HtmlTextInput text = (HtmlTextInput) getInputContainingGivenId(page, "def:form4:input"); text.setValueAttribute("foo"); page = submit.click(); assertTrue(page.asText().contains("validator invoked")); page = getPage("/faces/composite/defaultAttributeMethodExpression.xhtml"); submit = (HtmlSubmitInput) getInputContainingGivenId(page, "def:form5:command"); page = submit.click(); assertTrue(page.asText().contains("ValueChange invoked")); }
@Test public void testInvalidatedSession() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/invalidatedSession.xhtml"); assertTrue(page.asText().indexOf("This is from the @PostConstruct") != -1); webClient.getPage(webUrl + "faces/invalidatedPerform.xhtml"); page = webClient.getPage(webUrl + "faces/invalidatedVerify.xhtml"); assertTrue(page.asText().indexOf("true") != -1); }
public void testAlternateLifecycle() throws Exception { HtmlPage page = getPage("/alternate/test2.jsp"); assertTrue(-1 != page.asText().indexOf("beforePhase")); assertTrue(-1 != page.asText().indexOf("AlternateLifecycle")); page = getPage("/faces/test2.jsp"); assertTrue(-1 != page.asText().indexOf("beforePhase")); assertTrue(-1 != page.asText().indexOf("NewLifecycle")); }
public void testDeleteAttributes() throws Exception { String name = uniqueWikiPageName("EditPageTest"); HtmlPage edited = editWikiPage(name, "Initial Status: <<attr:status>>", "status = completed", "", true); assertTrue(edited.asText().contains("Initial Status: completed")); edited = editWikiPage(name, "Initial Status: <<attr:status>>", "", "", false); assertTrue(edited.asText().contains("Initial Status:")); assertFalse(edited.asText().contains("Initial Status: completed")); }
@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")); }
public void testCopy() throws Exception { String fromPageName = uniqueWikiPageName("CopyTestFrom"); String toPageName = uniqueWikiPageName("CopyTestTo"); editWikiPage(fromPageName, "Catchy tunes", "", "Whatever", true); HtmlPage page = getWikiPage(fromPageName); page = (HtmlPage) page.getAnchorByName("copy").click(); HtmlForm form = page.getFormByName("copyForm"); form.getInputByName("toPage").setValueAttribute(toPageName); page = (HtmlPage) form.getButtonByName("copy").click(); assertTrue( page.getWebResponse().getWebRequest().getUrl().toURI().getPath().contains(toPageName)); assertTrue(page.asText().contains("Catchy tunes")); page = getWikiPage(fromPageName); assertTrue(page.asText().contains("Catchy tunes")); }
/** 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")); }
protected Empresa getData(HtmlPage page) { StringBuffer sb = new StringBuffer(); sb.append(page.asText()); int posInit = 0; int posEnd = 0; Empresa empresa = new Empresa(); posInit = sb.indexOf(EMPRESA[0]); posEnd = (posInit > -1) ? sb.indexOf(EMPRESA[1], posInit) : -1; // NOME EMPRESA if (posInit > -1 && posEnd > -1) { empresa.setNome(sb.substring(posInit + EMPRESA[0].length(), posEnd).trim()); } posInit = sb.indexOf(CONTATO[0]); posEnd = (posInit > -1) ? sb.indexOf(CONTATO[1], posInit) : -1; if (posInit > -1 && posEnd > -1) { empresa.setContato(sb.substring(posInit + CONTATO[0].length(), posEnd).trim()); } empresa.setSite(null); empresa.setEmail(null); empresa.setLocal("MX"); System.out.println("\n### EMPRESA:" + empresa.getNome()); System.out.println("### CONTATO:" + empresa.getContato() + "\n"); return empresa; }
protected HtmlPage nextPage(HtmlPage nowPage) throws IOException { if (this.qtAnt != this.countLinks && (this.countLinks % 10) == 0) { this.qtAnt = this.countLinks; String strPage = nowPage.asText(); System.out.println("### PAGE: " + strPage); String url = HOST + NEXT_PAGE + (this.countLinks + 1); System.out.println( "####################################################################################"); System.out.println("### NEXT PAGE: " + url); HtmlPage newPage = this.getPageLink(url).getPage(); // System.out.println("### PAGE: "+newPage.asText()); System.out.println( "####################################################################################"); // System.out.println("#### ORIGINAL: " + HOST + // "bt-ofrlistado.htm?Bqd=&BqdPalabras=java&BqdComienzo=21"); // System.out.println("#### MANUAL: " + HOST + NEXT_PAGE + (this.countLinks+1)); return newPage; } else { return null; } }
/** * Tests that the details of cargo with tracking Id DEF789 can be viewed through the admin * interface. */ @Test @RunAsClient public void testViewDetailsId4() { log.log( Level.INFO, "Starting automated test to view details for Id \"" + trackingId4 + "\" through admin interface."); try { System.out.println(landingPageResponse.getUrl()); // Stores the adminDashboard as a HtmlPage object. HtmlPage adminDashboard = landingPageResponse.getElementById("adminLandingLink").click(); Assert.assertThat( "Page title was not as expected for the admin dashboard. Expected \"Cargo Dashboard\" but actual was \"" + adminDashboard.getTitleText() + "\".", adminDashboard.getTitleText(), is("Cargo Dashboard")); // Stores the details page as a HtmlPage object. HtmlPage detailsPage = adminDashboard.getAnchorByText(trackingId4).click(); Assert.assertTrue( "Expected \"Not routed\" message was not found.", detailsPage.asText().contains("Not routed")); } catch (IOException ex) { Assert.fail( "An IOException was thrown during the test for class \"" + ViewDetailTest.class.getSimpleName() + "\" at method \"" + testName.getMethodName() + "\" with message: " + ex.getMessage()); } }
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 static ArrayList<String> trans(String url) throws FailingHttpStatusCodeException, MalformedURLException, IOException { ArrayList<String> hrefList = new ArrayList<String>(); WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(false); webClient.getOptions().setCssEnabled(false); try { HtmlPage page = null; try { page = (HtmlPage) webClient.getPage(url); } catch (ConnectException e) { System.out.println("Connect fails here:" + e.getMessage()); } InputStream temp = new ByteArrayInputStream(page.asText().getBytes()); InputStreamReader isr = new InputStreamReader(temp); BufferedReader br = new BufferedReader(isr); String str = null, rs = null; while ((str = br.readLine()) != null) { rs = str; // System.out.println(rs); if (rs != null) hrefList.add(rs); } System.out.println("从该网址查找的可能相关文本如下:"); for (int i = 0; i < hrefList.size(); i++) { String string = hrefList.get(i); string = getTextFromHtml(string); if (string.length() >= 30) System.out.println("------" + i + ":" + string); } } catch (IOException e) { } return hrefList; }
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; }
@Test public void testReplaceVDL() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/replacevdl.xhtml"); String text = page.asText(); assertTrue(text.indexOf("buildView") != -1); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); text = page.asText(); assertTrue(text.indexOf("buildView") != -1); button = (HtmlSubmitInput) page.getElementById("buttonSkipBuildView"); page = button.click(); text = page.asText(); assertTrue(text.indexOf("buildView") == -1); }
/** Verify that the bean is successfully resolved */ public void testReplaceLifecycle() throws Exception { HtmlPage page = getPage("/faces/test.jsp"); String pageText = page.asText(); assertTrue(-1 != pageText.indexOf("beforePhase")); // Ensure the phaseListener is only called once. assertTrue(!pageText.matches("(?s).*beforePhase.*beforePhase.*")); }
public void testRenderFacetRequired03() throws Exception { // facet not required and not present client.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = getPage("/faces/composite/renderfacetrequired03.xhtml"); assertTrue(!page.asText().contains("Unable to find facet named 'header'")); }
/** Verify that the bean is successfully resolved */ public void testReplaceStateManager() throws Exception { HtmlPage page = getPage("/faces/test.jsp"); assertTrue(-1 != page.asText().indexOf("New String Value")); assertTrue(-1 != page.asText().indexOf("com.sun.faces.systest.NewStateManager")); assertTrue(-1 != page.asText().indexOf("com.sun.faces.systest.NewViewHandler")); assertTrue(-1 != page.asText().indexOf("com.sun.faces.systest.NewApplication")); List list; list = getAllElementsOfGivenClass(page, null, HtmlTextInput.class); ((HtmlTextInput) list.get(0)).setValueAttribute("text from client"); list = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class); HtmlSubmitInput button = (HtmlSubmitInput) list.get(0); page = (HtmlPage) button.click(); list = getAllElementsOfGivenClass(page, null, HtmlTextInput.class); assertEquals("text from client", ((HtmlTextInput) list.get(0)).asText()); }
// ------------------------------------------------------------ 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")); }
public void testCCPreRenderViewEvent() throws Exception { HtmlPage page = getPage("/faces/composite/1462-using.xhtml"); String text = page.asText(); System.out.println(text); assertTrue( text.matches( "(?s).*Message:.*Received.*event:.*javax.faces.event.PreRenderViewEvent.*for.*component:.*javax.faces.component.UIViewRoot.*")); }
// ------------------------------------------------- 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 testProgrammaticDefaultAttributeValueAccess() throws Exception { HtmlPage page = getPage("/faces/composite/programmaticDefaultAttributeValueAccess.xhtml"); String pageText = page.asText(); assertTrue(pageText.contains("attr1 value is attr1Value. attr2 value is attr2Value.")); assertTrue(pageText.contains("attr3 value is")); assertTrue(pageText.contains("action value is")); assertTrue(pageText.contains("actionListener value is")); assertTrue(pageText.contains("validator value is")); assertTrue(pageText.contains("valueChangeListener value is")); }
public void testInsertChildrenRequired03() throws Exception { // facet not required and not present client.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = getPage("/faces/composite/insertchildrenrequired03.xhtml"); assertTrue( !page.asText() .contains( "Unable to find any children components nested within parent composite component")); }
@Test public void testReplaceVDL() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue2405.xhtml"); String text = page.asText(); assertEquals(200, page.getWebResponse().getStatusCode()); assertTrue( text.indexOf( "The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>") == -1); }
private HtmlPage fetchHomePageAndClickStoryLink(int i) throws Exception { HtmlPage page = getPage("/viewParameters/page01.faces"); String pageText = page.asText(); assertOnHomePage(pageText); List<HtmlAnchor> anchors = new ArrayList<HtmlAnchor>(); this.getAllElementsOfGivenClass(page, anchors, HtmlAnchor.class); HtmlAnchor toClick = anchors.get(i); page = (HtmlPage) toClick.click(); int storyNum = i + 1; // Assert some things about the content of the page pageText = page.asText(); assertTrue(-1 != pageText.indexOf(getTitleContains(storyNum))); assertTrue(-1 != pageText.indexOf(getContentContains(storyNum))); return page; }
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; }
/** 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}")); }
/** * On SelectMany, test that the membership test works and doesn't produce spurious * ValueChangeEvent instances. */ public void testSelectManyInvalidValue() throws Exception { HtmlPage page = getPage("/faces/jsp/selectManyInvalidValue.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); Random random = new Random(4143); String str = new String((new Float(random.nextFloat())).toString()); String chosen[] = { (new Float(random.nextFloat())).toString(), (new Float(random.nextFloat())).toString() }; options.fakeSelectedAttribute(chosen); page = (HtmlPage) button.click(); ResourceBundle messages = ResourceBundle.getBundle("javax.faces.Messages"); String message = messages.getString("javax.faces.component.UISelectMany.INVALID"); // it does have a validation message assertTrue(-1 != page.asText().indexOf("Validation Error")); // it does not have a value change message assertTrue(-1 == page.asText().indexOf("value changed")); }
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; }
@Test public void testRecursive() throws Exception { /* * Make sure the added component and nested component is in the proper place. */ HtmlPage page = webClient.getPage(webUrl + "faces/recursive.xhtml"); String text = page.asText(); int first = text.indexOf("Dynamically"); int next = text.indexOf("Dynamically", first + ("Dynamically").length()); assertTrue(first < next); /** * After clicking make sure the added component and nested component is still in its proper * place. */ HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); text = page.asText(); first = text.indexOf("Dynamically"); next = text.indexOf("Dynamically", first + ("Dynamically").length()); assertTrue(first < next); }
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; }