Skip to content

Commit b4de770

Browse files
authored
Correctly deflake MavenPluginTest (#2165)
The prior attempt to fix the code was still flaky as the second click could also be intercepted by the chevron. Be more robust against the chevron clicking being intercepted by trying until the element is stale.
1 parent 3731267 commit b4de770

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/test/java/plugins/MavenPluginTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.jenkinsci.test.acceptance.Matchers.pageObjectExists;
2929

3030
import com.google.inject.Inject;
31+
import java.time.Duration;
3132
import java.util.HashMap;
3233
import java.util.Map;
3334
import java.util.regex.Pattern;
@@ -207,15 +208,23 @@ private void assertHasModule(MavenModuleSet job, String name) {
207208

208209
job.visit("modules");
209210
WebElement webElement = find(by.xpath("//a[@href='%s/']", name));
210-
webElement.click();
211-
// a menu pops out with how selenium clicks this, an actual user will not have an issue with this
212-
// clicking a second time fixes it
213-
if (!driver.getCurrentUrl().equals(job.module(name).url.toExternalForm())) {
211+
212+
// A selenium click will go to the center of the button.
213+
// If the name is short enough (like root in some of these tests) the click will be the chevron button that flys
214+
// out.
215+
//
216+
// To work around this we click multiple times, if the clicks are intercepted by a chevron flyout then due to
217+
// the sticky element hacks they do not fly back in, so eventually one of the clicks will make!
218+
waitFor(webElement).withTimeout(Duration.ofSeconds(5)).until(() -> {
214219
webElement.click();
215-
}
220+
return isStale(webElement);
221+
});
222+
216223
assertThat(driver.getCurrentUrl(), equalTo(job.module(name).url.toExternalForm()));
217224

218225
build.open();
226+
// in the build page the status icon is also within the 'a' element so the width is big enough that the center
227+
// point won't be the chevron
219228
find(by.xpath("//a[@href='%s/']", name)).click();
220229
assertThat(driver.getCurrentUrl(), equalTo(build.module(name).url.toExternalForm()));
221230
}

0 commit comments

Comments
 (0)