From 33dc6f03ad92495cf34d2b1377479e4255117f14 Mon Sep 17 00:00:00 2001 From: strangelookingnerd <49242855+strangelookingnerd@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:35:12 +0100 Subject: [PATCH] Fix cropper not loading correctly * try to fix flaky test --- .../jenkins/plugins/foldericon/UITest.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/test/java/jenkins/plugins/foldericon/UITest.java b/src/test/java/jenkins/plugins/foldericon/UITest.java index 44c4176f..e2b64d2d 100644 --- a/src/test/java/jenkins/plugins/foldericon/UITest.java +++ b/src/test/java/jenkins/plugins/foldericon/UITest.java @@ -11,6 +11,7 @@ import com.cloudbees.hudson.plugins.folder.Folder; import hudson.FilePath; import java.time.Duration; +import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.htmlunit.WebAssert; @@ -19,6 +20,7 @@ import org.htmlunit.html.HtmlOption; import org.htmlunit.html.HtmlPage; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.junit.jupiter.WithJenkins; @@ -87,6 +89,7 @@ void customFolderIconOption(JenkinsRule r) throws Throwable { * @throws Throwable in case anything goes wrong */ @Test + @Timeout(value = 60, unit = TimeUnit.SECONDS) void customFolderIconCroppieLoaded(JenkinsRule r) throws Throwable { Folder project = r.jenkins.createProject(Folder.class, "folder"); @@ -106,13 +109,21 @@ void customFolderIconCroppieLoaded(JenkinsRule r) throws Throwable { assertTrue(selection.isSelected()); r.submit(form); - configure = (HtmlPage) configure.refresh(); - DomElement cropper = configure.getElementById("custom-icon-cropper"); - assertNotNull(cropper); + String src = null; + + // the test is a little flaky for reasons I do not understand + while (StringUtils.isEmpty(src)) { + configure = (HtmlPage) configure.refresh(); + DomElement cropper = configure.getElementById("custom-icon-cropper"); + assertNotNull(cropper); + + if (!cropper.getElementsByTagName("img").isEmpty()) { + DomElement image = cropper.getElementsByTagName("img").get(0); + src = image.getAttribute("src"); + } + } - DomElement image = cropper.getElementsByTagName("img").get(0); - assertNotNull(image); - assertEquals("/jenkins/plugin/custom-folder-icon/icons/default.svg", image.getAttribute("src")); + assertEquals("/jenkins/plugin/custom-folder-icon/icons/default.svg", src); } }