Skip to content

Commit

Permalink
Add a page object for the snippet generator (#1492)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
  • Loading branch information
uhafner and timja committed Mar 9, 2024
1 parent 24c6ecd commit 4da234e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.net.URL;

import org.openqa.selenium.By;

/**
* Page object for the system configuration page.
*
Expand Down Expand Up @@ -50,4 +52,11 @@ public void setQuietPeriod(int seconds) {
public void setDescription(String desc) {
control("/system_message").set(desc);
}

public String getHomeDirectory() {
ensureConfigPage();

return driver.findElement(By.xpath("//div[contains(text(), 'Home directory')]//..//*[@class='setting-main']"))
.getText();
}
}
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"));
}
}
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"));
}
}

0 comments on commit 4da234e

Please sign in to comment.