Ejemplo n.º 1
0
  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"));
  }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
  @Override
  protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception {
    HtmlForm form = authorizationPage.getFormByName("loginform");
    final HtmlTextInput login = form.getInputByName("log");
    login.setValueAttribute("testscribeup");
    final HtmlPasswordInput passwd = form.getInputByName("pwd");
    passwd.setValueAttribute("testpwdscribeup");

    HtmlElement button = (HtmlElement) authorizationPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // HtmlButton button = form.getButtonByName("wp-submit");

    final HtmlPage confirmPage = button.click();
    form = confirmPage.getFormByName("loginform");

    button = (HtmlElement) confirmPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // button = form.getButtonByName("wp-submit");

    final HtmlPage callbackPage = button.click();
    final String callbackUrl = callbackPage.getUrl().toString();
    logger.debug("callbackUrl : {}", callbackUrl);
    return callbackUrl;
  }
  @Test
  public void testConfigurationAuthentication() throws Exception {
    prepareSecurity();

    FreeStyleProject p = j.createFreeStyleProject();

    WebClient wc = j.createWebClient();
    wc.login("test1");

    // Reauthentication is not required if No need for re-authentication is checked
    p.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", true)));
    j.submit(wc.getPage(p, "configure").getFormByName("config"));

    // Reauthentication is required if No need for re-authentication is checked
    p.removeProperty(AuthorizeProjectProperty.class);
    p.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", false)));
    try {
      j.submit(wc.getPage(p, "configure").getFormByName("config"));
      fail();
    } catch (FailingHttpStatusCodeException e) {
      assertEquals(400, e.getStatusCode());
    }

    // No authentication is required if oneself.
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlTextInput userid =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'userid') and @type='text']");
      userid.setValueAttribute("test1");
      j.submit(page.getFormByName("config"));

      assertEquals(
          "test1",
          ((SpecificUsersAuthorizationStrategy)
                  p.getProperty(AuthorizeProjectProperty.class).getStrategy())
              .getUserid());
    }

    // Reauthentication is required to change userid even if No need for re-authentication is
    // checked
    p.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", true)));
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlTextInput userid =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'userid') and @type='text']");
      userid.setValueAttribute("test2");
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }
  }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 @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"));
 }
Ejemplo n.º 7
0
  // Check the values of the input fields against the specified list
  private void checkJstlForEach01(HtmlPage page, String expected[]) {

    assertEquals("Correct page title", "jstl-foreach-01", page.getTitleText());
    HtmlForm form = getFormById(page, jstlForEach01_name);
    assertNotNull("form exists", form);
    for (int i = 0; i < expected.length; i++) {
      HtmlTextInput input =
          (HtmlTextInput)
              form.getInputByName(
                  jstlForEach01_name + NamingContainer.SEPARATOR_CHAR + jstlForEach01_names[i]);
      assertNotNull("field '" + jstlForEach01_names[i] + "' exists", input);
      assertEquals(
          "field '" + jstlForEach01_names[i] + "' value", expected[i], input.getValueAttribute());
    }
  }
Ejemplo n.º 8
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginValid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("*****@*****.**");
    textPassword.setValueAttribute("malczyk123");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.getTitleText().equals("Taskflow-Main"));

    webClient.closeAllWindows();
  }
Ejemplo n.º 9
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginInvalid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("invalidLogin");
    textPassword.setValueAttribute("invalidPasswd");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.asText().contains("Błędny login bądź hasło"));

    webClient.closeAllWindows();
  }
Ejemplo n.º 10
0
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   webClient.waitForBackgroundJavaScript(5000);
   HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlTextInput login = form.getInputByName("login_email");
   login.setValueAttribute("*****@*****.**");
   final HtmlPasswordInput passwd = form.getInputByName("login_password");
   passwd.setValueAttribute("testpwdscribeup");
   HtmlButton submit = form.getButtonByName("");
   HtmlPage confirmPage = submit.click();
   confirmPage = (HtmlPage) confirmPage.refresh();
   webClient.waitForBackgroundJavaScript(5000);
   form = confirmPage.getForms().get(0);
   HtmlButton submit2 = form.getButtonByName("allow_access");
   final HtmlPage callbackPage = submit2.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
