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 login() throws Exception { final HtmlPage loginPage = webClient.getPage(BASEURI); final HtmlForm form = loginPage.getForms().get(0); final HtmlTextInput userTextField = form.getInputByName("jsecLogin"); final HtmlPasswordInput passwordTextField = form.getInputByName("jsecPassword"); final HtmlSubmitInput button = form.getInputByName("login"); // Change the value of the text field userTextField.setValueAttribute("admin"); passwordTextField.setValueAttribute("admin"); HtmlPage homePage = null; try { homePage = button.click(); } catch (Exception e) { logger.error("error submitting", e); } Assert.assertEquals(homePage.getTitleText(), "Tynamo!"); webClient.closeAllWindows(); }
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 static HtmlPage solveCaptcha(HtmlPage page) throws Exception { System.out.println("Solving captcha..."); String url = page.getUrl().toString(); page = wc.getPage(url + "?bypass=1"); HtmlImage captchaImage = (HtmlImage) page.getElementById("recaptcha_image").getFirstChild(); captchaImage.saveAs(new File("captcha-image.jpg")); CaptchaSolver captchaSolver = new CaptchaSolver(new SocketClient("trialaccount", "Cappie1!"), "captcha-image.jpg"); captchaSolver.run(); Captcha captcha = captchaSolver.getCaptcha(); HtmlTextInput textField = (HtmlTextInput) page.getElementById("recaptcha_response_field"); textField.setValueAttribute(captcha.text); HtmlElement element = (HtmlElement) page.getElementByName("submit"); page = element.click(); System.out.println("Captcha entered."); return wc.getPage(url); }
public static HtmlPage login(HtmlPage page, String username, String password) { int attempts = 0; boolean loggedIn = false; while (!loggedIn) { try { if (attempts > 3) System.exit(1); attempts++; System.out.println("Logging in... (Attempt " + attempts + ")"); page = wc.getPage("http://torn.com/login"); final HtmlForm form = page.getFormByName("login"); HtmlSubmitInput button = form.getInputByName("btnLogin"); HtmlTextInput textField = form.getInputByName("player"); // Change the value of the text field textField.setValueAttribute(username); final HtmlPasswordInput passwordField = form.getInputByName("password"); // Change the value of the text field passwordField.setValueAttribute(password); // Now submit the form by clicking the button and get back the second page. page = button.click(); page = wc.getPage("http://torn.com/index.php"); loggedIn = true; } catch (Exception e) { System.out.println(e.toString()); loggedIn = false; } } return page; }
public void testAjaxTagDefaultsEditNoPrepend() throws Exception { System.out.println("Starting Tag Defaults Edit No Prepend Test"); getPage("/faces/ajax/ajaxTagDefaultsEditNoPrepend.xhtml"); String out1 = "out1"; String out2 = "out2"; String out3 = "out3"; String echo1Out = "echo1Out"; String echo2Out = "echo2Out"; String echo3Out = "echo3Out"; String echo4Out = "echo4Out"; String edit1 = "edit1"; String edit2 = "edit2"; String edit3 = "edit3"; String edit4 = "edit4"; String refresh = "refresh"; // First, we'll test to make sure the initial values come out right checkTrue(out1, "echo"); checkTrue(out2, "echo"); checkTrue(out3, "echo"); checkTrue(echo1Out, ""); checkTrue(echo2Out, ""); checkTrue(echo3Out, ""); checkTrue(echo4Out, ""); // Next, enter data into first field HtmlTextInput echo1 = ((HtmlTextInput) lastpage.getHtmlElementById(edit1)); echo1.focus(); echo1.type("test1"); echo1.blur(); // Refresh the panel to check the listener fired HtmlSubmitInput button = lastpage.getHtmlElementById(refresh); button.click(); checkTrue(echo1Out, "test1"); checkTrue(out1, "test1"); checkTrue(out2, "echo"); checkTrue(out3, "echo"); // Next, enter data into second field HtmlTextInput echo2 = ((HtmlTextInput) lastpage.getHtmlElementById(edit2)); echo2.focus(); echo2.type("test2"); echo2.blur(); // Refresh the panel to check the listener fired button = lastpage.getHtmlElementById(refresh); button.click(); checkTrue(echo2Out, "test2"); checkTrue(out1, "test2"); checkTrue(out2, "echo"); checkTrue(out3, "echo"); // Next, enter data into third field HtmlTextInput echo3 = ((HtmlTextInput) lastpage.getHtmlElementById(edit3)); echo3.focus(); echo3.type("test3"); echo3.blur(); // Refresh the panel to check the listener fired button = lastpage.getHtmlElementById(refresh); button.click(); checkTrue(echo3Out, "test3"); checkTrue(out1, "test3"); checkTrue(out2, "echo"); checkTrue(out3, "echo"); // Next, enter data into the fourth field HtmlTextInput echo4 = ((HtmlTextInput) lastpage.getHtmlElementById(edit4)); echo4.focus(); echo4.type("test4"); echo4.blur(); // Refresh the panel to check the listener fired button = lastpage.getHtmlElementById(refresh); button.click(); checkTrue(echo4Out, "test4"); checkTrue(out1, "test4"); checkTrue(out2, "echo"); checkTrue(out3, "echo"); }