Skip to content

Commit

Permalink
[JENKINS-37615] Honor context PageObject when looking for Jenkins ins…
Browse files Browse the repository at this point in the history
…tance
  • Loading branch information
Manuel Franco committed Aug 23, 2016
1 parent df009fc commit 158b7c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Expand Up @@ -32,7 +32,10 @@ public URL getConfigUrl() {
}

protected ContainerPageObject(PageObject context, URL url) {
this(context.injector, url);
super(context, url);
if (!url.toExternalForm().endsWith("/")) {
throw new IllegalArgumentException("URL should end with '/': " + url);
}
}

public URL getJsonApiUrl() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jenkinsci/test/acceptance/po/Jenkins.java
Expand Up @@ -42,6 +42,11 @@ private Jenkins(Injector injector, URL url) {
slaves = new SlavesMixIn(this);
}

@Override
public Jenkins getJenkins() {
return this;
}

public Jenkins(Injector injector, JenkinsController controller) {
this(injector, startAndGetUrl(controller));
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jenkinsci/test/acceptance/po/PageObject.java
Expand Up @@ -32,6 +32,12 @@ public abstract class PageObject extends CapybaraPortingLayerImpl {
* @see ContainerPageObject#url(String) Method that lets you resolve relative paths easily.
*/
public final URL url;

/**
* If the object was created with some context, preserve it so that we can
* easily get the real Jenkins root
*/
private PageObject context;

private static final RandomNameGenerator RND = new RandomNameGenerator();

Expand All @@ -42,13 +48,17 @@ public PageObject(Injector injector, URL url) {

protected PageObject(PageObject context, URL url) {
this(context.injector, url);
this.context = context;
}

public static String createRandomName() {
return RND.next();
}

public Jenkins getJenkins() {
if (context != null) {
return context.getJenkins();
}
// TODO try to find the real Jenkins root according to the owner of this object, via breadcrumb
// Alternately, Job could have a method to get Jenkins by appending ../../ to its own URL, if not in a folder (need a separate method to find folder owner, but that needs its own page object too)
return injector.getInstance(Jenkins.class);
Expand Down

0 comments on commit 158b7c7

Please sign in to comment.