Search in sources :

Example 1 with HtmlNumberInput

use of com.gargoylesoftware.htmlunit.html.HtmlNumberInput in project htmlunit by HtmlUnit.

the class HTMLInputElement method getValue.

/**
 * Returns the value of the JavaScript attribute {@code value}.
 *
 * @return the value of this attribute
 */
@JsxGetter
@Override
public String getValue() {
    final HtmlInput htmlInput = getDomNodeOrDie();
    if (htmlInput instanceof HtmlFileInput) {
        final File[] files = ((HtmlFileInput) htmlInput).getFiles();
        if (files == null || files.length == 0) {
            return ATTRIBUTE_NOT_DEFINED;
        }
        final File first = files[0];
        final String name = first.getName();
        if (name.isEmpty()) {
            return name;
        }
        return "C:\\fakepath\\" + name;
    }
    if (htmlInput instanceof HtmlNumberInput) {
        final HtmlNumberInput htmlNumberInput = (HtmlNumberInput) htmlInput;
        final String valueAttr = htmlInput.getAttributeDirect("value");
        if (!valueAttr.isEmpty()) {
            if ("-".equals(valueAttr) || "+".equals(valueAttr)) {
                return "";
            }
            final int lastPos = valueAttr.length() - 1;
            if (lastPos >= 0 && valueAttr.charAt(lastPos) == '.') {
                if (htmlNumberInput.hasFeature(JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE)) {
                    return "";
                }
            }
            try {
                Double.parseDouble(valueAttr);
            } catch (final NumberFormatException e) {
                return "";
            }
        }
    }
    return htmlInput.getAttributeDirect("value");
}
Also used : HtmlFileInput(com.gargoylesoftware.htmlunit.html.HtmlFileInput) HtmlNumberInput(com.gargoylesoftware.htmlunit.html.HtmlNumberInput) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) File(java.io.File) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 2 with HtmlNumberInput

use of com.gargoylesoftware.htmlunit.html.HtmlNumberInput in project htmlunit by HtmlUnit.

the class HtmlSerializerNormalizedText2Test method getNormalizedTextFormatedAfterTyping.

