|
23 | 23 | */
|
24 | 24 | package org.biouno.unochoice.issue63963;
|
25 | 25 |
|
26 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
27 |
| -import static org.junit.jupiter.api.Assertions.assertNotNull; |
28 |
| - |
29 |
| -import java.io.IOException; |
30 |
| -import java.util.Arrays; |
31 |
| -import java.util.LinkedList; |
32 |
| -import java.util.List; |
33 |
| - |
34 | 26 | import hudson.model.Descriptor;
|
| 27 | +import hudson.model.FreeStyleProject; |
| 28 | +import hudson.model.ParametersDefinitionProperty; |
| 29 | +import hudson.model.StringParameterDefinition; |
| 30 | +import org.biouno.unochoice.BaseUiTest; |
35 | 31 | import org.biouno.unochoice.CascadeChoiceParameter;
|
36 | 32 | import org.biouno.unochoice.model.GroovyScript;
|
37 | 33 | import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
|
38 | 34 | import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
|
39 | 35 | import org.junit.jupiter.api.Test;
|
40 |
| -import org.jvnet.hudson.test.JenkinsRule; |
41 |
| -import org.jvnet.hudson.test.JenkinsRule.WebClient; |
| 36 | +import org.jvnet.hudson.test.Issue; |
42 | 37 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
|
43 |
| -import org.xml.sax.SAXException; |
| 38 | +import org.openqa.selenium.By; |
| 39 | +import org.openqa.selenium.WebElement; |
| 40 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 41 | +import org.openqa.selenium.support.ui.Select; |
44 | 42 |
|
45 |
| -import org.htmlunit.html.DomElement; |
46 |
| -import org.htmlunit.html.DomNode; |
47 |
| -import org.htmlunit.html.HtmlOption; |
48 |
| -import org.htmlunit.html.HtmlPage; |
49 |
| -import org.htmlunit.html.HtmlSelect; |
| 43 | +import java.io.IOException; |
| 44 | +import java.util.Arrays; |
| 45 | +import java.util.LinkedList; |
| 46 | +import java.util.List; |
50 | 47 |
|
51 |
| -import hudson.model.FreeStyleProject; |
52 |
| -import hudson.model.ParametersDefinitionProperty; |
53 |
| -import hudson.model.StringParameterDefinition; |
| 48 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
54 | 49 |
|
55 | 50 | /**
|
56 | 51 | * Test that verifies that the order of parameters is correct
|
57 | 52 | * when using a {@code Map}.
|
58 | 53 | *
|
59 | 54 | * @since 2.5.1
|
60 | 55 | */
|
| 56 | +@Issue("JENKINS-63963") |
61 | 57 | @WithJenkins
|
62 |
| -class TestGroovyScriptParametersOrder { |
| 58 | +class TestGroovyScriptParametersOrder extends BaseUiTest { |
63 | 59 |
|
64 | 60 | /**
|
65 | 61 | * Using test kindly provided by Jason Antman in JENKINS-63963. See issue in JIRA for more context
|
66 | 62 | * about the problem, analysis, and solution (mostly done by Jason).
|
67 | 63 | *
|
68 | 64 | * @throws IOException if it fails to load the script
|
69 |
| - * @throws SAXException if the XML is malformed |
70 | 65 | */
|
71 | 66 | @Test
|
72 |
| - void testGroovyScriptParametersOrder(JenkinsRule j) throws IOException, SAXException, Descriptor.FormException { |
| 67 | + void testGroovyScriptParametersOrder() throws IOException, Descriptor.FormException { |
73 | 68 | FreeStyleProject project = j.createFreeStyleProject();
|
74 | 69 |
|
75 | 70 | StringParameterDefinition teamUid = new StringParameterDefinition("TEAM_UID", "foo", "Team name (UID)");
|
76 | 71 | StringParameterDefinition environment = new StringParameterDefinition("ENVIRONMENT", "bar", "The environment name to use for this stack (default: dev)");
|
77 | 72 |
|
78 | 73 | String scriptText = """
|
79 |
| - Map getOptions(String teamId, String enviro) { |
80 |
| - def found_snapshots = ["":"Select a backup file or snapshot to restore for " + teamId + " enviro " + enviro]; // value => selection text |
| 74 | + Map getOptions(String teamId, String env) { |
| 75 | + def found_snapshots = ["":"Select a backup file or snapshot to restore for " + teamId + " env " + env]; // value => selection text |
81 | 76 | found_snapshots["one"] = "snapshot e";
|
82 | 77 | found_snapshots["two"] = "snapshot d";
|
83 | 78 | found_snapshots["three"] = "snapshot c";
|
@@ -112,36 +107,25 @@ Map getOptions(String teamId, String enviro) {
|
112 | 107 | project.addProperty(new ParametersDefinitionProperty(Arrays.asList(teamUid, environment, backupFileName)));
|
113 | 108 | project.save();
|
114 | 109 |
|
| 110 | + driver.get(j.getURL().toString() + "job/" + project.getName() + "/build?delay=0sec"); |
115 | 111 |
|
116 |
| - WebClient wc = j.createWebClient(); |
117 |
| - wc.setThrowExceptionOnFailingStatusCode(false); |
118 |
| - HtmlPage configPage = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); |
119 |
| - DomElement renderedParameterElement = configPage.getElementById("random-name"); |
120 |
| - HtmlSelect select = null; |
121 |
| - for (DomNode node: renderedParameterElement.getChildren()) { |
122 |
| - if (node instanceof HtmlSelect) { |
123 |
| - select = (HtmlSelect) node; |
124 |
| - break; |
125 |
| - } |
126 |
| - } |
127 |
| - |
128 |
| - assertNotNull(select, "Missing cascade parameter select HTML node element!"); |
| 112 | + wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".jenkins-spinner"))); |
129 | 113 |
|
130 |
| - List<HtmlOption> htmlOptions = select.getOptions(); |
131 |
| - final List<String> options = htmlOptions |
132 |
| - .stream() |
133 |
| - .map(HtmlOption::getText) |
134 |
| - .toList(); |
| 114 | + By selectOptions = By.cssSelector("div.active-choice:has([name='name'][value='BACKUP_FILENAME']) > select > option"); |
| 115 | + wait.until(ExpectedConditions.numberOfElementsToBe(selectOptions, 6)); |
| 116 | + WebElement renderedParameterElement = findSelect("BACKUP_FILENAME"); |
| 117 | + Select select = new Select(renderedParameterElement); |
| 118 | + List<WebElement> htmlOptions = select.getOptions(); |
135 | 119 | final List<String> expected = new LinkedList<>();
|
136 |
| - { |
137 |
| - expected.add("Select a backup file or snapshot to restore for foo enviro bar"); |
138 |
| - expected.add("snapshot e"); |
139 |
| - expected.add("snapshot d"); |
140 |
| - expected.add("snapshot c"); |
141 |
| - expected.add("snapshot b"); |
142 |
| - expected.add("snapshot a"); |
| 120 | + expected.add("Select a backup file or snapshot to restore for foo env bar"); |
| 121 | + expected.add("snapshot e"); |
| 122 | + expected.add("snapshot d"); |
| 123 | + expected.add("snapshot c"); |
| 124 | + expected.add("snapshot b"); |
| 125 | + expected.add("snapshot a"); |
| 126 | + assertEquals(expected.size(), htmlOptions.size(), "Wrong number of HTML options rendered"); |
| 127 | + for (int i = 0; i < htmlOptions.size(); i++) { |
| 128 | + assertEquals(expected.get(i), htmlOptions.get(i).getText(), "Wrong HTML options rendered (or out of order)"); |
143 | 129 | }
|
144 |
| - assertEquals(expected.size(), options.size(), "Wrong number of HTML options rendered"); |
145 |
| - assertEquals(expected, options, "Wrong HTML options rendered (or out of order)"); |
146 | 130 | }
|
147 | 131 | }
|
0 commit comments