Ejemplo n.º 11
0
  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);
  }
Ejemplo n.º 12
0
  @JsfTest(JsfVersion.JSF_2_2_5)
  @Test
  public void testDropFlashCookie() throws Exception {

    HtmlPage page = webClient.getPage(webUrl + "faces/flashDropCookie.xhtml");
    webClient.getOptions().setRedirectEnabled(true);
    HtmlTextInput textInput = (HtmlTextInput) page.getHtmlElementById("input");
    textInput.setValueAttribute("test");
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("submit");

    int currentSize = webClient.getCookieManager().getCookies().size();

    page = button.click();
    HtmlElement element = page.getHtmlElementById("link");
    page = element.click();

    int newSize = webClient.getCookieManager().getCookies().size();

    assertTrue(newSize < currentSize);
  }
Ejemplo n.º 13
0
  // Submit the form with updates to every field
  public void testFormInput02_submit02() throws Exception {

    checkFormInput00();
    HtmlPage page = getFormInput02();
    checkFormInput02(page, formInput02_pristine);
    HtmlForm form = getFormById(page, formInput02_name);
    assertNotNull("form exists", form);
    for (int i = 0; i < formInput02_names.length; i++) {
      HtmlTextInput input =
          (HtmlTextInput)
              form.getInputByName(
                  formInput02_name + NamingContainer.SEPARATOR_CHAR + formInput02_names[i]);
      assertNotNull("field '" + formInput02_names[i] + "' exists", input);
      input.setValueAttribute(formInput02_updated[i]);
    }
    HtmlSubmitInput submit =
        (HtmlSubmitInput)
            form.getInputByName(formInput02_name + NamingContainer.SEPARATOR_CHAR + "submit");
    page = (HtmlPage) submit.click();
    checkFormInput02(page, formInput02_updated);
    checkFormInput01();
  }
Ejemplo n.º 14
0
  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;
  }
Ejemplo n.º 15
0
 @Test
 public void testConfigurationEffective() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/spec566.xhtml");
   HtmlTextInput input1 = (HtmlTextInput) page.getHtmlElementById("input1");
   input1.setTextContent("3");
   HtmlTextInput input2 = (HtmlTextInput) page.getHtmlElementById("input2");
   input2.setTextContent("4");
   HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("reload");
   page = button.click();
   input1 = (HtmlTextInput) page.getHtmlElementById("input1");
   input1.setValueAttribute("");
   input2 = (HtmlTextInput) page.getHtmlElementById("input2");
   input2.setValueAttribute("abcd");
   button = (HtmlSubmitInput) page.getHtmlElementById("reload");
   page = button.click();
   HtmlElement message1 = page.getHtmlElementById("input1Message");
   assertTrue(!message1.getTextContent().contains("input1:"));
   HtmlElement message2 = page.getHtmlElementById("input2Message");
   assertTrue(message2.getTextContent().contains("input2:"));
   input1 = (HtmlTextInput) page.getElementById("input1");
   assertEquals(0, input1.getTextContent().length());
   input2 = (HtmlTextInput) page.getElementById("input2");
   assertEquals("abcd", input2.getValueAttribute());
 }
