Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-37276] Initial implementation based on @Describable
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-arabaolaza committed Oct 7, 2016
1 parent 01f7714 commit 8312875
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/org/jenkinsci/test/acceptance/po/Job.java
Expand Up @@ -128,11 +128,31 @@ public <T extends PostBuildStep> T getPublisher(Class<T> type) {
private <T extends Step> T addStep(Class<T> type, String section) {
ensureConfigPage();

// get @Describable value to use later to retrieve the path
String[] describableValue = null;
if (type.isAnnotationPresent(Describable.class)) {
describableValue = type.getAnnotation(Describable.class).value();
}
control(by.path("/hetero-list-add[%s]", section)).selectDropdownMenu(type);
elasticSleep(1000); // it takes some time until the element is visible
WebElement last = last(by.xpath("//div[@name='%s']", section));
String path = last.getAttribute("path");

String path = null;
// if I have got a Describable use it to get the path
if (describableValue != null) {
List<WebElement> newSteps = driver.findElements(by.xpath("//div[@name='%s']", section));
outer:
for (WebElement element : newSteps) {
for (String s : describableValue) {
if (element.getText().contains(s)) {
path = element.getAttribute("path");
break outer;
}
}
}
} else {
// on the other case just use the last element
WebElement last = last(by.xpath("//div[@name='%s']", section));
path = last.getAttribute("path");
}
return newInstance(type, this, path);
}

Expand Down
55 changes: 55 additions & 0 deletions src/test/java/core/PublisherOrderTest.java
@@ -0,0 +1,55 @@
package core;

import org.apache.commons.lang.SystemUtils;
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.po.AggregateDownstreamTestResults;
import org.jenkinsci.test.acceptance.po.ArtifactArchiver;
import org.jenkinsci.test.acceptance.po.BuildTrigger;
import org.jenkinsci.test.acceptance.po.Fingerprint;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.junit.Test;

public class PublisherOrderTest extends AbstractJUnitTest {

@Test
public void testOrdered() {
FreeStyleJob upstream = jenkins.jobs.create(FreeStyleJob.class);
upstream.configure();
String command = "echo 'hello' > aggregate.txt";
if(SystemUtils.IS_OS_UNIX) {
upstream.addShellStep(command);
} else {
upstream.addBatchStep(command);
}
AggregateDownstreamTestResults aggregate = upstream.addPublisher(AggregateDownstreamTestResults.class);
aggregate.specify.check();
ArtifactArchiver archiver = upstream.addPublisher(ArtifactArchiver.class);
archiver.includes("aggregate.txt");
BuildTrigger trigger = upstream.addPublisher(BuildTrigger.class);
trigger.childProjects.set("projectName");
Fingerprint fingerprint = upstream.addPublisher(Fingerprint.class);
fingerprint.targets.set("aggregate.txt");
upstream.save();
}

@Test
public void testUnordered() {
FreeStyleJob upstream = jenkins.jobs.create(FreeStyleJob.class);
upstream.configure();
String command = "echo 'hello' > aggregate.txt";
if(SystemUtils.IS_OS_UNIX) {
upstream.addShellStep(command);
} else {
upstream.addBatchStep(command);
}
ArtifactArchiver archiver = upstream.addPublisher(ArtifactArchiver.class);
archiver.includes("aggregate.txt");
BuildTrigger trigger = upstream.addPublisher(BuildTrigger.class);
trigger.childProjects.set("projectName");
Fingerprint fingerprint = upstream.addPublisher(Fingerprint.class);
fingerprint.targets.set("aggregate.txt");
AggregateDownstreamTestResults aggregate = upstream.addPublisher(AggregateDownstreamTestResults.class);
aggregate.specify.check();
upstream.save();
}
}

0 comments on commit 8312875

Please sign in to comment.