commit | author | age
|
5686c9
|
1 |
import org.openqa.selenium.WebDriver |
JK |
2 |
import org.openqa.selenium.By |
|
3 |
import java.net.URLEncoder |
|
4 |
|
|
5 |
import Config |
|
6 |
|
|
7 |
class Common { |
|
8 |
public static WebDriver set(String casServer, String caFile = null, |
|
9 |
String method = null, String serviceUrl = null, |
|
10 |
WebDriver driver = null) { |
|
11 |
if(driver == null) { |
|
12 |
driver = Config.getDriver() |
|
13 |
} |
|
14 |
|
|
15 |
def url = Config.baseUrl + '/basic/set.php' |
|
16 |
url += '?cas=' + URLEncoder.encode(casServer) |
|
17 |
if(caFile != null) { |
|
18 |
url += '&cafile=' + URLEncoder.encode(caFile) |
|
19 |
} |
|
20 |
if(method != null) { |
|
21 |
url += '&method=' + URLEncoder.encode(method) |
|
22 |
} |
|
23 |
if(serviceUrl != null) { |
|
24 |
url += '&url=' + URLEncoder.encode(serviceUrl) |
|
25 |
} |
|
26 |
|
|
27 |
driver.get(url); |
|
28 |
|
|
29 |
assert driver.getPageSource().contains('CAS server set.'); |
|
30 |
if(caFile != null) { |
|
31 |
assert driver.getPageSource().contains('CA file set.'); |
|
32 |
} else { |
|
33 |
assert driver.getPageSource().contains('CA file unset.'); |
|
34 |
} |
|
35 |
if(method != null) { |
|
36 |
assert driver.getPageSource().contains('Method set.'); |
|
37 |
} else { |
|
38 |
assert driver.getPageSource().contains('Method unset.'); |
|
39 |
} |
|
40 |
if(serviceUrl != null) { |
|
41 |
assert driver.getPageSource().contains('URL set.'); |
|
42 |
} else { |
|
43 |
assert driver.getPageSource().contains('URL unset.'); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
return driver; |
|
48 |
} |
|
49 |
|
|
50 |
public static WebDriver login(String url, WebDriver driver, |
|
51 |
String user = null, String attrs = null) { |
|
52 |
if(user == null) { |
|
53 |
user = "user123" |
|
54 |
} |
|
55 |
|
|
56 |
assert driver.getCurrentUrl().contains('service=' + URLEncoder.encode(url)) |
|
57 |
assert driver.getPageSource().contains('<form') |
|
58 |
|
|
59 |
def element = driver.findElement(By.name('user')) |
|
60 |
element.sendKeys(user) |
|
61 |
element.submit() |
|
62 |
|
|
63 |
return driver |
|
64 |
} |
|
65 |
|
|
66 |
public static WebDriver loginSingle(String url, WebDriver driver = null, |
|
67 |
String user = null, String attrs = null) { |
|
68 |
if(driver == null) { |
|
69 |
driver = Config.getDriver() |
|
70 |
} |
|
71 |
|
|
72 |
driver.get(url) |
|
73 |
this.login(url, driver, user, attrs) |
|
74 |
|
|
75 |
return driver |
|
76 |
} |
|
77 |
|
|
78 |
public static WebDriver loginMulti(String url, WebDriver driver = null, |
|
79 |
String user = null, String attrs = null) { |
|
80 |
if(driver == null) { |
|
81 |
driver = Config.getDriver() |
|
82 |
} |
|
83 |
|
|
84 |
driver.get(url) |
|
85 |
assert driver.getPageSource().contains("Not authenticated.") |
|
86 |
|
|
87 |
// Go to login page |
|
88 |
driver.findElement(By.tagName("a")).click() |
|
89 |
|
|
90 |
// Login |
|
91 |
this.login(url, driver, user, attrs) |
|
92 |
|
|
93 |
return driver |
|
94 |
} |
|
95 |
} |