-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a page object for the snippet generator (#1492)
Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/org/jenkinsci/test/acceptance/po/SnippetGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.jenkinsci.test.acceptance.po; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
|
||
/** | ||
* {@link PageObject} for the snippet generator to create bits of code for individual steps. | ||
*/ | ||
public class SnippetGenerator extends PageObject { | ||
private static final String URI = "pipeline-syntax/"; | ||
|
||
/** | ||
* Creates a new page object for the snippet generator. | ||
* | ||
* @param context | ||
* job context | ||
*/ | ||
public SnippetGenerator(final WorkflowJob context) { | ||
super(context, context.url(URI)); | ||
} | ||
|
||
@Override | ||
protected WorkflowJob getContext() { | ||
return (WorkflowJob) super.getContext(); | ||
} | ||
|
||
/** | ||
* Generates the sample pipeline script. | ||
* | ||
* @return the generated script | ||
*/ | ||
public String generateScript() { | ||
WebElement generateButton = find(By.id("generatePipelineScript-button")); | ||
generateButton.click(); | ||
|
||
WebElement snippet = find(By.id("prototypeText")); | ||
waitFor().until(() -> StringUtils.isNotBlank(snippet.getAttribute("value"))); | ||
|
||
return StringUtils.defaultString(snippet.getAttribute("value")); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/org/jenkinsci/test/acceptance/po/SnippetGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jenkinsci.test.acceptance.po; | ||
|
||
import org.junit.Test; | ||
|
||
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest; | ||
import org.jenkinsci.test.acceptance.junit.WithPlugins; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@WithPlugins("pipeline-model-definition") | ||
public class SnippetGeneratorTest extends AbstractJUnitTest { | ||
@Test | ||
public void createPipelineSnippetToArchiveArtifacts() { | ||
WorkflowJob job = jenkins.getJobs().create(WorkflowJob.class); | ||
job.save(); | ||
|
||
SnippetGenerator snippetGenerator = new SnippetGenerator(job); | ||
snippetGenerator.open(); | ||
|
||
assertThat(snippetGenerator.generateScript(), is("archiveArtifacts artifacts: '', followSymlinks: false")); | ||
} | ||
} |