/
ViewsMixIn.java
48 lines (37 loc) · 1.36 KB
/
ViewsMixIn.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
package org.jenkinsci.test.acceptance.po;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
/**
* Mix-in for {@link PageObject}s that own a group of views, like
* {@link Jenkins}.
*
* @author Kohsuke Kawaguchi
*/
public class ViewsMixIn extends MixIn {
public ViewsMixIn(ContainerPageObject context) {
super(context);
}
public <T extends View> T create(final Class<T> type) {
return create(type, createRandomName());
}
public <T extends View> T create(final Class<T> type, String name) {
final Finder<WebElement> finder = new Finder<WebElement>() {
@Override protected WebElement find(String caption) {
return outer.find(by.radioButton(caption));
}
};
// Views contributed by plugins might need some extra time to appear
WebElement typeRadio = waitFor().withTimeout(5, TimeUnit.SECONDS)
.until(new Callable<WebElement>() {
@Override public WebElement call() throws Exception {
visit("newView");
return findCaption(type, finder);
}
});
typeRadio.click();
fillIn("name", name);
clickButton("OK");
return newInstance(type, injector, url("view/%s/", name));
}
}