Skip to content

Commit

Permalink
[JENKINS-65813] add an integration test for the help files
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Oct 8, 2023
1 parent eae4a30 commit 38031b3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/test/java/org/biouno/unochoice/UiAcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<WebElement> param1Input, String... options) {
wait.withMessage(() -> {
List<WebElement> optionElements = param1Input.get().findElements(By.cssSelector("option"));
Expand Down

0 comments on commit 38031b3

Please sign in to comment.