Ejemplo n.º 16
0
  @Test
  public void parameterTypes() throws Exception {
    FreeStyleProject otherProject = j.createFreeStyleProject();
    otherProject.scheduleBuild2(0).get();

    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdp =
        new ParametersDefinitionProperty(
            new StringParameterDefinition("string", "defaultValue", "string description"),
            new BooleanParameterDefinition("boolean", true, "boolean description"),
            new ChoiceParameterDefinition("choice", "Choice 1\nChoice 2", "choice description"),
            new RunParameterDefinition("run", otherProject.getName(), "run description", null));
    project.addProperty(pdp);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);

    WebClient wc = j.createWebClient();
    wc.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec");

    HtmlForm form = page.getFormByName("parameters");

    HtmlElement element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='string']");
    assertNotNull(element);
    assertEquals(
        "string description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());

    HtmlTextInput stringParameterInput =
        (HtmlTextInput) element.selectSingleNode(".//input[@name='value']");
    assertEquals("defaultValue", stringParameterInput.getAttribute("value"));
    assertEquals(
        "string",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
    stringParameterInput.setAttribute("value", "newValue");

    element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='boolean']");
    assertNotNull(element);
    assertEquals(
        "boolean description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    Object o = element.selectSingleNode(".//input[@name='value']");
    System.out.println(o);
    HtmlCheckBoxInput booleanParameterInput = (HtmlCheckBoxInput) o;
    assertEquals(true, booleanParameterInput.isChecked());
    assertEquals(
        "boolean",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());

    element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']");
    assertNotNull(element);
    assertEquals(
        "choice description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    assertEquals(
        "choice",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());

    element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='run']");
    assertNotNull(element);
    assertEquals(
        "run description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    assertEquals(
        "run",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());

    j.submit(form);
    Queue.Item q = j.jenkins.getQueue().getItem(project);
    if (q != null) q.getFuture().get();
    else Thread.sleep(1000);

    assertEquals("newValue", builder.getEnvVars().get("STRING"));
    assertEquals("true", builder.getEnvVars().get("BOOLEAN"));
    assertEquals("Choice 1", builder.getEnvVars().get("CHOICE"));
    assertEquals(
        j.jenkins.getRootUrl() + otherProject.getLastBuild().getUrl(),
        builder.getEnvVars().get("RUN"));
  }
Ejemplo n.º 17
0
 /**
  * Sets the artist input text field
  *
  * @param artist the new artist value to set
  * @return {@link AlbumPage}
  */
 public AlbumPage changeArtist(String artist) {
   HtmlTextInput artistInputTextField = (HtmlTextInput) page.getElementById("albumArtist");
   artistInputTextField.setText(artist);
   return this;
 }
Ejemplo n.º 18
0
 /**
  * Sets the album title input text field
  *
  * @param albumTitle the new album title value to set
  * @return {@link AlbumPage}
  */
 public AlbumPage changeAlbumTitle(String albumTitle) {
   HtmlTextInput albumTitleInputTextField = (HtmlTextInput) page.getElementById("albumTitle");
   albumTitleInputTextField.setText(albumTitle);
   return this;
 }
Ejemplo n.º 19
0
 /**
  * Sets the album rating input text field
  *
  * @param albumRating the new album rating value to set
  * @return {@link AlbumPage}
  */
 public AlbumPage changeAlbumRating(String albumRating) {
   HtmlTextInput albumRatingInputTextField = (HtmlTextInput) page.getElementById("albumRating");
   albumRatingInputTextField.setText(albumRating);
   return this;
 }
Ejemplo n.º 20
0
  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");
  }
  @Test
  public void testConfigureApitoken() throws Exception {
    prepareSecurity();

    FreeStyleProject p = j.createFreeStyleProject();
    p.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("test2", false)));

    WebClient wc = j.createWebClient();
    wc.login("test1");

    String apitokenForTest2 = User.get("test2").getProperty(ApiTokenProperty.class).getApiToken();
    assertNotNull(apitokenForTest2);
    assertNotEquals("", apitokenForTest2);

    // authentication fails without apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }

    // authentication succeeds with the good apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2);
      j.submit(page.getFormByName("config"));

      assertEquals(
          "test2",
          ((SpecificUsersAuthorizationStrategy)
                  p.getProperty(AuthorizeProjectProperty.class).getStrategy())
              .getUserid());
    }

    // authentication fails with a bad apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2 + "xxx");
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }

    // authentication fails if the apitoken is used for password
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(false);
      HtmlPasswordInput password =
          page.<HtmlPasswordInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'password') and @type='password']");
      password.setValueAttribute(apitokenForTest2);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2);
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }
  }
