public Form check(String checkbox) {
   if (logger.isDebugEnabled()) {
     logger.debug("Checking " + checkbox);
   }
   HtmlCheckBoxInput chk = getCheckbox(checkbox);
   parent.setPage((HtmlPage) chk.setChecked(true));
   return this;
 }
Exemple #2
0
 /**
  * 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);
 }
  public void testAjaxTagEventAttribute() throws Exception {
    getPage("/faces/ajax/ajaxTagEventAttribute.xhtml");
    System.out.println("Start ajax tag event attribute test");

    // Check initial values
    checkTrue("out1", "0");
    checkTrue("out2", "1");
    checkTrue("out3", "");
    checkTrue("checkedvalue1", "false");
    checkTrue("checkedvalue2", "false");

    // Press Count
    HtmlSubmitInput button = (HtmlSubmitInput) lastpage.getHtmlElementById("button");
    lastpage = (HtmlPage) button.click();

    checkTrue("out1", "0");
    checkTrue("out2", "0");

    HtmlInput input = (HtmlInput) lastpage.getHtmlElementById("in1");
    lastpage = (HtmlPage) input.setValueAttribute("test");

    checkTrue("out3", "test");

    // Check ajax checkbox
    HtmlCheckBoxInput checked = ((HtmlCheckBoxInput) lastpage.getHtmlElementById("checkbox1"));
    lastpage = (HtmlPage) checked.click();

    checkTrue("checkedvalue1", "true");

    // Check ajax checkbox
    checked = ((HtmlCheckBoxInput) lastpage.getHtmlElementById("checkbox2"));
    lastpage = (HtmlPage) checked.click();

    checkTrue("checkedvalue2", "true");

    // Check ajax checkbox
    checked = ((HtmlCheckBoxInput) lastpage.getHtmlElementById("checkbox3"));
    lastpage = (HtmlPage) checked.click();

    checkTrue("checkedvalue3", "true");

    // Check that all ajax requests didn't result in a reload
    checkTrue("out4", "2");
  }
  @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());
      }
    }
  }
  public void testAjaxTagEventWrapping() throws Exception {
    getPage("/faces/ajax/ajaxTagEventWrapping.xhtml");
    System.out.println("Start ajax tag event wrapping test");

    // Check initial values
    checkTrue("out1", "0");
    checkTrue("say", "init");
    checkTrue("paramOut", "");
    checkTrue("out2", "1");

    // Press Count
    HtmlSubmitInput button = (HtmlSubmitInput) lastpage.getHtmlElementById("button1");
    lastpage = (HtmlPage) button.click();

    checkTrue("out1", "2");
    checkTrue("out2", "1");

    // Press Say
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("button2");
    lastpage = (HtmlPage) button.click();

    checkTrue("say", "1");
    checkTrue("out1", "2");
    checkTrue("out2", "1");

    // Press Count and Say
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("button3");
    lastpage = (HtmlPage) button.click();

    checkTrue("say", "2");
    checkTrue("out1", "3");
    checkTrue("out2", "1");

    // Press Param
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("button4");
    lastpage = (HtmlPage) button.click();

    checkTrue("say", "init");
    checkTrue("out1", "4");
    checkTrue("out2", "5");
    checkTrue("paramOut", "testval");

    // Reset Page
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("reset");
    lastpage = (HtmlPage) button.click();
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("reload");
    lastpage = (HtmlPage) button.click();

    // Check initial values
    checkTrue("out1", "0");
    checkTrue("say", "init");
    checkTrue("paramOut", "");
    checkTrue("out2", "1");

    // Press Count and Param
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("button5");
    lastpage = (HtmlPage) button.click();

    checkTrue("out1", "2");
    checkTrue("say", "init");
    checkTrue("paramOut", "testval");
    checkTrue("out2", "1");

    // Reset Page
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("reset");
    lastpage = (HtmlPage) button.click();
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("reload");
    lastpage = (HtmlPage) button.click();

    // Check initial values
    checkTrue("out1", "0");
    checkTrue("say", "init");
    checkTrue("paramOut", "");
    checkTrue("out2", "1");

    // Press Count and Say and Param
    /*  Test is faulty - commenting out - race to see if say is actually set

    button = (HtmlSubmitInput) lastpage.getHtmlElementById("button6");
    lastpage = (HtmlPage) button.click();

    checkTrue("out1","2");
    checkTrue("say","1");
    checkTrue("paramOut","testval");
    checkTrue("out2","1");
    */
    // leaving out button 7

    // Reset Page
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("reset");
    lastpage = (HtmlPage) button.click();
    button = (HtmlSubmitInput) lastpage.getHtmlElementById("reload");
    lastpage = (HtmlPage) button.click();

    // Check initial values
    checkTrue("out1", "0");
    checkTrue("say", "init");
    checkTrue("paramOut", "");
    checkTrue("out2", "1");

    // Check ajax checkbox
    HtmlCheckBoxInput checked = ((HtmlCheckBoxInput) lastpage.getHtmlElementById("checkbox1"));
    lastpage = (HtmlPage) checked.click();

    System.out.println(getText("checkedvalue1"));
    checkTrue("checkedvalue1", "true");
    checkTrue("out2", "1");

    // Check ajax + userwrap checkbox
    checked = ((HtmlCheckBoxInput) lastpage.getHtmlElementById("checkbox2"));
    lastpage = (HtmlPage) checked.click();

    checkTrue("checkedvalue2", "true");
    checkTrue("say", "1");
    checkTrue("out2", "1");

    // Check user onchange checkbox
    checked = ((HtmlCheckBoxInput) lastpage.getHtmlElementById("checkbox3"));
    lastpage = (HtmlPage) checked.click();

    checkTrue("checkedvalue3", "false");
    checkTrue("say", "2");
    checkTrue("out2", "1");
  }
Exemple #6
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"));
  }