Skip to content

Commit 93969c7

Browse files
jeromepochatjtnord
andauthored
[JENKINS-76114] Test "All" and "Suggested" buttons from the plugin configuration wizard (#2178)
* Test "All" and "Suggested" links * Avoid elastic sleep and assert selected/unselected plugins * remove blank line --------- Co-authored-by: James Nord <jtnord@users.noreply.github.com>
1 parent d12fdd5 commit 93969c7

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/main/java/org/jenkinsci/test/acceptance/po/WizardCustomizeJenkins.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.jenkinsci.test.acceptance.Matchers.hasContent;
3030

3131
import java.time.Duration;
32+
import java.util.List;
3233
import org.openqa.selenium.By;
3334
import org.openqa.selenium.NoSuchElementException;
3435
import org.openqa.selenium.NoSuchFrameException;
@@ -87,15 +88,61 @@ public void searchPlugin(String searchSring) {
8788

8889
public void selectPlugin(String pluginKey) {
8990
control(by.name(pluginKey)).click();
90-
elasticSleep(200);
91+
waitFor().withTimeout(Duration.ofSeconds(1)).until(() -> isSelected(pluginKey));
9192
}
9293

9394
public void startInstall() {
9495
clickButton("Install");
9596
}
9697

98+
/**
99+
* @deprecated use {@link #selectNone()} instead.
100+
*/
101+
@Deprecated
97102
public void deselectAll() {
103+
selectNone();
104+
}
105+
106+
public void selectAll() {
107+
clickLink("All");
108+
waitFor()
109+
.withTimeout(Duration.ofSeconds(1))
110+
.until(() -> !getSelected().isEmpty() && getUnselected().isEmpty());
111+
}
112+
113+
public void selectNone() {
98114
clickLink("None");
99-
elasticSleep(200);
115+
waitFor()
116+
.withTimeout(Duration.ofSeconds(1))
117+
.until(() -> getSelected().isEmpty() && !getUnselected().isEmpty());
118+
}
119+
120+
public void selectSuggested() {
121+
clickLink("Suggested");
122+
waitFor()
123+
.withTimeout(Duration.ofSeconds(1))
124+
.until(() -> !getSelected().isEmpty() && !getUnselected().isEmpty());
125+
}
126+
127+
private boolean isSelected(String pluginKey) {
128+
return driver
129+
.findElements(by.xpath(
130+
"//div[contains(@class, 'plugins-for-category')]/div[contains(@class, 'plugin') and contains(@class, 'selected') and contains(@class, '%s')]",
131+
pluginKey))
132+
.stream()
133+
.findFirst()
134+
.isPresent();
135+
}
136+
137+
private List<WebElement> getSelected() {
138+
return driver.findElements(
139+
by.xpath(
140+
"//div[contains(@class, 'plugins-for-category')]/div[contains(@class, 'plugin') and contains(@class, 'selected')]"));
141+
}
142+
143+
private List<WebElement> getUnselected() {
144+
return driver.findElements(
145+
by.xpath(
146+
"//div[contains(@class, 'plugins-for-category')]/div[contains(@class, 'plugin') and not(contains(@class, 'selected'))]"));
100147
}
101148
}

src/test/java/core/InstallWizardTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public void wizardInstallCustomPluginsTest() throws IOException {
9090
// Customize Jenkins step
9191
WizardCustomizeJenkins wizardCustomize = new WizardCustomizeJenkins(jenkins);
9292
wizardCustomize.doSelectPluginsToInstall();
93-
wizardCustomize.deselectAll();
93+
wizardCustomize.selectSuggested();
94+
wizardCustomize.selectAll();
95+
wizardCustomize.selectNone();
9496
wizardCustomize.searchPlugin("JUnit");
9597
wizardCustomize.selectPlugin("junit");
9698
wizardCustomize.startInstall();

0 commit comments

Comments
 (0)