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
/
CreateVersionPage.java
158 lines (138 loc) · 5.66 KB
/
CreateVersionPage.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
/*
* Copyright 2010, 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.projectversion;
import com.google.common.base.Function;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.zanata.page.BasePage;
import static org.assertj.core.api.Assertions.assertThat;
@Slf4j
public class CreateVersionPage extends BasePage {
public final static String VALIDATION_ERROR =
"must start and end with letter or number, and contain only " +
"letters, numbers, periods, underscores and hyphens.";
public By projectVersionID = By.id("create-version-form:slug:input:slug");
private By projectTypeSelection = By.id("create-version-form:project-type");
private By saveButton = By.id("create-version-form:button-create");
private By copyFromPreviousVersionChk = By.id("create-version-form:copy-from-version");
private By projectTypesList = By.id("create-version-form:project-type-list");
private By previousVersionsList = By.id("create-version-form:project-version");
public CreateVersionPage(final WebDriver driver) {
super(driver);
}
/**
* Enter a version ID - only available on creating a new version
*
* @param versionId
* @return new CreateVersionPage
*/
public CreateVersionPage inputVersionId(final String versionId) {
log.info("Enter version ID {}", versionId);
enterText(getVersionIdField(), versionId);
return new CreateVersionPage(getDriver());
}
private boolean isCopyFromVersionAvailable() {
return getDriver()
.findElements(copyFromPreviousVersionChk)
.size() > 0;
}
private void clickCopyFromCheckbox() {
((JavascriptExecutor) getDriver())
.executeScript("arguments[0].click();",
readyElement(copyFromPreviousVersionChk)
.findElement(By.tagName("span")));
}
public CreateVersionPage enableCopyFromVersion() {
log.info("Set Copy From Previous checkbox");
if (!isCopyFromVersionAvailable()) {
log.warn("Copy Version not available!");
return this;
}
if (copyFromVersionIsChecked()) {
log.warn("Checkbox already enabled!");
} else {
clickCopyFromCheckbox();
}
readyElement(previousVersionsList);
return this;
}
public CreateVersionPage disableCopyFromVersion() {
log.info("Unset Copy From Previous checkbox");
if (!isCopyFromVersionAvailable()) {
log.warn("Copy Version not available!");
return this;
}
if (!copyFromVersionIsChecked()) {
log.warn("Checkbox already disabled!");
} else {
clickCopyFromCheckbox();
}
readyElement(projectTypesList);
return this;
}
public boolean copyFromVersionIsChecked() {
log.info("Query is Copy from Version checkbox checked");
return readyElement(copyFromPreviousVersionChk)
.findElement(By.tagName("input")).isSelected();
}
private WebElement getVersionIdField() {
log.info("Query Version ID");
return readyElement(projectVersionID);
}
public CreateVersionPage selectProjectType(final String projectType) {
log.info("Click project type {}", projectType);
WebElement projectTypeCheck = waitForAMoment()
.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
for (WebElement item : readyElement(projectTypeSelection)
.findElements(By.tagName("li"))) {
if (item.findElement(By.tagName("label")).getText()
.startsWith(projectType)) {
return item;
}
}
return null;
}
});
projectTypeCheck.click();
return new CreateVersionPage(getDriver());
}
public VersionLanguagesPage saveVersion() {
log.info("Click Save");
clickAndCheckErrors(readyElement(saveButton));
return new VersionLanguagesPage(getDriver());
}
public CreateVersionPage saveExpectingError() {
log.info("Click Save");
clickElement(saveButton);
return new CreateVersionPage(getDriver());
}
public CreateVersionPage expectNumErrors(final int numberOfErrors) {
log.info("Wait for number of error to be {}", numberOfErrors);
waitForPageSilence();
assertThat(getErrors()).hasSize(numberOfErrors);
return new CreateVersionPage(getDriver());
}
}