1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.aludratest.service.gui.web.selenium.selenium1;
17
18 import org.aludratest.exception.AludraTestException;
19 import org.aludratest.service.gui.web.WebGUICondition;
20 import org.aludratest.service.locator.element.GUIElementLocator;
21 import org.aludratest.service.locator.window.WindowLocator;
22 import org.databene.commons.StringUtil;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27
28
29
30
31
32
33 public class Selenium1Condition extends AbstractSeleniumAction implements WebGUICondition {
34
35 private final static Logger LOGGER = LoggerFactory.getLogger(Selenium1Condition.class);
36
37
38
39
40
41
42
43 public Selenium1Condition(SeleniumWrapper seleniumWrapper) {
44 super(seleniumWrapper);
45 }
46
47 @Override
48 public boolean isElementPresent(String elementType, String operation, GUIElementLocator locator) {
49 try {
50 wrapper.waitForElement(locator);
51 return true;
52 }
53 catch (AludraTestException e) {
54 return false;
55 }
56 catch (Exception e) {
57 LOGGER.error("Unexpected exception during check which will be ignored", e);
58 return false;
59 }
60 }
61
62 @Override
63 public boolean isElementVisible(String elementType, String operation, GUIElementLocator locator) {
64 try {
65 wrapper.waitForVisible(locator);
66 return true;
67 }
68 catch (AludraTestException e) {
69 return false;
70 }
71 catch (Exception e) {
72 LOGGER.error("Unexpected exception during check which will be ignored", e);
73 return false;
74 }
75 }
76
77 @Override
78 public boolean isElementEnabled(String elementType, String operation, GUIElementLocator locator) {
79 try {
80 wrapper.waitForEnabled(locator);
81 return true;
82 }
83 catch (AludraTestException e) {
84 return false;
85 }
86 catch (Exception e) {
87 LOGGER.error("Unexpected exception during check which will be ignored", e);
88 return false;
89 }
90 }
91
92 @Override
93 public boolean isElementEditable(String elementType, String elementName, GUIElementLocator locator) {
94 try {
95 wrapper.waitForEditable(locator);
96 return true;
97 }
98 catch (AludraTestException e) {
99 return false;
100 }
101 catch (Exception e) {
102 LOGGER.error("Unexpected exception during check which will be ignored", e);
103 return false;
104 }
105 }
106
107 @Override
108 public boolean isElementEditable(String elementType, String elementName, GUIElementLocator locator, long timeout) {
109 try {
110 wrapper.waitForEditable(locator, timeout);
111 return true;
112 }
113 catch (AludraTestException e) {
114 return false;
115 }
116 catch (Exception e) {
117 LOGGER.error("Unexpected exception during check which will be ignored", e);
118 return false;
119 }
120 }
121
122 @Override
123 public boolean isElementNotPresent(String elementType, String operation, GUIElementLocator locator) {
124 try {
125 wrapper.waitForElementNotPresent(locator);
126 return true;
127 }
128 catch (AludraTestException e) {
129 return false;
130 }
131 catch (Exception e) {
132 LOGGER.error("Unexpected exception during check which will be ignored", e);
133 return false;
134 }
135 }
136
137 @Override
138 public boolean isElementPresent(String elementType, String operation, GUIElementLocator locator, long timeout) {
139 try {
140 wrapper.waitForElement(locator, timeout);
141 return true;
142 }
143 catch (AludraTestException e) {
144 return false;
145 }
146 catch (Exception e) {
147 LOGGER.error("Unexpected exception during check which will be ignored", e);
148 return false;
149 }
150 }
151
152 @Override
153 public boolean isElementVisible(String elementType, String operation, GUIElementLocator locator, long timeout) {
154 try {
155 wrapper.waitForVisible(locator, timeout);
156 return true;
157 }
158 catch (AludraTestException e) {
159 return false;
160 }
161 catch (Exception e) {
162 LOGGER.error("Unexpected exception during check which will be ignored", e);
163 return false;
164 }
165 }
166
167 @Override
168 public boolean isElementEnabled(String elementType, String operation, GUIElementLocator locator, long timeout) {
169 try {
170 wrapper.waitForEnabled(locator, timeout);
171 return true;
172 }
173 catch (AludraTestException e) {
174 return false;
175 }
176 catch (Exception e) {
177 LOGGER.error("Unexpected exception during check which will be ignored", e);
178 return false;
179 }
180 }
181
182 @Override
183 public boolean isElementNotPresent(String elementType, String operation, GUIElementLocator locator, long timeout) {
184 try {
185 wrapper.waitForElementNotPresent(locator, timeout);
186 return true;
187 }
188 catch (AludraTestException e) {
189 return false;
190 }
191 catch (Exception e) {
192 LOGGER.error("Unexpected exception during check which will be ignored", e);
193 return false;
194 }
195 }
196
197 @Override
198 public boolean isWindowOpen(String elementType, String operation, WindowLocator locator) {
199 try {
200 wrapper.selectWindow(locator);
201 return true;
202 }
203 catch (AludraTestException e) {
204 return false;
205 }
206 catch (Exception e) {
207 LOGGER.error("Unexpected exception during check which will be ignored", e);
208 return false;
209 }
210 }
211
212 @Override
213 public boolean isElementPresentandInForeground(String elementType, String operation, GUIElementLocator locator) {
214 try {
215 wrapper.waitForElement(locator);
216 wrapper.waitForInForeground(locator);
217 return true;
218 }
219 catch (AludraTestException e) {
220 return false;
221 }
222 catch (Exception e) {
223 LOGGER.error("Unexpected exception during check which will be ignored", e);
224 return false;
225 }
226 }
227
228 @Override
229 public boolean isElementChecked(String elementType, String elementName, GUIElementLocator locator) {
230 try {
231 wrapper.waitForElement(locator);
232 wrapper.waitForInForeground(locator);
233 return wrapper.isChecked(locator);
234 }
235 catch (AludraTestException e) {
236 return false;
237 }
238 catch (Exception e) {
239 LOGGER.error("Unexpected exception during check which will be ignored", e);
240 return false;
241 }
242 }
243
244 @Override
245 public boolean containsLabels(String elementType, String elementName, GUIElementLocator locator, String... labels) {
246 CheckLabelCondition condition = new CheckLabelCondition(true, labels, wrapper, locator);
247 wrapper.retryUntilTimeout(condition);
248 return StringUtil.isEmpty(condition.getMismatches());
249 }
250
251 @Override
252 public boolean equalsLabels(String elementType, String elementName, GUIElementLocator locator, String... labels) {
253 CheckLabelCondition condition = new CheckLabelCondition(false, labels, wrapper, locator);
254 wrapper.retryUntilTimeout(condition);
255 return StringUtil.isEmpty(condition.getMismatches());
256 }
257 }