-
Notifications
You must be signed in to change notification settings - Fork 229
/
SshCredentialDialog.java
66 lines (55 loc) · 2.09 KB
/
SshCredentialDialog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.jenkinsci.test.acceptance.plugins.ssh_credentials;
import java.time.Duration;
import org.jenkinsci.test.acceptance.plugins.credentials.Credential;
import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.PageAreaImpl;
import org.jenkinsci.test.acceptance.po.PageObject;
import org.jenkinsci.test.acceptance.selenium.Scroller;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
/**
* Modal dialog to enter a credential.
*
* @author Kohsuke Kawaguchi
*/
public class SshCredentialDialog extends PageAreaImpl {
public final Control kind = control(by.xpath("//*[@id='credentials-dialog-form']//*[@path='/']"));
public SshCredentialDialog(PageObject context, String path) {
super(context, path);
}
/**
* Selects the credential type and bind the controls to the page area.
*/
public <T extends Credential> T select(Class<T> type) {
findCaption(type, new Resolver() {
@Override
protected void resolve(String caption) {
kind.select(caption);
}
});
return newInstance(type, getPage(), getPath());
}
/**
* Adds this credential and close the modal dialog.
*/
public void add() {
this.findAndPerformClick(Credential.submitButton());
waitFor().withTimeout(Duration.ofSeconds(5)).until(() -> {
try {
return !find(Credential.submitButton()).isDisplayed();
} catch (final NoSuchElementException | StaleElementReferenceException ex) {
return true;
}
});
}
private void findAndPerformClick(final By addSubmitButtonLocator) {
final WebElement addSubmitButton = find(addSubmitButtonLocator);
final Actions builder = new Actions(driver);
new Scroller(driver).scrollIntoView(addSubmitButton);
addSubmitButton.click();
builder.perform();
}
}