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; }