Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-33944] Use PageAreas for verifications. Adding one more test…
Browse files Browse the repository at this point in the history
… case.
  • Loading branch information
armfergom committed Apr 5, 2016
1 parent 2025004 commit 5655353
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 138 deletions.
Expand Up @@ -24,6 +24,8 @@

package org.jenkinsci.test.acceptance.plugins.credentials;

import java.util.concurrent.Callable;

import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.PageArea;
import org.jenkinsci.test.acceptance.po.PageObject;
Expand All @@ -32,7 +34,7 @@ public abstract class BaseStandardCredentials extends Credential {

public final Control description = control("description");
public final Control scope = control("scope");
public final Control delete = control("repeatable-delete");
private final Control delete = control("repeatable-delete");

protected BaseStandardCredentials(PageObject context, String path) {
super(context, path);
Expand All @@ -46,5 +48,29 @@ public void setId(String id) {
control("advanced-button").click();
control("id").set(id);
}

/**
* Clicks the delete credential button and wait until it is not present anymore
*/
public void delete() {
delete.click();
// Wait for element not present to avoid errors
waitFor().until(new Callable<Boolean>() {

@Override
public Boolean call() throws Exception {
return !isPresent();
}
});
}

/**
* If the delete button is present, the credential still exists in the page.
*
* @return true if the credential is present in the page. False otherwise.
*/
private boolean isPresent() {
return this.delete.exists();
}

}
Expand Up @@ -2,9 +2,7 @@

import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.Describable;
import org.jenkinsci.test.acceptance.po.PageArea;
import org.jenkinsci.test.acceptance.po.PageAreaImpl;
import org.jenkinsci.test.acceptance.po.PageObject;

@Describable("Credential Domain")
public class Domain extends PageAreaImpl {
Expand All @@ -14,21 +12,17 @@ public class Domain extends PageAreaImpl {
public final Control addCredentialButton = control("/hetero-list-add[credentials]");
public final Control addSpecificationButton = control("/domain/hetero-list-add[specifications]");

public Domain(PageObject context, String path) {
public Domain(ManagedCredentials context, String path) {
super(context, path);
}

public Domain(PageArea area, String relativePath) {
super(area, relativePath);
}

/**
* Adds a new credential under the scope of this domain
*/
public <T extends Credential> T addCredential(Class<T> type) {
addCredentialButton.selectDropdownMenu(type);

String path = last(by.xpath("//div[@name='credentials']")).getAttribute("path");
String path = last(by.name("credentials")).getAttribute("path");

return newInstance(type, this, path);
}
Expand Down
@@ -1,10 +1,12 @@
package org.jenkinsci.test.acceptance.plugins.credentials;

import java.util.List;
import java.util.concurrent.Callable;

import org.jenkinsci.test.acceptance.po.ContainerPageObject;
import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.openqa.selenium.WebElement;

/**
* "Manage Credentials" page.
Expand All @@ -21,12 +23,13 @@ public ManagedCredentials(Jenkins j) {
}

/**
* Adds a new credential and bind it to the page ae object.
* Adds a new credential and bind it to the page object.
*/
public <T extends Credential> T add(Class<T> type) {
addButton.selectDropdownMenu(type);

String path = last(by.xpath("//div[@name='credentials']")).getAttribute("path");
List<WebElement> globalCredentials = find(by.path("/domainCredentials")).findElements(by.name("credentials"));
String path = globalCredentials.get(globalCredentials.size() - 1).getAttribute("path");

return newInstance(type, this, path);
}
Expand All @@ -48,24 +51,4 @@ public Boolean call() throws Exception {

return newInstance(Domain.class, this, path);
}

/**
* Gets a credential by the credential id
*/
public <T extends Credential> T get(Class<T> type, String id) {
String path = findIfNotVisible(by.input(id)).findElement(by.ancestor("div")).getAttribute("path");
return newInstance(type, this, path);
}

public <T extends Credential> T get(Class<T> type, String domainName, String id) {
// Find domain div
String path = findIfNotVisible(by.input(domainName))
.findElement(by.ancestor("div"))
// Find credential div inside domain div
.findElement(by.input(id))
.findElement(by.ancestor("div"))
.getAttribute("path");

return newInstance(type, this, path);
}
}

0 comments on commit 5655353

Please sign in to comment.