Search in sources :

Example 16 with HtmlOption

use of com.gargoylesoftware.htmlunit.html.HtmlOption in project throttle-concurrent-builds-plugin by jenkinsci.

the class ThrottleQueueTaskDispatcherTest method configureLogger.

private String configureLogger() throws IOException {
    String logger = ThrottleQueueTaskDispatcher.class.getName();
    r.jenkins.getLog().doNewLogRecorder(logger);
    URL url = new URL(r.getURL() + logUrlPrefix + logger + "/" + configUrlSuffix);
    HtmlPage page = r.createWebClient().getPage(url);
    HtmlForm form = page.getFormByName(configFormName);
    List<HtmlButton> buttons = HtmlUnitHelper.getButtonsByXPath(form, buttonsXPath);
    String buttonText = "Add";
    boolean buttonFound = false;
    for (HtmlButton button : buttons) {
        if (button.getTextContent().equals(buttonText)) {
            buttonFound = true;
            button.click();
            List<HtmlInput> inputs = form.getInputsByName("_.name");
            for (HtmlInput input : inputs) {
                input.setValueAttribute(logger);
            }
            HtmlSelect select = form.getSelectByName("level");
            HtmlOption option;
            try {
                option = select.getOptionByValue("fine");
            } catch (ElementNotFoundException e) {
                // gets upper case since Jenkins 1.519
                option = select.getOptionByValue("FINE");
            }
            select.setSelectedAttribute(option, true);
            break;
        }
    }
    failWithMessageIfButtonNotFoundOnPage(buttonFound, buttonText, url);
    buttonText = saveButtonText;
    buttonFound = buttonFoundThusFormSubmitted(form, buttons, buttonText);
    failWithMessageIfButtonNotFoundOnPage(buttonFound, buttonText, url);
    return logger;
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSelect(com.gargoylesoftware.htmlunit.html.HtmlSelect) HtmlOption(com.gargoylesoftware.htmlunit.html.HtmlOption) ElementNotFoundException(com.gargoylesoftware.htmlunit.ElementNotFoundException) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) URL(java.net.URL) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton)

Example 17 with HtmlOption

use of com.gargoylesoftware.htmlunit.html.HtmlOption in project maven-plugin by jenkinsci.

the class ListScmBrowsersTest method check.

private void check(Item p) throws IOException, SAXException {
    HtmlPage page = j.createWebClient().getPage(p, "configure");
    List<HtmlSelect> selects = DomNodeUtil.selectNodes(page, "//select");
    assertTrue(selects.size() > 0);
    for (HtmlSelect select : selects) {
        Set<String> title = new HashSet<>();
        for (HtmlOption o : select.getOptions()) {
            assertTrue("Duplicate entry: " + o.getText(), title.add(o.getText()));
        }
    }
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSelect(com.gargoylesoftware.htmlunit.html.HtmlSelect) HtmlOption(com.gargoylesoftware.htmlunit.html.HtmlOption) HashSet(java.util.HashSet)

Aggregations

HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)17 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)8 HtmlSelect (com.gargoylesoftware.htmlunit.html.HtmlSelect)8 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)3 Test (org.junit.Test)3 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)2 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)2 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)2 HashSet (java.util.HashSet)2 CSSErrorHandler (com.gargoylesoftware.css.parser.CSSErrorHandler)1 CSSException (com.gargoylesoftware.css.parser.CSSException)1 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)1 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)1 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)1 SelectorList (com.gargoylesoftware.css.parser.selector.SelectorList)1 ElementNotFoundException (com.gargoylesoftware.htmlunit.ElementNotFoundException)1 DisabledElement (com.gargoylesoftware.htmlunit.html.DisabledElement)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1