forked from jenkinsci/acceptance-test-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlavesMixIn.java
67 lines (54 loc) · 1.87 KB
/
SlavesMixIn.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
67
package org.jenkinsci.test.acceptance.po;
import java.io.File;
import org.jenkinsci.test.acceptance.selenium.Scroller;
import org.openqa.selenium.NoSuchElementException;
/**
* Mix-in for slaves.
*
* @author Kohsuke Kawaguchi
*/
public class SlavesMixIn extends MixIn {
private final Jenkins jenkins;
public SlavesMixIn(Jenkins jenkins) {
super(jenkins);
this.jenkins = jenkins;
}
public <S extends Slave> S get(Class<S> type, String name) {
return newInstance(type,jenkins,name);
}
public <S extends Slave> S create(Class<S> type) {
return create(type,createRandomName());
}
/**
* Creates a new slave of the given type. After the call, the web driver is on the config page.
*/
public <S extends Slave> S create(Class<S> type, String name) {
visit("computer/new");
find(by.input("name")).sendKeys(name);
find(by.radioButton("Permanent Agent")).click();
try {
clickButton("Create");
} catch (NoSuchElementException e) {
clickButton("OK");
}
// This form submission will drop us on the configure page
S s = newInstance(type, jenkins, name);
// Automatic disabling of sticky elements doesn't occur after a redirect
// so force it after the configuration page has loaded
new Scroller(driver).disableStickyElements();
// reasonable starting point values
s.setExecutors(1);
s.setRemoteFs(remoteFs(name));
return s;
}
private String remoteFs(String name) {
String base = System.getProperty("java.io.tmpdir");
if (System.getenv("SLAVE_FS_BASE") != null) {
base = System.getenv("SLAVE_FS_BASE");
}
if (!(base.endsWith("\\") || base.endsWith("/"))) {
base += File.separatorChar;
}
return base + name;
}
}