Skip to content

Commit 4cbf7e6

Browse files
timjalewisbirks
andauthored
Test coverage for input step (jenkinsci#786)
Co-authored-by: Lewis Birks <22620804+lewisbirks@users.noreply.github.com>
1 parent 4fb37e0 commit 4cbf7e6

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package io.jenkins.plugins.pipelinegraphview.consoleview;
2+
3+
import com.microsoft.playwright.Page;
4+
import com.microsoft.playwright.junit.UsePlaywright;
5+
import hudson.model.Result;
6+
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
7+
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
8+
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
9+
import io.jenkins.plugins.pipelinegraphview.playwright.PipelineJobPage;
10+
import io.jenkins.plugins.pipelinegraphview.playwright.PipelineOverviewPage;
11+
import io.jenkins.plugins.pipelinegraphview.playwright.PlaywrightConfig;
12+
import io.jenkins.plugins.pipelinegraphview.utils.TestUtils;
13+
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
14+
import org.junit.jupiter.api.Disabled;
15+
import org.junit.jupiter.api.Test;
16+
17+
@WithJenkinsConfiguredWithCode
18+
@UsePlaywright(PlaywrightConfig.class)
19+
class PipelineConsoleViewInputTest {
20+
21+
@Test
22+
@ConfiguredWithCode("../configure-appearance.yml")
23+
void inputWithParametersSucceeds(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
24+
WorkflowRun run = TestUtils.createAndRunJobNoWait(
25+
j, "input-with-parameters", "input-with-parameters.jenkinsfile")
26+
.waitForStart();
27+
new PipelineJobPage(p, run.getParent())
28+
.goTo()
29+
.hasBuilds(1)
30+
.nthBuild(0)
31+
.goToBuild()
32+
.goToPipelineOverview()
33+
.clickInputWithParameters()
34+
.enterText("Hi there!")
35+
.proceed();
36+
j.assertBuildStatus(Result.SUCCESS, j.waitForCompletion(run));
37+
}
38+
39+
@Test
40+
@ConfiguredWithCode("../configure-appearance.yml")
41+
void inputSucceeds(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
42+
WorkflowRun run =
43+
TestUtils.createAndRunJobNoWait(j, "input", "input.jenkinsfile").waitForStart();
44+
45+
new PipelineJobPage(p, run.getParent())
46+
.goTo()
47+
.hasBuilds(1)
48+
.nthBuild(0)
49+
.goToBuild()
50+
.goToPipelineOverview()
51+
.clickProceed();
52+
53+
j.assertBuildStatus(Result.SUCCESS, j.waitForCompletion(run));
54+
}
55+
56+
@Test
57+
@ConfiguredWithCode("../configure-appearance.yml")
58+
@Disabled("https://github.com/jenkinsci/pipeline-graph-view-plugin/issues/568")
59+
void inputSucceedsWithDelay(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
60+
WorkflowRun run =
61+
TestUtils.createAndRunJobNoWait(j, "input", "input.jenkinsfile").waitForStart();
62+
63+
PipelineOverviewPage pipelineOverviewPage = new PipelineJobPage(p, run.getParent())
64+
.goTo()
65+
.hasBuilds(1)
66+
.nthBuild(0)
67+
.goToBuild()
68+
.goToPipelineOverview();
69+
70+
// Fails if you don't click proceed immediately currently
71+
p.waitForTimeout(1000D);
72+
73+
pipelineOverviewPage.clickProceed();
74+
j.assertBuildStatus(Result.SUCCESS, j.waitForCompletion(run));
75+
}
76+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.jenkins.plugins.pipelinegraphview.playwright;
2+
3+
import com.microsoft.playwright.Page;
4+
import com.microsoft.playwright.options.AriaRole;
5+
6+
public class InputPage extends JenkinsPage<InputPage> {
7+
8+
protected InputPage(Page page, String baseUrl) {
9+
super(page, baseUrl + "input/");
10+
}
11+
12+
public InputPage enterText(String input) {
13+
page.getByRole(AriaRole.TEXTBOX).fill(input);
14+
return this;
15+
}
16+
17+
public void proceed() {
18+
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("proceed"))
19+
.click();
20+
}
21+
22+
public void abort() {
23+
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("abort"))
24+
.click();
25+
}
26+
}

src/test/java/io/jenkins/plugins/pipelinegraphview/playwright/OverviewTree.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,12 @@ public void stageIsVisible(String stage) {
100100
Locator found = getStageByName(stage);
101101
assertThat(found).isVisible();
102102
}
103+
104+
public void clickProceed() {
105+
this.page.getByText("Proceed").click();
106+
}
107+
108+
public void clickInputWithParameters() {
109+
this.page.getByText("Input requested").click();
110+
}
103111
}

src/test/java/io/jenkins/plugins/pipelinegraphview/playwright/PipelineOverviewPage.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ public class PipelineOverviewPage extends JenkinsPage<PipelineOverviewPage> {
1515
private final PipelineGraph graph;
1616
private final OverviewTree tree;
1717
private final PipelineConsole logs;
18+
private final String jobUrl;
1819

1920
public PipelineOverviewPage(Page page, String jobUrl, String buildName) {
2021
super(page, jobUrl + "pipeline-overview/");
2122
this.buildName = buildName;
23+
this.jobUrl = jobUrl;
2224
graph = new PipelineGraph(page.locator(".PWGx-PipelineGraph-container"));
2325
tree = new OverviewTree(page.locator("#tree-view-pane"));
2426
logs = new PipelineConsole(page.locator("#stage-view-pane"));
@@ -113,6 +115,17 @@ public PipelineOverviewPage stageHasStateInLogs(String stage, PipelineState stat
113115
return this;
114116
}
115117

118+
public InputPage clickInputWithParameters() {
119+
tree.clickInputWithParameters();
120+
121+
return new InputPage(page, jobUrl).waitForLoaded();
122+
}
123+
124+
public PipelineOverviewPage clickProceed() {
125+
tree.clickProceed();
126+
return this;
127+
}
128+
116129
public PipelineOverviewPage clearSearch() {
117130
tree.clearSearch();
118131
return this;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pipeline {
2+
agent any
3+
stages {
4+
stage('Input') {
5+
steps {
6+
input message: 'Shall we continue?', parameters: [string('Hello'), booleanParam('boolean-value')]
7+
}
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pipeline {
2+
agent any
3+
stages {
4+
stage('Input') {
5+
steps {
6+
input 'Do you allow this?'
7+
}
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)