Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments for form rework #151

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,55 @@ 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
.stream().filter(button -> button.getTextContent().equals("OK"))
.findFirst()
.orElseThrow(() -> new AssertionError(String.format(
"Failed to find button by xpath: %s and text 'OK'", buttonsXPath))
)
.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