Ejemplo n.º 22
0
  @JsfTest(
      value = JSF_2_2_0_M02,
      excludes = {WEBLOGIC_12_1_4})
  @Test
  public void testFlash() throws Exception {
    // Get the first page
    HtmlPage page = webClient.getPage(webUrl + "faces/index.xhtml");
    String pageText = page.asXml();
    // (?s) is an "embedded flag expression" for the "DOTALL" operator.
    // It says, "let . match any character including line terminators."
    // Because page.asXml() returns a big string with lots of \r\n chars
    // in it, we need (?s).
    // the page contains a table tag with a frame attribute whose value is hsides.

    // the page contains the following span, with the following id, with no contents
    assertTrue(pageText.matches("(?s)(?m).*<span.*id=\"fooValueId\">\\s*</span>.*"));

    // Click the reload button
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("reload");
    page = (HtmlPage) button.click();
    pageText = page.asXml();
    // verify that fooValue is there, indicating that it's been stored in the flash
    assertTrue(pageText.matches("(?s)(?m).*<span.*id=\"fooValueId\">\\s*fooValue\\s*</span>.*"));

    // Get the first page, again
    page = webClient.getPage(webUrl + "faces/index.xhtml");

    // the page contains the following span, with the following id, with no contents
    // meaning the flash has no value for foo
    // assertTrue(pageText.matches("(?s)(?m).*<span.*id=\"fooValueId\">\\s*</span>.*"));
    // fill in "addMessage" in the textBox
    HtmlTextInput text = (HtmlTextInput) page.getHtmlElementById("inputText");
    text.setValueAttribute("addMessage");

    // go to the next page
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();
    // See that it has fooValue
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash2FooValueId\">\\s*fooValue\\s*</span>.*"));
    // See that it has barValue
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash2BarValueId\">\\s*barValue\\s*</span>.*"));
    // See that it has the message
    assertTrue(-1 != pageText.indexOf("test that this persists across the redirect"));

    // click the reload button
    button = (HtmlSubmitInput) page.getHtmlElementById("reload");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that it doesn't have the message
    assertTrue(-1 == pageText.indexOf("test that this persists across the redirect"));

    // Click the back button
    button = (HtmlSubmitInput) page.getHtmlElementById("back");
    page = (HtmlPage) button.click();

    // Click the next button
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that the page does not have the message
    assertTrue(-1 == pageText.indexOf("test that this persists across the redirect"));

    // Click the next button
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that it has banzai
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash3NowValueId\">\\s*banzai\\s*</span>.*"));

    // Click the next button
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that it still has banzai
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash4BuckarooValueId\">\\s*banzai\\s*</span>.*"));

    // click the link
    HtmlAnchor link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    // on flash5
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    // click the link on the next page
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    // click the link on the same page
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    // click the link on the same page
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    link = (HtmlAnchor) page.getElementById("link2");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    // it went away because there was no keep
    assertTrue(page.asText().contains("Value is ."));

    page = webClient.getPage(webUrl + "faces/flash9.xhtml");

    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    text.setValueAttribute("a value");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    text.setValueAttribute("b value");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    text.setValueAttribute("c value");

    button = (HtmlSubmitInput) page.getHtmlElementById("keep");
    page = (HtmlPage) button.click();

    pageText = page.asText();

    assertTrue(pageText.contains("valueA: a value"));
    assertTrue(pageText.contains("valueB: b value"));
    assertTrue(pageText.contains("valueC: c value"));

    link = (HtmlAnchor) page.getElementById("flash9");
    page = link.click();

    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    assertEquals(text.getValueAttribute(), "a value");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    assertEquals(text.getValueAttribute(), "b value");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    assertEquals(text.getValueAttribute(), "c value");

    page = webClient.getPage(webUrl + "faces/flash9.xhtml");
    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    assertEquals(text.getValueAttribute(), "");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    assertEquals(text.getValueAttribute(), "");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    assertEquals(text.getValueAttribute(), "");

    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    text.setValueAttribute("A value");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    text.setValueAttribute("B value");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    text.setValueAttribute("C value");

    button = (HtmlSubmitInput) page.getHtmlElementById("nokeep");
    page = (HtmlPage) button.click();

    pageText = page.asText();

    assertTrue(pageText.contains("valueA: A value"));
    assertTrue(pageText.contains("valueB: B value"));
    assertTrue(pageText.contains("valueC: C value"));

    button = (HtmlSubmitInput) page.getHtmlElementById("reload");
    page = (HtmlPage) button.click();

    pageText = page.asText();

    assertTrue(!pageText.contains("valueA: A value"));
    assertTrue(!pageText.contains("valueB: B value"));
    assertTrue(!pageText.contains("valueC: C value"));

    // content from Sebastian Hennebrueder
    page = webClient.getPage(webUrl + "faces/flash12.xhtml");
    button = (HtmlSubmitInput) page.getHtmlElementById("start");
    page = (HtmlPage) button.click();

    pageText = page.asText();
    assertTrue(pageText.contains("4711"));

    page = (HtmlPage) page.refresh();

    pageText = page.asText();
    assertTrue(!pageText.contains("4711"));

    // Test for JAVASERVERFACES-2087
    page = webClient.getPage(webUrl + "faces/flash13.xhtml");
    button = (HtmlSubmitInput) page.getHtmlElementById("flashbtn");
    page = (HtmlPage) button.click();

    pageText = page.asText();
    assertTrue(pageText.contains("read strobist"));

    page = webClient.getPage(webUrl + "faces/flash13.xhtml");
    pageText = page.asText();
    assertTrue(!pageText.contains("read strobist"));

    page = webClient.getPage(webUrl + "faces/flash13.xhtml");
    pageText = page.asText();
    assertTrue(!pageText.contains("read strobist"));

    page = webClient.getPage(webUrl + "faces/flash14.xhtml");
    pageText = page.asText();
    assertTrue(
        pageText.matches(
            "(?s).*\\[received javax.faces.event.PreClearFlashEvent source:\\{\\}\\].*"));
  }
