|
24 | 24 |
|
25 | 25 | package org.biouno.unochoice.issue62835;
|
26 | 26 |
|
27 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
28 |
| -import static org.junit.jupiter.api.Assertions.assertNotNull; |
29 |
| - |
30 |
| -import java.io.IOException; |
31 |
| -import java.util.Arrays; |
32 |
| -import java.util.Collections; |
33 |
| -import java.util.LinkedList; |
34 |
| -import java.util.List; |
35 |
| - |
| 27 | +import com.google.common.collect.Lists; |
36 | 28 | import hudson.model.Descriptor;
|
| 29 | +import hudson.model.FreeStyleProject; |
| 30 | +import hudson.model.ParametersDefinitionProperty; |
| 31 | +import hudson.model.labels.LabelAtom; |
| 32 | +import hudson.slaves.DumbSlave; |
| 33 | +import org.biouno.unochoice.BaseUiTest; |
37 | 34 | import org.biouno.unochoice.CascadeChoiceParameter;
|
38 | 35 | import org.biouno.unochoice.model.GroovyScript;
|
39 | 36 | import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
|
|
42 | 39 | import org.junit.jupiter.api.Test;
|
43 | 40 | import org.jvnet.hudson.test.Issue;
|
44 | 41 | import org.jvnet.hudson.test.JenkinsRule;
|
45 |
| -import org.jvnet.hudson.test.JenkinsRule.WebClient; |
46 | 42 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
|
47 | 43 | import org.jvnet.jenkins.plugins.nodelabelparameter.Constants;
|
48 | 44 | import org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterDefinition;
|
49 | 45 | import org.jvnet.jenkins.plugins.nodelabelparameter.node.AllNodeEligibility;
|
| 46 | +import org.openqa.selenium.By; |
| 47 | +import org.openqa.selenium.WebElement; |
| 48 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 49 | +import org.openqa.selenium.support.ui.Select; |
50 | 50 | import org.xml.sax.SAXException;
|
51 | 51 |
|
52 |
| -import org.htmlunit.html.DomElement; |
53 |
| -import org.htmlunit.html.DomNode; |
54 |
| -import org.htmlunit.html.HtmlOption; |
55 |
| -import org.htmlunit.html.HtmlPage; |
56 |
| -import org.htmlunit.html.HtmlSelect; |
57 |
| -import com.google.common.collect.Lists; |
| 52 | +import java.io.IOException; |
| 53 | +import java.util.Arrays; |
| 54 | +import java.util.Collections; |
| 55 | +import java.util.List; |
58 | 56 |
|
59 |
| -import hudson.model.FreeStyleProject; |
60 |
| -import hudson.model.ParametersDefinitionProperty; |
61 |
| -import hudson.model.labels.LabelAtom; |
62 |
| -import hudson.slaves.DumbSlave; |
| 57 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
63 | 58 |
|
64 | 59 | /**
|
65 | 60 | * Test for parameters created by the NodeLabel Plug-in.
|
66 | 61 | *
|
67 | 62 | * @see <a href="https://github.com/jenkinsci/nodelabelparameter-plugin/blob/ea0a822f3a09423eb32eee9d5496ce7a14b4a931/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/TriggerJobsTest.java">https://github.com/jenkinsci/nodelabelparameter-plugin/blob/ea0a822f3a09423eb32eee9d5496ce7a14b4a931/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/TriggerJobsTest.java</a>
|
68 | 63 | */
|
69 |
| -@Issue("62835") |
| 64 | +@Issue("JENKINS-62835") |
70 | 65 | @WithJenkins
|
71 |
| -class TestForNodeLabelParameter { |
| 66 | +class TestForNodeLabelParameter extends BaseUiTest { |
72 | 67 |
|
73 | 68 | private JenkinsRule j;
|
74 | 69 |
|
75 | 70 | private DumbSlave onlineNode;
|
76 | 71 |
|
77 | 72 | @BeforeEach
|
78 |
| - void setUp(JenkinsRule j) throws Exception { |
| 73 | + public void setUp(JenkinsRule j) { |
| 74 | + super.setUp(j); |
79 | 75 | this.j = j;
|
80 |
| - onlineNode = j.createOnlineSlave(new LabelAtom("mylabel1")); |
| 76 | + try { |
| 77 | + onlineNode = j.createOnlineSlave(new LabelAtom("mylabel1")); |
| 78 | + } catch (Exception e) { |
| 79 | + throw new RuntimeException(e); |
| 80 | + } |
81 | 81 | }
|
82 | 82 |
|
83 | 83 | @AfterEach
|
84 |
| - void tearDown() throws Exception { |
85 |
| - j.jenkins.removeNode(onlineNode); |
| 84 | + public void tearDown() { |
| 85 | + super.tearDown();; |
| 86 | + try { |
| 87 | + j.jenkins.removeNode(onlineNode); |
| 88 | + } catch (IOException e) { |
| 89 | + throw new RuntimeException(e); |
| 90 | + } |
86 | 91 | }
|
87 | 92 |
|
88 | 93 | @Test
|
@@ -120,28 +125,17 @@ void testNodeLabelParameterValueFound() throws IOException, SAXException, Descri
|
120 | 125 | project.addProperty(new ParametersDefinitionProperty(Arrays.asList(nodeLabelParameter, reactsToNodeLabelParameter)));
|
121 | 126 | project.save();
|
122 | 127 |
|
123 |
| - try (WebClient wc = j.createWebClient()) { |
124 |
| - wc.setThrowExceptionOnFailingStatusCode(false); |
125 |
| - HtmlPage configPage = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); |
126 |
| - DomElement renderedParameterElement = configPage.getElementById("random-name"); |
127 |
| - HtmlSelect select = null; |
128 |
| - for (DomNode node: renderedParameterElement.getChildren()) { |
129 |
| - if (node instanceof HtmlSelect) { |
130 |
| - select = (HtmlSelect) node; |
131 |
| - break; |
132 |
| - } |
133 |
| - } |
134 |
| - |
135 |
| - assertNotNull(select, "Missing cascade parameter select HTML node element!"); |
136 |
| - |
137 |
| - List<HtmlOption> htmlOptions = select.getOptions(); |
138 |
| - final List<String> options = htmlOptions |
139 |
| - .stream() |
140 |
| - .map(HtmlOption::getText) |
141 |
| - .toList(); |
142 |
| - final List<String> expected = new LinkedList<>(Collections.singletonList(nodeName)); |
143 |
| - assertEquals(expected.size(), options.size(), "Wrong number of HTML options rendered"); |
144 |
| - assertEquals(expected, options, "Wrong HTML options rendered (or out of order)"); |
145 |
| - } |
| 128 | + driver.get(j.getURL().toString() + "job/" + project.getName() + "/build?delay=0sec"); |
| 129 | + |
| 130 | + wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".jenkins-spinner"))); |
| 131 | + |
| 132 | + WebElement renderedParameterElement = findSelect("PARAM_B"); |
| 133 | + final Select select = new Select(renderedParameterElement); |
| 134 | + |
| 135 | + wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".jenkins-spinner"))); |
| 136 | + |
| 137 | + List<WebElement> htmlOptions = select.getOptions(); |
| 138 | + assertEquals(1, htmlOptions.size(), "Wrong number of HTML options rendered"); |
| 139 | + assertEquals(nodeName, htmlOptions.get(0).getText(), "Wrong HTML options rendered (or out of order)"); |
146 | 140 | }
|
147 | 141 | }
|
0 commit comments