private void getNormalizedTextFormatedAfterTyping(final String htmlTesterSnipped, final String... typed) throws Exception {
    final String htmlContent = "<html>\n" + "<head></head>\n" + "<body>\n" + "  " + htmlTesterSnipped + "\n" + "</body></html>";
    final HtmlPage page = loadPage(htmlContent);
    final HtmlNumberInput input = page.getHtmlElementById("inpt");
    for (final String string : typed) {
        input.type(string);
    }
    final HtmlElement tester = page.getHtmlElementById("tester");
    assertEquals(getExpectedAlerts()[0], tester.asNormalizedText());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlNumberInput(com.gargoylesoftware.htmlunit.html.HtmlNumberInput)

Example 3 with HtmlNumberInput

use of com.gargoylesoftware.htmlunit.html.HtmlNumberInput in project java-design-patterns by iluwatar.

the class AlbumPage method changeNumberOfSongs.

/**
 * Sets the number of songs number input field
 *
 * @param numberOfSongs the new number of songs value to be set
 * @return {@link AlbumPage}
 */
public AlbumPage changeNumberOfSongs(int numberOfSongs) {
    HtmlNumberInput numberOfSongsNumberField = (HtmlNumberInput) page.getElementById("numberOfSongs");
    numberOfSongsNumberField.setText(Integer.toString(numberOfSongs));
    return this;
}
Also used : HtmlNumberInput(com.gargoylesoftware.htmlunit.html.HtmlNumberInput)

Example 4 with HtmlNumberInput

use of com.gargoylesoftware.htmlunit.html.HtmlNumberInput in project email-ext-plugin by jenkinsci.

the class ExtendedEmailPublisherDescriptorTest method testSmtpPortRetainsSetValue.

@Test
@Issue("JENKINS-63367")
public void testSmtpPortRetainsSetValue() throws Exception {
    ExtendedEmailPublisherDescriptor descriptor = j.jenkins.getDescriptorByType(ExtendedEmailPublisherDescriptor.class);
    JenkinsRule.WebClient client = j.createWebClient();
    HtmlPage page = client.goTo("configure");
    HtmlNumberInput smtpPort = page.getElementByName("_.smtpPort");
    smtpPort.setValueAttribute("587");
    j.submit(page.getFormByName("config"));
    assertEquals("587", descriptor.getMailAccount().getSmtpPort());
    page = client.goTo("configure");
    smtpPort = page.getElementByName("_.smtpPort");
    assertEquals("587", smtpPort.getValueAttribute());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlNumberInput(com.gargoylesoftware.htmlunit.html.HtmlNumberInput) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 5 with HtmlNumberInput

use of com.gargoylesoftware.htmlunit.html.HtmlNumberInput in project email-ext-plugin by jenkinsci.

the class ExtendedEmailPublisherDescriptorTest method testGlobalConfigDefaultState.

@Test
public void testGlobalConfigDefaultState() throws Exception {
    HtmlPage page = j.createWebClient().goTo("configure");
    assertEquals("Should be at the Configure System page", "Configure System [Jenkins]", page.getTitleText());
    HtmlTextInput smtpHost = page.getElementByName("_.smtpHost");
    assertNotNull("SMTP Server should be present", smtpHost);
    assertEquals("SMTP Server should be blank by default", "", smtpHost.getText());
    HtmlNumberInput smtpPort = page.getElementByName("_.smtpPort");
    assertNotNull("SMTP Port should be present", smtpPort);
    assertEquals("SMTP Port should be 25 by default", "25", smtpPort.getText());
    HtmlTextInput defaultSuffix = page.getElementByName("_.defaultSuffix");
    assertNotNull("Default suffix should be present", defaultSuffix);
    assertEquals("Default suffix should be blank by default", "", defaultSuffix.getText());
    // default content type select control
    HtmlSelect contentType = page.getElementByName("_.defaultContentType");
    assertNotNull("Content type selection should be present", contentType);
    assertEquals("Plain text should be selected by default", "text/plain", contentType.getSelectedOptions().get(0).getValueAttribute());
    HtmlCheckBoxInput precedenceBulk = page.getElementByName("_.precedenceBulk");
    assertNotNull("Precedence Bulk should be present", precedenceBulk);
    assertFalse("Add precedence bulk should not be checked by default", precedenceBulk.isChecked());
    HtmlTextInput defaultRecipients = page.getElementByName("_.defaultRecipients");
    assertNotNull("Default Recipients should be present", defaultRecipients);
    assertEquals("Default recipients should be blank by default", "", defaultRecipients.getText());
    HtmlTextInput defaultReplyTo = page.getElementByName("_.defaultReplyTo");
    assertNotNull("Default Reply-to should be present", defaultReplyTo);
    assertEquals("Default Reply-To should be blank by default", "", defaultReplyTo.getText());
    HtmlTextInput emergencyReroute = page.getElementByName("_.emergencyReroute");
    assertNotNull("Emergency Reroute should be present", emergencyReroute);
    assertEquals("Emergency Reroute should be blank by default", "", emergencyReroute.getText());
    HtmlTextInput allowedDomains = page.getElementByName("_.allowedDomains");
    assertNotNull("Allowed Domains should be present", allowedDomains);
    assertEquals("Allowed Domains should be blank by default", "", allowedDomains.getText());
    HtmlTextInput excludedRecipients = page.getElementByName("_.excludedCommitters");
    assertNotNull("Excluded Recipients should be present", excludedRecipients);
    assertEquals("Excluded Recipients should be blank by default", "", excludedRecipients.getText());
    HtmlTextInput defaultSubject = page.getElementByName("_.defaultSubject");
    assertNotNull("Default Subject should be present", defaultSubject);
    assertEquals("Default Subject should be set", "$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!", defaultSubject.getText());
    HtmlNumberInput maxAttachmentSize = page.getElementByName("_.maxAttachmentSizeMb");
    assertNotNull("Max attachment size should be present", maxAttachmentSize);
    assertThat("Max attachment size should be blank or -1 by default", maxAttachmentSize.getText(), is(oneOf("", "-1")));
    HtmlTextArea defaultContent = page.getElementByName("_.defaultBody");
    assertNotNull("Default content should be present", defaultContent);
    assertEquals("Default content should be set by default", "$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:\n\nCheck console output at $BUILD_URL to view the results.", defaultContent.getText());
    HtmlTextArea defaultPresendScript = page.getElementByName("_.defaultPresendScript");
    assertNotNull("Default presend script should be present", defaultPresendScript);
    assertEquals("Default presend script should be blank by default", "", defaultPresendScript.getText());
    HtmlTextArea defaultPostsendScript = page.getElementByName("_.defaultPostsendScript");
    assertNotNull("Default postsend script should be present", defaultPostsendScript);
    assertEquals("Default postsend script should be blank by default", "", defaultPostsendScript.getText());
    HtmlCheckBoxInput debugMode = page.getElementByName("_.debugMode");
    assertNotNull("Debug mode should be present", debugMode);
    assertFalse("Debug mode should not be checked by default", debugMode.isChecked());
    HtmlCheckBoxInput adminRequiredForTemplateTesting = page.getElementByName("_.adminRequiredForTemplateTesting");
    assertNotNull("Admin required for template testing should be present", adminRequiredForTemplateTesting);
    assertFalse("Admin required for template testing should be unchecked by default", adminRequiredForTemplateTesting.isChecked());
    HtmlCheckBoxInput watchingEnabled = page.getElementByName("_.watchingEnabled");
    assertNotNull("Watching enable should be present", watchingEnabled);
    assertFalse("Watching enable should be unchecked by default", watchingEnabled.isChecked());
    HtmlCheckBoxInput allowUnregisteredEnabled = page.getElementByName("_.allowUnregisteredEnabled");
    assertNotNull("Allow unregistered should be present", allowUnregisteredEnabled);
    assertFalse("Allow unregistered should be unchecked by default", allowUnregisteredEnabled.isChecked());
    assertThrows("defaultClasspath section should not be present", ElementNotFoundException.class, () -> page.getElementByName("defaultClasspath"));
}
Also used : HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSelect(com.gargoylesoftware.htmlunit.html.HtmlSelect) HtmlNumberInput(com.gargoylesoftware.htmlunit.html.HtmlNumberInput) HtmlTextArea(com.gargoylesoftware.htmlunit.html.HtmlTextArea) Test(org.junit.Test)

Aggregations

HtmlNumberInput (com.gargoylesoftware.htmlunit.html.HtmlNumberInput)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 Test (org.junit.Test)2 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlFileInput (com.gargoylesoftware.htmlunit.html.HtmlFileInput)1 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)1 HtmlSelect (com.gargoylesoftware.htmlunit.html.HtmlSelect)1 HtmlTextArea (com.gargoylesoftware.htmlunit.html.HtmlTextArea)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)1 File (java.io.File)1 Issue (org.jvnet.hudson.test.Issue)1 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)1