Ejemplo n.º 23
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    int no = 0;
    try {
      no = Integer.parseInt(request.getParameter("no"));

    } catch (NumberFormatException exception) {
      no = 0;
    }

    try {
      /* TODO output your page here. You may use following sample code. */
      out.println("<!DOCTYPE html>");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet NewServlet</title>");
      out.println("</head>");
      out.println("<body>");

      final WebClient webClient = new WebClient();
      webClient.getCookieManager().clearCookies();
      webClient.getOptions().setUseInsecureSSL(true);
      webClient.setJavaScriptEnabled(false);
      final HtmlPage page = webClient.getPage("https://filestream.me/");
      // out.println(page.getTitleText());
      System.out.println("no of forms : " + page.getForms().size());
      HtmlForm form = page.getForms().get(1);
      final HtmlTextInput textField = form.getInputByName("login");
      textField.setAttribute("value", "*****@*****.**");

      final HtmlPasswordInput passField = form.getInputByName("password");
      passField.setAttribute("value", "ramkrishnan18");
      HtmlSubmitInput htmlSubmitInput = form.getInputByValue("login");
      HtmlPage page1 = htmlSubmitInput.click();

      HtmlTable htmlTable = page1.getHtmlElementById("fileCatTable");
      List<HtmlTableRow> listOfHtmlTableRow = htmlTable.getBodies().get(0).getRows();
      List<String> allLinks = new ArrayList<String>();
      for (HtmlTableRow htmlTableRow : listOfHtmlTableRow) {
        HtmlTableCell cell = htmlTableRow.getCells().get(htmlTableRow.getCells().size() - 1);
        for (DomElement domElement : cell.getChildElements()) {
          // out.println(domElement.getTagName());
          if (domElement.getTagName().equals("div")) {
            boolean flag = true;

            for (DomElement celldomElement : domElement.getChildElements()) {
              if (flag) {
                // out.println(celldomElement.getTagName());

                String title = celldomElement.getAttribute("title");
                if ("Download".equals(title) || "Downloads".equals(title)) {

                  String link = celldomElement.getAttribute("onclick");
                  String http =
                      link.substring(
                          link.indexOf('\'') + 1, link.indexOf('\'', link.indexOf('\'') + 1));

                  //  out.println(celldomElement.getAttribute("onclick") + "<br/>");
                  // out.println(http + "<br/>");
                  allLinks.add(http);
                  flag = false;
                }
              }
            }
          }
        }
      }

      //  InputStream is =anchorAttachment.click().getWebResponse().getContentAsStream();

      out.println("************ Start *************");

      //  HtmlAnchor anchorElement=HTMLAnchorElement.;
      //  anchorElement.set
      // anchorElement.setHref(allLinks.get(0));

      //  anchorElement.cl
      final String u = allLinks.get(no);
      Thread t =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    URL url = new URL(u);
                    System.out.println("Link : " + u);
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();

                    // System.out.println("Response Code : " + con.getInputStream().available());
                    con.setRequestProperty("Accept-Encoding", "gzip,deflate");
                    con.setRequestProperty(
                        "User-Agent",
                        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36");

                    Map<String, List<String>> map = con.getHeaderFields();

                    for (String object : map.keySet()) {
                      System.out.println(object + " --> " + map.get(object));
                    }

                    System.out.println("Response Code : " + con.getResponseCode());
                    System.out.println("length :" + con.getContentLength());
                    System.out.println("Message " + con.getResponseMessage());

                    InputStream inputStream = con.getInputStream();
                    String path = System.getenv("OPENSHIFT_JBOSSAS_DIR");
                    FileOutputStream fileOutputStream = new FileOutputStream(path + "test.zip");
                    byte[] buffer = new byte[1024];
                    System.out.println(inputStream.available());
                    int bytesRead = 10;
                    while (true) {
                      //   System.out.print("--");
                      bytesRead = inputStream.read(buffer);
                      //   System.out.println(bytesRead);
                      if (bytesRead == -1) {
                        break;
                      }
                      fileOutputStream.write(buffer, 0, bytesRead);
                      // System.out.print(">");
                    }
                    fileOutputStream.close();

                    System.out.println("File Completed");
                  } catch (IOException ex) {
                    Logger.getLogger(MakeData.class.getName()).log(Level.SEVERE, null, ex);
                  }
                }
              });
      t.start();

      //            System.out.println(allLinks.get(0));
      //            System.out.println(webClient.getCookieManager().getCookies(new
      // URL(allLinks.get(0))).size());
      //            // System.out.println(httpPage.asText());
      //             HtmlPage httpPage = webClient.getPage(allLinks.get(0));
      //
      //           // final String pageAsXml = page1.asXml();
      //            // InputStream inputStream=httpPage.getWebResponse().getContentAsStream();
      //           //  inputStream.available();
      //              System.out.println("Code : "+httpPage.getWebResponse().getStatusMessage());
      //               System.out.println("Code : "+httpPage.getWebResponse().getContentType());
      //                System.out.println("netCode :
      // "+httpPage.getWebResponse().getContentCharset());
      //
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getStatusCode());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentType());
      // out.println("<br/><br/>Code : "+httpPage.getWebResponse().getContentCharset());

      // final String pageAsText = page1.asText();

      // out.println(pageAsXml);
      webClient.closeAllWindows();
      out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
      out.println("</body>");
      out.println("</html>");
    } finally {
      out.close();
    }
  }