From 38031b365650ce61995740aacc8ed916ff62b089 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Sun, 8 Oct 2023 14:21:49 +0200 Subject: [PATCH] [JENKINS-65813] add an integration test for the help files --- .../biouno/unochoice/UiAcceptanceTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/org/biouno/unochoice/UiAcceptanceTest.java b/src/test/java/org/biouno/unochoice/UiAcceptanceTest.java index c5b89c23..1b1f2622 100644 --- a/src/test/java/org/biouno/unochoice/UiAcceptanceTest.java +++ b/src/test/java/org/biouno/unochoice/UiAcceptanceTest.java @@ -2,6 +2,7 @@ import io.github.bonigarcia.wdm.WebDriverManager; import org.apache.commons.lang3.StringUtils; +import org.htmlunit.ElementNotFoundException; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -26,6 +27,7 @@ import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class UiAcceptanceTest { @@ -73,6 +75,24 @@ public void tearDown() { driver.quit(); } + @LocalData("test") + @Test + public void testHelpFiles() throws Exception { + // Load the page + driver.get(j.getURL().toString() + "job/test/configure"); + + // Get the help container div of PARAM1. + final WebElement param1ParamDiv = findParamDiv("PARAM1"); + + final WebElement helpTextDiv = param1ParamDiv.findElement(By.cssSelector("div.help-area > div.help")); + assertFalse(helpTextDiv.isDisplayed()); + + param1ParamDiv.findElement(By.cssSelector("a.jenkins-help-button")).click(); + + wait.withMessage(() -> "The help text should have been displayed").until(d -> helpTextDiv.isDisplayed()); + assertTrue(helpTextDiv.getText().startsWith("This is a simple parameter")); + } + @LocalData @Test public void test() throws Exception { @@ -202,6 +222,21 @@ private WebElement findSelect(String paramName) { return driver.findElement(By.cssSelector("div.active-choice:has([name='name'][value='" + paramName + "']) > select")); } + private WebElement findParamDiv(String paramName) { + final WebElement paramValueInput = driver.findElement(By.cssSelector("input[name='parameter.name'][value='" + paramName + "']")); + // Up to how many parent levels to we want to search for the help button? + // At the moment it's 3 levels up, so let's give it some room, use 7. + final int parentsLimit = 7; + WebElement parentElement = paramValueInput.findElement(By.xpath("./.."));; + for (int i = 0; i < parentsLimit; i++) { + if (parentElement.getAttribute("name") != null && parentElement.getAttribute("name").equals("parameterDefinitions")) { + return parentElement; + } + parentElement = parentElement.findElement(By.xpath("./..")); + } + throw new ElementNotFoundException("div", "parameterDefinitions", ""); + } + private void checkOptions(Supplier param1Input, String... options) { wait.withMessage(() -> { List optionElements = param1Input.get().findElements(By.cssSelector("option"));