From f9748b2e917291d1b3c33818c12c6ba4965957e2 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Sat, 15 Jun 2019 11:06:03 -0700 Subject: [PATCH] Add UI test --- .../TextFinderPublisherFreestyleTest.java | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java index 840f50c..503cc8d 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java @@ -1,5 +1,10 @@ package hudson.plugins.textfinder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.Functions; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; @@ -9,6 +14,8 @@ import hudson.tasks.Shell; import java.io.File; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -36,7 +43,7 @@ private void assertLogContainsMatch( @Test public void successIfFoundInConsole() throws Exception { - FreeStyleProject project = rule.createFreeStyleProject("freestyle"); + FreeStyleProject project = rule.createFreeStyleProject(); CommandInterpreter command = Functions.isWindows() ? new BatchFile("prompt $G\n" + ECHO_UNIQUE_TEXT) @@ -60,7 +67,7 @@ public void successIfFoundInConsole() throws Exception { @Test public void failureIfFoundInConsole() throws Exception { - FreeStyleProject project = rule.createFreeStyleProject("freestyle"); + FreeStyleProject project = rule.createFreeStyleProject(); CommandInterpreter command = Functions.isWindows() ? new BatchFile("prompt $G\n" + ECHO_UNIQUE_TEXT) @@ -83,7 +90,7 @@ public void failureIfFoundInConsole() throws Exception { @Test public void unstableIfFoundInConsole() throws Exception { - FreeStyleProject project = rule.createFreeStyleProject("freestyle"); + FreeStyleProject project = rule.createFreeStyleProject(); CommandInterpreter command = Functions.isWindows() ? new BatchFile("prompt $G\n" + ECHO_UNIQUE_TEXT) @@ -107,7 +114,7 @@ public void unstableIfFoundInConsole() throws Exception { @Test public void notFoundInConsole() throws Exception { - FreeStyleProject project = rule.createFreeStyleProject("freestyle"); + FreeStyleProject project = rule.createFreeStyleProject(); TextFinderPublisher textFinder = new TextFinderPublisher(UNIQUE_TEXT); textFinder.setAlsoCheckConsoleOutput(true); project.getPublishersList().add(textFinder); @@ -121,4 +128,50 @@ public void notFoundInConsole() throws Exception { build); rule.assertBuildStatus(Result.SUCCESS, build); } + + @Test + public void createTextFinderViaWebClient() throws Exception { + FreeStyleProject project = rule.createFreeStyleProject(); + assertEquals(0, project.getPublishersList().size()); + + // Go to the "Configure" page. + JenkinsRule.WebClient webClient = rule.createWebClient(); + HtmlPage page = webClient.goTo(project.getUrl() + "/configure"); + + // Add a Text Finder. + HtmlForm config = page.getFormByName("config"); + rule.getButtonByCaption(config, "Add post-build action").click(); + page.getAnchorByText("Text Finder").click(); + + // Wait for the YUI JavaScript to load. + Set requiredInputs = new HashSet<>(); + requiredInputs.add("_.fileSet"); + requiredInputs.add("_.regexp"); + requiredInputs.add("_.succeedIfFound"); + requiredInputs.add("_.unstableIfFound"); + requiredInputs.add("_.notBuiltIfFound"); + requiredInputs.add("_.alsoCheckConsoleOutput"); + for (String requiredInput : requiredInputs) { + while (config.getInputsByName(requiredInput).isEmpty()) { + Thread.sleep(100); + } + } + + // Configure the Text Finder. + config.getInputByName("_.fileSet").setValueAttribute("file1"); + config.getInputByName("_.regexp").setValueAttribute(UNIQUE_TEXT); + config.getInputByName("_.unstableIfFound").click(); + config.getInputByName("_.alsoCheckConsoleOutput").click(); + + // Submit the page. + rule.submit(config); + + // Ensure that the Text Finder was configured correctly. + assertEquals(1, project.getPublishersList().size()); + TextFinderPublisher textFinder = (TextFinderPublisher) project.getPublishersList().get(0); + assertEquals("file1", textFinder.fileSet); + assertEquals(UNIQUE_TEXT, textFinder.regexp); + assertTrue(textFinder.unstableIfFound); + assertTrue(textFinder.alsoCheckConsoleOutput); + } }