m2u-upass-admin / test / selenium / FirstTestWithSeleniumIde.java @ 150:394c7bd4fa4e
History | View | Annotate | Download (6.21 KB)
1 |
package selenium; |
---|---|
2 |
|
3 |
import static org.junit.Assert.assertEquals; |
4 |
import static org.junit.Assert.fail; |
5 |
|
6 |
import java.util.concurrent.TimeUnit; |
7 |
|
8 |
import org.junit.After; |
9 |
import org.junit.Before; |
10 |
import org.junit.Test; |
11 |
import org.openqa.selenium.Alert; |
12 |
import org.openqa.selenium.By; |
13 |
import org.openqa.selenium.NoAlertPresentException; |
14 |
import org.openqa.selenium.NoSuchElementException; |
15 |
import org.openqa.selenium.WebDriver; |
16 |
import org.openqa.selenium.firefox.FirefoxDriver; |
17 |
|
18 |
public class FirstTestWithSeleniumIde { |
19 |
private WebDriver driver;
|
20 |
private String baseUrl; |
21 |
private boolean acceptNextAlert = true; |
22 |
private StringBuffer verificationErrors = new StringBuffer(); |
23 |
|
24 |
@Before
|
25 |
public void setUp() throws Exception { |
26 |
driver = new FirefoxDriver();
|
27 |
baseUrl = "http://localhost:9100/";
|
28 |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); |
29 |
} |
30 |
|
31 |
@Test
|
32 |
public void test() throws Exception { |
33 |
driver.get(baseUrl + "/m2u-upass-admin/common/Login.do");
|
34 |
driver.switchTo().frame(0);
|
35 |
driver.findElement(By.name("userId")).clear();
|
36 |
driver.findElement(By.name("userId")).sendKeys("administrator"); |
37 |
driver.findElement(By.name("password")).clear();
|
38 |
driver.findElement(By.name("password")).sendKeys("Mss@dm1n"); |
39 |
driver.findElement(By.name("action")).click();
|
40 |
driver.findElement(By.linkText("Admin Group Maintenance")).click();
|
41 |
try {
|
42 |
assertEquals("No group(s) found", driver.findElement(By.cssSelector("table.tabularForm > tbody > tr > td")) |
43 |
.getText()); |
44 |
} catch (Error e) { |
45 |
verificationErrors.append(e.toString()); |
46 |
} |
47 |
driver.findElement(By.name("action")).click();
|
48 |
driver.findElement(By.name("groupName")).clear();
|
49 |
driver.findElement(By.name("groupName")).sendKeys("First Group"); |
50 |
driver.findElement(By.name("groupDescription")).clear();
|
51 |
driver.findElement(By.name("groupDescription")).sendKeys("First Group Desc"); |
52 |
driver.findElement(By.name("selectedAccesses")).click();
|
53 |
driver.findElement(By.xpath("(//input[@name='action'])[2]")).click();
|
54 |
driver.findElement(By.xpath("(//input[@name='action'])[2]")).click();
|
55 |
try {
|
56 |
assertEquals("Successful", driver.findElement(By.cssSelector("td.success > strong")).getText()); |
57 |
} catch (Error e) { |
58 |
verificationErrors.append(e.toString()); |
59 |
} |
60 |
try {
|
61 |
assertEquals("Group First Group has been successfully created",
|
62 |
driver.findElement(By.xpath("//tr[2]/td[2]/strong")).getText());
|
63 |
} catch (Error e) { |
64 |
verificationErrors.append(e.toString()); |
65 |
} |
66 |
driver.findElement(By.name("action")).click();
|
67 |
driver.findElement(By.cssSelector(".alt > td:nth-child(1) > a:nth-child(1)")).click();
|
68 |
driver.findElement(By.xpath("(//input[@name='action'])[2]")).click();
|
69 |
try {
|
70 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[2]")) |
71 |
.getAttribute("value"));
|
72 |
} catch (Error e) { |
73 |
verificationErrors.append(e.toString()); |
74 |
} |
75 |
try {
|
76 |
assertEquals("on", driver.findElement(By.name("editableArray")).getAttribute("value")); |
77 |
} catch (Error e) { |
78 |
verificationErrors.append(e.toString()); |
79 |
} |
80 |
try {
|
81 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[3]")) |
82 |
.getAttribute("value"));
|
83 |
} catch (Error e) { |
84 |
verificationErrors.append(e.toString()); |
85 |
} |
86 |
try {
|
87 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[4]")) |
88 |
.getAttribute("value"));
|
89 |
} catch (Error e) { |
90 |
verificationErrors.append(e.toString()); |
91 |
} |
92 |
try {
|
93 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[4]")) |
94 |
.getAttribute("value"));
|
95 |
} catch (Error e) { |
96 |
verificationErrors.append(e.toString()); |
97 |
} |
98 |
try {
|
99 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[5]")) |
100 |
.getAttribute("value"));
|
101 |
} catch (Error e) { |
102 |
verificationErrors.append(e.toString()); |
103 |
} |
104 |
try {
|
105 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[6]")) |
106 |
.getAttribute("value"));
|
107 |
} catch (Error e) { |
108 |
verificationErrors.append(e.toString()); |
109 |
} |
110 |
try {
|
111 |
assertEquals("on", driver.findElement(By.xpath("(//input[@name='editableArray'])[7]")) |
112 |
.getAttribute("value"));
|
113 |
} catch (Error e) { |
114 |
verificationErrors.append(e.toString()); |
115 |
} |
116 |
try {
|
117 |
assertEquals("on", driver.findElement(By.cssSelector("li.lastLine > input[name=\"editableArray\"]")) |
118 |
.getAttribute("value"));
|
119 |
} catch (Error e) { |
120 |
verificationErrors.append(e.toString()); |
121 |
} |
122 |
driver.findElement(By.name("action")).click();
|
123 |
driver.findElement(By.name("action")).click();
|
124 |
driver.findElement(By.linkText("Admin Group Maintenance")).click();
|
125 |
driver.findElement(By.cssSelector("tr.alt > td > a")).click();
|
126 |
driver.findElement(By.xpath("(//input[@name='action'])[3]")).click();
|
127 |
driver.findElement(By.xpath("(//input[@name='action'])[2]")).click();
|
128 |
try {
|
129 |
assertEquals("Successful", driver.findElement(By.cssSelector("td.success > strong")).getText()); |
130 |
} catch (Error e) { |
131 |
verificationErrors.append(e.toString()); |
132 |
} |
133 |
try {
|
134 |
assertEquals("Group First Group has been successfully deleted",
|
135 |
driver.findElement(By.xpath("//tr[2]/td[2]/strong")).getText());
|
136 |
} catch (Error e) { |
137 |
verificationErrors.append(e.toString()); |
138 |
} |
139 |
driver.findElement(By.linkText("Admin Group Maintenance")).click();
|
140 |
try {
|
141 |
assertEquals("No group(s) found", driver.findElement(By.cssSelector("table.tabularForm > tbody > tr > td")) |
142 |
.getText()); |
143 |
} catch (Error e) { |
144 |
verificationErrors.append(e.toString()); |
145 |
} |
146 |
driver.findElement(By.xpath("//td[3]/a/img")).click();
|
147 |
} |
148 |
|
149 |
@After
|
150 |
public void tearDown() throws Exception { |
151 |
driver.quit(); |
152 |
String verificationErrorString = verificationErrors.toString();
|
153 |
if (!"".equals(verificationErrorString)) { |
154 |
fail(verificationErrorString); |
155 |
} |
156 |
} |
157 |
|
158 |
private boolean isElementPresent(By by) { |
159 |
try {
|
160 |
driver.findElement(by); |
161 |
return true; |
162 |
} catch (NoSuchElementException e) { |
163 |
return false; |
164 |
} |
165 |
} |
166 |
|
167 |
private boolean isAlertPresent() { |
168 |
try {
|
169 |
driver.switchTo().alert(); |
170 |
return true; |
171 |
} catch (NoAlertPresentException e) {
|
172 |
return false; |
173 |
} |
174 |
} |
175 |
|
176 |
private String closeAlertAndGetItsText() { |
177 |
try {
|
178 |
Alert alert = driver.switchTo().alert(); |
179 |
String alertText = alert.getText();
|
180 |
if (acceptNextAlert) {
|
181 |
alert.accept(); |
182 |
} else {
|
183 |
alert.dismiss(); |
184 |
} |
185 |
return alertText;
|
186 |
} finally {
|
187 |
acceptNextAlert = true;
|
188 |
} |
189 |
} |
190 |
} |