Skip to content

Commit

Permalink
Adjustments for form rework
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Nov 16, 2021
1 parent 1688700 commit 11d2f4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,8 @@ public void clearConfiguredCategories() throws Exception {
// TODO Delete the tables code once the baseline is past 2.264.
VersionNumber version = Jenkins.getVersion();
if (version.isNewerThanOrEqualTo(new VersionNumber("2.264"))) {
deleteButtons =
config.getByXPath(
"//div[contains(concat(' ',normalize-space(@class),' '),' setting-name"
+ " ') and text()='Multi-Project Throttle"
+ " Categories']/../div[@class='setting-main']"
+ "//button[text()='Delete']");
deleteButtons = config.getByXPath(
"//div[text()='Multi-Project Throttle Categories']/../div//button[text()='Delete']");
} else {
deleteButtons =
config.getByXPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
Expand Down Expand Up @@ -313,41 +314,49 @@ private void configureNewNodeWithLabel(String label)
for(HtmlRadioButtonInput radio: radios) {
radio.setChecked(radio.getValueAttribute().equals("hudson.slaves.DumbSlave"));
}
List<HtmlButton> buttons = HtmlUnitHelper.getButtonsByXPath(form, buttonsXPath);
String buttonText = "OK";
boolean buttonFound = false;
page = submitForm(form);
boolean buttonFound;

for(HtmlButton button: buttons) {
if(button.getTextContent().equals(buttonText))
List<HtmlForm> forms = page.getForms();

for(HtmlForm aForm: forms) {
if(aForm.getActionAttribute().equals("doCreateItem"))
{
buttonFound = true;
page = button.click();
List<HtmlForm> forms = page.getForms();
form = aForm;
break;
}
}
input = form.getInputByName("_.numExecutors");
input.setValueAttribute("1");

for(HtmlForm aForm: forms) {
if(aForm.getActionAttribute().equals("doCreateItem"))
{
form = aForm;
break;
}
}
input = form.getInputByName("_.numExecutors");
input.setValueAttribute("1");
input = form.getInputByName("_.remoteFS");
input.setValueAttribute("/");

input = form.getInputByName("_.remoteFS");
input.setValueAttribute("/");
input = form.getInputByName("_.labelString");
input.setValueAttribute(label);

input = form.getInputByName("_.labelString");
input.setValueAttribute(label);
break;
List<HtmlButton> buttons = HtmlUnitHelper.getButtonsByXPath(form, buttonsXPath);
buttonFound = buttonFoundThusFormSubmitted(form, buttons, saveButtonText);
failWithMessageIfButtonNotFoundOnPage(buttonFound, saveButtonText, url);
}

private HtmlPage submitForm(HtmlForm form) throws IOException {
HtmlPage page;
if (Jenkins.getVersion().isOlderThan(new VersionNumber("2.320"))) {
List<HtmlButton> buttons = HtmlUnitHelper.getButtonsByXPath(form, buttonsXPath);
if (buttons.isEmpty()) {
fail("Failed to find button by xpath: " + buttonsXPath);
}
}
failWithMessageIfButtonNotFoundOnPage(buttonFound, buttonText, url);
page = buttons.get(0).click();

buttons = HtmlUnitHelper.getButtonsByXPath(form, buttonsXPath);
buttonText = saveButtonText;
buttonFound = buttonFoundThusFormSubmitted(form, buttons, buttonText);
failWithMessageIfButtonNotFoundOnPage(buttonFound, buttonText, url);
} else {
List<HtmlElement> elementsByAttribute = form.getElementsByAttribute("input", "type", "submit");
if (elementsByAttribute.isEmpty()) {
fail("Failed to find an input with type submit on the page");
}
page = elementsByAttribute.get(0).click();
}
return page;
}

private String configureLogger()
Expand Down

0 comments on commit 11d2f4b

Please sign in to comment.