-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminPageObjects.java
More file actions
184 lines (160 loc) · 7.02 KB
/
AdminPageObjects.java
File metadata and controls
184 lines (160 loc) · 7.02 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package homework2;
import homework3.AdminPageDrivers;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
public class AdminPageObjects {
private WebDriver webDriver;
public AdminPageObjects(WebDriver webDriver) {
this.webDriver = webDriver;
PageFactory.initElements(webDriver, this);
}
public WebElement emailField() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("email")));
return webDriver.findElement(By.id("email"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement passwordField() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("passwd")));
return webDriver.findElement(By.id("passwd"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement submitButton() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("submitLogin")));
return webDriver.findElement(By.name("submitLogin"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement employeeNameDropdownToggle() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='employee_avatar_small']")));
return webDriver.findElement(By.xpath("//span[@class='employee_avatar_small']"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement logoutLink() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("header_logout")));
return webDriver.findElement(By.id("header_logout"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement menuItem(String itemText) {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(), '" + itemText + "')]")));
return webDriver.findElement(By.xpath("//span[contains(text(), '" + itemText + "')]"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public void printTitleText() throws InterruptedException {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
Thread.sleep(2000);
System.out.println(webDriver.getTitle());
}
public void refreshPage() {
webDriver.navigate().refresh();
}
public WebElement categoriesSubMenuItem() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("subtab-AdminCategories")));
return webDriver.findElement(By.id("subtab-AdminCategories"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement catalogMenuItem() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("subtab-AdminCatalog")));
return webDriver.findElement(By.id("subtab-AdminCatalog"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement addNewCategoryButton() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("page-header-desc-category-new_category")));
return webDriver.findElement(By.id("page-header-desc-category-new_category"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement categoryNameField() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("name_1")));
return webDriver.findElement(By.id("name_1"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement saveNewCategoryButton() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("category_form_submit_btn")));
return webDriver.findElement(By.id("category_form_submit_btn"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement successMessage() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='alert alert-success']")));
return webDriver.findElement(By.xpath("//div[@class='alert alert-success']"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement searcByNameField() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("categoryFilter_name")));
return webDriver.findElement(By.name("categoryFilter_name"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement searcByNameButton() {
try {
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("submitFilterButtoncategory")));
return webDriver.findElement(By.id("submitFilterButtoncategory"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public WebElement searcByNameElement() {
try {
AdminPageDrivers adminPageDriver = new AdminPageDrivers();
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//td[contains(text(), '" + adminPageDriver.categoryName() + "')]")));
return webDriver.findElement(By.xpath("//td[contains(text(), '" + adminPageDriver.categoryName() + "')]"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}