-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
AskForValueDialog.java
249 lines (205 loc) · 7.88 KB
/
AskForValueDialog.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.pageobject;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC;
import static org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.action.ActionsFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
/** @author Vitaliy Gulyy */
@Singleton
public class AskForValueDialog {
private static final String OK_BTN_ID = "askValue-dialog-ok";
private static final String CANCEL_BTN_ID = "askValue-dialog-cancel";
private static final String CANCEL_BTN_JAVA = "newJavaClass-dialog-cancel";
private static final String ASK_FOR_VALUE_FORM = "gwt-debug-askValueDialog-window";
private static final String INPUT = "gwt-debug-askValueDialog-textBox";
private static final String NEW_JAVA_CLASS_FORM = "gwt-debug-newJavaSourceFileView-window";
private static final String INPUT_NAME_JAVA_CLASS = "gwt-debug-newJavaSourceFileView-nameField";
private static final String OK_BTN_NEW_JAVA_CLASS = "newJavaClass-dialog-ok";
private static final String ERROR_LABEL =
"//*[@id='gwt-debug-askValueDialog-window']//"
+ "div[@style='position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;']";
private static final String ERROR_LABEL_JAVA =
"//input[@id='gwt-debug-newJavaSourceFileView-nameField']/following-sibling::div[text()='Name is invalid']";
private static final String TYPE_ID = "gwt-debug-newJavaSourceFileView-typeField";
private static final String INTERFACE_ITEM =
"//*[@id='gwt-debug-newJavaSourceFileView-typeField' ]//option[@value='Interface']";
private static final String ENUM_ITEM =
"//*[@id='gwt-debug-newJavaSourceFileView-typeField' ]//option[@value='Enum']";
private final ActionsFactory actionsFactory;
public enum JavaFiles {
CLASS,
INTERFACE,
ENUM
}
@FindBy(id = OK_BTN_ID)
WebElement okBtn;
@FindBy(id = CANCEL_BTN_ID)
WebElement cancelBtn;
@FindBy(id = ASK_FOR_VALUE_FORM)
WebElement form;
@FindBy(id = INPUT)
WebElement input;
@FindBy(id = NEW_JAVA_CLASS_FORM)
WebElement newJavaClass;
@FindBy(id = INPUT_NAME_JAVA_CLASS)
WebElement inputNameJavaClass;
@FindBy(id = OK_BTN_NEW_JAVA_CLASS)
WebElement okBtnnewJavaClass;
@FindBy(xpath = ERROR_LABEL)
WebElement errorLabel;
@FindBy(id = TYPE_ID)
WebElement type;
@FindBy(xpath = INTERFACE_ITEM)
WebElement interfaceItem;
@FindBy(xpath = ENUM_ITEM)
WebElement enumItem;
@FindBy(id = CANCEL_BTN_JAVA)
WebElement cancelButtonJava;
@FindBy(xpath = ERROR_LABEL_JAVA)
WebElement errorLabelJava;
private final SeleniumWebDriver seleniumWebDriver;
private final WebDriverWait loadPageWait;
private final WebDriverWait redrawElementWait;
private final Loader loader;
@Inject
public AskForValueDialog(
SeleniumWebDriver seleniumWebDriver, Loader loader, ActionsFactory actionsFactory) {
this.seleniumWebDriver = seleniumWebDriver;
this.loader = loader;
this.actionsFactory = actionsFactory;
this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC);
this.redrawElementWait = new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC);
PageFactory.initElements(seleniumWebDriver, this);
}
public void waitFormToOpen() {
redrawElementWait.until(visibilityOf(form));
}
public void waitFormToClose() {
redrawElementWait.until(invisibilityOfElementLocated(By.id(ASK_FOR_VALUE_FORM)));
loader.waitOnClosed();
}
/** click ok button */
public void clickOkBtn() {
loadPageWait.until(visibilityOf(okBtn)).click();
waitFormToClose();
}
/** click cancel button */
public void clickCancelBtn() {
loadPageWait.until(visibilityOf(cancelBtn)).click();
waitFormToClose();
}
public void clickCancelButtonJava() {
redrawElementWait.until(visibilityOf(cancelButtonJava)).click();
}
public void typeAndWaitText(String text) {
loadPageWait.until(visibilityOf(input)).sendKeys(text);
waitInputNameContains(text);
}
public void waitNewJavaClassOpen() {
redrawElementWait.until(visibilityOf(newJavaClass));
}
public void waitNewJavaClassClose() {
redrawElementWait.until(invisibilityOfElementLocated(By.id(NEW_JAVA_CLASS_FORM)));
}
public void clickOkBtnNewJavaClass() {
loadPageWait.until(visibilityOf(okBtnnewJavaClass)).click();
loader.waitOnClosed();
}
public void typeTextInFieldName(String text) {
loadPageWait.until(visibilityOf(inputNameJavaClass)).sendKeys(text);
waitTextInFieldName(text);
}
public void waitTextInFieldName(String expectedText) {
loadPageWait.until(
(ExpectedCondition<Boolean>)
driver ->
loadPageWait
.until(visibilityOf(inputNameJavaClass))
.getAttribute("value")
.contains(expectedText));
}
public void deleteNameFromDialog() {
loadPageWait.until(visibilityOf(input)).clear();
}
/** select interface item from dropdown */
public void selectInterfaceItemFromDropDown() {
loadPageWait.until(visibilityOf(type)).click();
loadPageWait.until(visibilityOf(interfaceItem)).click();
}
/** select enum item from dropdown */
public void selectEnumItemFromDropDown() {
loadPageWait.until(visibilityOf(type)).click();
loadPageWait.until(visibilityOf(enumItem)).click();
}
public void createJavaFileByNameAndType(String name, JavaFiles javaFileType) {
waitNewJavaClassOpen();
typeTextInFieldName(name);
if (javaFileType == JavaFiles.INTERFACE) {
selectInterfaceItemFromDropDown();
}
if (javaFileType == JavaFiles.ENUM) {
selectEnumItemFromDropDown();
}
clickOkBtnNewJavaClass();
waitNewJavaClassClose();
}
/** wait expected text */
public void waitInputNameContains(final String expectedText) {
loadPageWait.until(
(ExpectedCondition<Boolean>)
webDriver ->
seleniumWebDriver
.findElement(By.id(INPUT))
.getAttribute("value")
.contains(expectedText));
}
public void createNotJavaFileByName(String name) {
typeAndWaitText(name);
clickOkBtn();
}
/** clear the input box */
public void clearInput() {
waitFormToOpen();
loadPageWait.until(visibilityOf(input)).clear();
}
/** Wait for error message */
public boolean waitErrorMessage() {
loadPageWait.until(visibilityOf(errorLabel));
return "Name is invalid".equals(errorLabel.getText());
}
public void waitErrorMessageInJavaClass() {
loadPageWait.until(visibilityOf(errorLabelJava));
}
public boolean isWidgetNewJavaClassIsOpened() {
try {
return newJavaClass.isDisplayed();
} catch (NoSuchElementException ex) {
return false;
}
}
/** launch the 'Rename project' form by keyboard */
public void launchFindFormByKeyboard() {
actionsFactory.createAction(seleniumWebDriver).sendKeys(Keys.SHIFT, Keys.F6).perform();
}
}