This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
ServerConfigurationPage.java
198 lines (171 loc) · 7.85 KB
/
ServerConfigurationPage.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
/*
* Copyright 2014, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.page.administration;
import com.google.common.base.Function;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.zanata.page.BasePage;
/**
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Slf4j
public class ServerConfigurationPage extends BasePage {
private By urlField = By.id("serverConfigForm:urlField:url");
public static By registerUrlField = By.id("serverConfigForm:registerField:registerUrl");
private By emailDomainField = By.id("serverConfigForm:emailDomainField:emailDomain");
private By adminEmailField = By.id("serverConfigForm:adminEmailField:adminEml");
public static By fromEmailField = By.id("serverConfigForm:fromEmailField:fromEml");
private By enableLogCheck = By.id("serverConfigForm:enableLogCheck");
private By logLevelSelect = By.id("serverConfigForm:logEmailLvl");
private By emailDestinationField = By.id("serverConfigForm:logDestEmailField:logDestEml");
private By helpUrlField = By.id("serverConfigForm:helpUrlField");
private By termsUrlField = By.id("serverConfigForm:termsOfUseUrlField");
private By piwikUrl = By.id("serverConfigForm:piwikUrlField:piwikUrlEml");
private By piwikId = By.id("serverConfigForm:piwikIdSiteEml");
private By maxConcurrentField = By.id("serverConfigForm:maxConcurrentPerApiKeyField:maxConcurrentPerApiKeyEml");
private By maxActiveField = By.id("serverConfigForm:maxActiveRequestsPerApiKeyField:maxActiveRequestsPerApiKeyEml");
private By saveButton = By.id("serverConfigForm:save");
public ServerConfigurationPage(WebDriver driver) {
super(driver);
}
private void enterTextConfigField(By by, String text) {
scrollIntoView(readyElement(by));
new Actions(getDriver()).moveToElement(readyElement(by))
.click()
.sendKeys(Keys.chord(Keys.CONTROL, "a"))
.sendKeys(Keys.DELETE)
.sendKeys(text).perform();
}
public ServerConfigurationPage inputServerURL(String url) {
log.info("Enter Server URL {}", url);
enterTextConfigField(urlField, url);
return new ServerConfigurationPage(getDriver());
}
public ServerConfigurationPage inputRegisterURL(String url) {
log.info("Enter Register URL {}", url);
enterTextConfigField(registerUrlField, url);
return new ServerConfigurationPage(getDriver());
}
public boolean expectFieldValue(final By by, final String expectedValue) {
log.info("Wait for field {} value", by.toString(), expectedValue);
return waitForAMoment().until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver input) {
String value = existingElement(by).getAttribute("value");
log.info("Found {}", value);
return expectedValue.equals(value);
}
});
}
public ServerConfigurationPage inputAdminEmail(String email) {
log.info("Enter admin email address {}", email);
enterTextConfigField(adminEmailField, email);
return new ServerConfigurationPage(getDriver());
}
public ServerConfigurationPage inputAdminFromEmail(String email) {
log.info("Enter admin From email address {}", email);
enterTextConfigField(fromEmailField, email);
return new ServerConfigurationPage(getDriver());
}
public ServerConfigurationPage inputHelpURL(String url) {
log.info("Enter Help URL {}", url);
enterTextConfigField(helpUrlField, url);
return new ServerConfigurationPage(getDriver());
}
public ServerConfigurationPage inputTermsOfUseURL(String url) {
log.info("Enter Terms of Use URL {}", url);
enterTextConfigField(termsUrlField, url);
return new ServerConfigurationPage(getDriver());
}
public ServerConfigurationPage clickLoggingEnabledCheckbox() {
log.info("Click enable logging checkbox");
clickElement(enableLogCheck);
return new ServerConfigurationPage(getDriver());
}
public ServerConfigurationPage selectLoggingLevel(String logLevel) {
log.info("Select logging level {}", logLevel);
new Select(readyElement(logLevelSelect)).selectByVisibleText(
logLevel);
return new ServerConfigurationPage(getDriver());
}
public String selectedLoggingLevel() {
log.info("Query selected logging level");
return new Select(readyElement(logLevelSelect))
.getFirstSelectedOption().getText();
}
public ServerConfigurationPage inputLogEmailTarget(String email) {
log.info("Enter log email target {}", email);
enterTextConfigField(emailDestinationField, email);
return new ServerConfigurationPage(getDriver());
}
public String getLogEmailTarget() {
log.info("Query log email target");
return readyElement(emailDestinationField).getAttribute("value");
}
public ServerConfigurationPage inputPiwikUrl(String url) {
log.info("Enter Piwik URL", url);
enterTextConfigField(piwikUrl, url);
return new ServerConfigurationPage(getDriver());
}
public String getPiwikUrl() {
log.info("Query Piwik URL");
return readyElement(piwikUrl).getAttribute("value");
}
public ServerConfigurationPage inputPiwikID(String id) {
log.info("Enter Piwik ID", id);
enterTextConfigField(piwikId, id);
return new ServerConfigurationPage(getDriver());
}
public String getPiwikID() {
log.info("Query Piwik ID");
return readyElement(piwikId).getAttribute("value");
}
public ServerConfigurationPage inputMaxConcurrent(int max) {
log.info("Enter maximum concurrent API requests {}", max);
readyElement(maxConcurrentField).clear();
readyElement(maxConcurrentField).sendKeys(max + "");
return new ServerConfigurationPage(getDriver());
}
public String getMaxConcurrentRequestsPerApiKey() {
log.info("Query maximum concurrent API requests");
return readyElement(maxConcurrentField).getAttribute("value");
}
public ServerConfigurationPage inputMaxActive(int max) {
log.info("Enter maximum active API requests {}", max);
readyElement(maxActiveField).clear();
readyElement(maxActiveField).sendKeys(max + "");
return new ServerConfigurationPage(getDriver());
}
public String getMaxActiveRequestsPerApiKey() {
log.info("Query maximum active API requests");
return readyElement(maxActiveField).getAttribute("value");
}
public AdministrationPage save() {
log.info("Click Save");
clickElement(saveButton);
return new AdministrationPage(getDriver());
}
}