Skip to content
Permalink
Browse files

[JENKINS-33944] Use PageAreas for verifications. Adding one more test…

… case.
  • Loading branch information...
armfergom committed Apr 5, 2016
1 parent 2025004 commit 5655353c15e3c0521e37e56293e943e52a04aef4
@@ -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;
@@ -32,7 +34,7 @@

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);
@@ -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();
}

}
@@ -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 {
@@ -14,21 +12,17 @@
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);
}
@@ -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.
@@ -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);
}
@@ -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.
You can’t perform that action at this time.