-
Notifications
You must be signed in to change notification settings - Fork 528
/
ParallelNavigationTest.java
205 lines (180 loc) · 9.66 KB
/
ParallelNavigationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package io.blueocean.ath.offline.multibranch;
import io.blueocean.ath.ATHJUnitRunner;
import io.blueocean.ath.GitRepositoryRule;
import io.blueocean.ath.Retry;
import io.blueocean.ath.WaitUtil;
import io.blueocean.ath.api.classic.ClassicJobApi;
import io.blueocean.ath.factory.MultiBranchPipelineFactory;
import io.blueocean.ath.model.MultiBranchPipeline;
import io.blueocean.ath.sse.SSEClientRule;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.junit.*;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
@RunWith(ATHJUnitRunner.class)
public class ParallelNavigationTest {
private Logger logger = LoggerFactory.getLogger(CommitMessagesTest.class);
@Rule
@Inject
public GitRepositoryRule git;
@Rule
@Inject
public SSEClientRule sseClientRule;
@Inject
ClassicJobApi jobApi;
@Inject
WaitUtil wait;
@Inject
MultiBranchPipelineFactory mbpFactory;
// Names of the pipelines we'll create
String navTest = "ParallelNavTest_tested";
String navTestWithInput = "ParallelNavTestWithInput_tested";
String navTestWithFailedInputStep = "ParallelNavigationTest_failed_input";
String navTestWithNoStepsNoStages = "ParallelNavTestWithNoStepsNoStages";
String navTestInputParamGoToClassicLink = "ParallelNavTestInputParamGoToClassicLink";
// Initialize our MultiBranchPipeline objects
static MultiBranchPipeline navTestPipeline = null;
static MultiBranchPipeline navTestWithInputPipeline = null;
static MultiBranchPipeline navTestWithFailedInputStepPipeline = null;
static MultiBranchPipeline navTestWithNoStepsNoStagesPipeline = null;
static MultiBranchPipeline navTestInputParamGoToClassicLinkPipeline = null;
/**
* This checks that we can run a pipeline with 2 long running parallel branches.
* You should be able to click between one and the other and see it progressing.
*/
@Test
@Retry(3)
public void parallelNavigationTest() throws IOException, GitAPIException, InterruptedException {
// Create navTest
logger.info("Creating pipeline {}", navTest);
URL navTestJenkinsfile = ParallelNavigationTest.class.getResource("ParallelNavigationTest/Jenkinsfile");
Files.copy(new File(navTestJenkinsfile.getFile()).toPath(), new File(git.gitDirectory, "Jenkinsfile").toPath());
git.addAll();
git.commit("Initial commit for " + navTest);
logger.info("Committed Jenkinsfile for {}", navTest);
navTestPipeline = mbpFactory.pipeline(navTest).createPipeline(git);
logger.info("Finished creating {}", navTest);
logger.info("Beginning parallelNavigationTest()");
navTestPipeline.getRunDetailsPipelinePage().open(1);
// At first we see branch one
wait.until(By.xpath("//*[text()=\"firstBranch\"]"));
logger.info("Found first branch");
wait.until(By.xpath("//*[text()=\"first branch visible\"]"));
// and clicking on the unselected node will yield us the second branch
wait.click(By.xpath("//*[contains(@class, 'pipeline-node')][3]"));
wait.until(By.xpath("//*[text()=\"secondBranch\"]"));
wait.until(By.xpath("//*[text()=\"second branch visible\"]"));
logger.info("Found second branch");
}
/**
* This checks that you can have input on 2 different parallel branches. There are no stages either side of the parallel construct.
* One at a time, the proceed button will be clicked.
*/
@Test
@Retry(3)
public void parallelNavigationTestInput() throws IOException, GitAPIException, InterruptedException {
// Create navTestWithInput
logger.info("Creating pipeline {}", navTestWithInput);
URL navTestInputJenkinsfile = ParallelNavigationTest.class.getResource("ParallelNavigationTest/Jenkinsfile.input");
Files.copy(new File(navTestInputJenkinsfile.getFile()).toPath(), new File(git.gitDirectory, "Jenkinsfile").toPath());
git.addAll();
git.commit("Initial commit for " + navTestWithInput);
logger.info("Committed Jenkinsfile for " + navTestWithInput);
navTestWithInputPipeline = mbpFactory.pipeline(navTestWithInput).createPipeline(git);
logger.info("Finished creating {}", navTestWithInput);
logger.info("Beginning parallelNavigationTestInput()");
navTestWithInputPipeline.getRunDetailsPipelinePage().open(1);
// At first we see branch one
wait.until(By.xpath("//*[text()=\"firstBranch\"]"));
logger.info("Found first branch");
wait.click(By.cssSelector(".btn.inputStepSubmit"));
logger.info("Clicked the inputStepSubmit button");
// And clicking on the unselected node will yield us the second branch
wait.click(By.xpath("//*[contains(@class, 'pipeline-node')][3]"));
wait.until(By.xpath("//*[text()=\"secondBranch\"]"));
logger.info("Found second branch");
wait.click(By.cssSelector(".btn.inputStepSubmit"));
logger.info("Clicked the inputStepSubmit button");
}
/**
* This checks that an error is shown in the UI for a failed input step
*/
@Test
@Retry(3)
public void failedInputStep() throws IOException, GitAPIException, InterruptedException {
try
{
// Create navTestWithFailedInputStep
logger.info("Creating pipeline {}", navTestWithFailedInputStep);
URL navTestWithFailedInputStepJenkinsfile = ParallelNavigationTest.class
.getResource("ParallelNavigationTest/Jenkinsfile.failed.input");
Files.copy(new File( navTestWithFailedInputStepJenkinsfile.getFile()).toPath(),
new File(git.gitDirectory, "Jenkinsfile").toPath());
git.addAll();
git.commit("Initial commit for " + navTestWithFailedInputStep);
logger.info("Committed Jenkinsfile for {}", navTestWithFailedInputStep);
navTestWithFailedInputStepPipeline = mbpFactory.pipeline(navTestWithFailedInputStep).createPipeline(git);
logger.info("Finished creating " + navTestWithFailedInputStep);
navTestWithFailedInputStepPipeline.getRunDetailsPipelinePage().open(1);
logger.info("Beginning failedInputStep()");
wait.until(
By.xpath("//*[text()=\"This step will fail because the user is not authorised to click OK\"]"));
logger.info("Found failed input step error message");
//wait.until(By.cssSelector( ".btn.inputStepSubmit" ) ).click();
wait.until(By.xpath("//button[@class='btn inputStepSubmit']")).click();
logger.info("Clicked the inputStepSubmit button");
} finally {
mbpFactory.pipeline(navTestWithFailedInputStep).deleteThisPipeline(navTestWithFailedInputStep);
}
}
/**
* This checks that the log is visible when a run fails with no steps or stages
*/
@Test
@Retry(3)
public void testLogVisibilityWhenNoStepsOrStages() throws IOException, GitAPIException, InterruptedException {
// Create navTestWithNoStepsNoStages
logger.info("Creating pipeline " + navTestWithNoStepsNoStages);
URL navTestWithNoStepsNoStagesJenkinsfile = ParallelNavigationTest.class.getResource("ParallelNavigationTest/Jenkinsfile.nosteps.nostages");
Files.copy(new File(navTestWithNoStepsNoStagesJenkinsfile.getFile()).toPath(),
new File(git.gitDirectory, "Jenkinsfile").toPath());
git.addAll();
git.commit("Initial commit for " + navTestWithNoStepsNoStages);
logger.info("Committed Jenkinsfile for " + navTestWithNoStepsNoStages);
navTestWithNoStepsNoStagesPipeline = mbpFactory.pipeline(navTestWithNoStepsNoStages).createPipeline(git);
sseClientRule.untilEvents(navTestWithNoStepsNoStagesPipeline.buildsFinished);
logger.info("Finished creating " + navTestWithNoStepsNoStages);
navTestWithNoStepsNoStagesPipeline.getRunDetailsPipelinePage().open(1);
logger.info("Wait for log to appear");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".log-body")));
}
/**
* This checks that href attr of the alert error for unsupported inputs leads to the correct classic url
*/
@Test
@Retry(3)
public void testInputParamGoToClassicLink() throws IOException, GitAPIException, InterruptedException {
// Create navTestInputParamGoToClassicLink
logger.info("Creating pipeline " + navTestInputParamGoToClassicLink);
URL navTestInputParamGoToClassicLinkJenkinsfile = ParallelNavigationTest.class
.getResource("ParallelNavigationTest/Jenkinsfile.input.param.classic.link");
Files.copy(new File(navTestInputParamGoToClassicLinkJenkinsfile.getFile()).toPath(),
new File(git.gitDirectory, "Jenkinsfile").toPath());
git.addAll();
git.commit("Initial commit for " + navTestInputParamGoToClassicLink);
logger.info("Committed Jenkinsfile for " + navTestInputParamGoToClassicLink);
navTestInputParamGoToClassicLinkPipeline = mbpFactory.pipeline(navTestInputParamGoToClassicLink).createPipeline(git);
logger.info("Finished creating " + navTestInputParamGoToClassicLink);
navTestInputParamGoToClassicLinkPipeline.getRunDetailsPipelinePage().open(1);
logger.info("Wait for alert error with link to classic input to appear");
wait.until(By.xpath("//*[@class=\"Alert Error\"]//a[@href=\"/job/ParallelNavTestInputParamGoToClassicLink/job/master/1/input\"]"));
}
}