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
/
ProjectWorkFlow.java
181 lines (167 loc) · 7.36 KB
/
ProjectWorkFlow.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
/*
* 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.workflow;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.zanata.page.projects.CreateProjectPage;
import org.zanata.page.projects.ProjectVersionsPage;
import org.zanata.page.projects.ProjectsPage;
import org.zanata.page.projects.projectsettings.ProjectPermissionsTab;
import org.zanata.page.projectversion.CreateVersionPage;
import org.zanata.page.projectversion.VersionLanguagesPage;
import java.util.HashMap;
import java.util.List;
/**
* This class represents the work-flows involved when interacting with
* projects, such as creating projects and versions and altering settings.
*/
@Slf4j
public class ProjectWorkFlow extends AbstractWebWorkFlow {
/**
* Creates a new project using minimal input, all other items are default.
* This function is lenient, i.e. will not fail if the project exists.
*
* @param projectId
* Project identifier
* @param projectName
* Project short name
* @return new Project page for created project
*/
public ProjectVersionsPage createNewSimpleProject(String projectId,
String projectName) {
ProjectsPage projectsPage = goToHome().goToProjects();
List<String> projects = projectsPage.getProjectNamesOnCurrentPage();
log.info("current projects: {}", projects);
if (projects.contains(projectName)) {
log.warn("{} already exists. This test environment is not clean.",
projectId);
// since we can't create same project multiple times,
// if we run this test more than once manually, we don't want it to
// fail
return projectsPage.goToProject(projectName);
}
return projectsPage.clickOnCreateProjectLink()
.enterProjectId(projectId).enterProjectName(projectName)
.pressCreateProject();
}
/**
* Create a project in full, using the details given in settings.<br/>
* All items must be defined.
*
* @param settings
* A HashMap of project identifiers and settings
* @return a new Project page for the created project
* @see {@link #projectDefaults()}
*/
public ProjectVersionsPage createNewProject(HashMap<String, String> settings) {
ProjectsPage projectsPage = goToHome().goToProjects();
List<String> projects = projectsPage.getProjectNamesOnCurrentPage();
log.info("current projects: {}", projects);
CreateProjectPage createProjectPage = projectsPage
.clickOnCreateProjectLink()
.enterProjectName(settings.get("Name"))
.enterProjectId(settings.get("Project ID"))
.enterDescription(settings.get("Description"))
.selectProjectType(settings.get("Project Type"));
createProjectPage.slightPause(); // Unusual timing issue
return createProjectPage.pressCreateProject();
}
public static HashMap<String, String> projectDefaults() {
HashMap<String, String> defaults = new HashMap<String, String>();
defaults.put("Project ID", "");
defaults.put("Name", "");
defaults.put("Description", "");
defaults.put("Project Type", "File");
return defaults;
}
/**
* By default this will create a podir project version
*
* @param projectName
* project name
* @param projectVersion
* project version id
* @return project version page
*/
public VersionLanguagesPage createNewProjectVersion(String projectName,
String projectVersion) {
return createNewProjectVersion(projectName, projectVersion, "Podir");
}
/**
* Create a new project version.
*
* @param projectName name of the project
* @param versionID ID of the version
* @param versionType type of the version
* @return new Version page, on the default Languages tab
*/
public VersionLanguagesPage createNewProjectVersion(String projectName,
String versionID, String versionType) {
ProjectVersionsPage projectVersionsPage =
goToProjectByName(projectName);
if (projectVersionsPage.getVersions().contains(versionID)) {
log.warn("{} has already been created. " +
"Presumably you are running this test manually and more" +
" than once.", versionID);
return projectVersionsPage.gotoVersion(versionID);
}
CreateVersionPage createVersionPage = projectVersionsPage
.clickCreateVersionLink();
// First version has no copy options
if (driver.findElements(By.id("create-version-form:copy-from-version"))
.size() > 0) {
createVersionPage = createVersionPage
.disableCopyFromVersion()
.selectProjectType(versionType);
}
return createVersionPage.inputVersionId(versionID).saveVersion();
}
public ProjectVersionsPage goToProjectByName(String projectName) {
ProjectsPage projects = goToHome().goToProjects();
log.info("go to project by name with current projects: {}, name: {}",
projects.getProjectNamesOnCurrentPage(), projectName);
return projects.goToProject(projectName);
}
public ProjectPermissionsTab addMaintainer(String projectName,
final String username) {
ProjectPermissionsTab projectPermissionsTab = goToHome()
.goToProjects()
.goToProject(projectName)
.gotoSettingsTab()
.gotoSettingsPermissionsTab()
.enterSearchMaintainer(username)
.selectSearchMaintainer(username);
projectPermissionsTab.waitForMaintainersContains(username);
return new ProjectPermissionsTab(driver);
}
public ProjectPermissionsTab removeMaintainer(String projectName,
final String username) {
ProjectPermissionsTab projectPermissionsTab =
new BasicWorkFlow().goToHome()
.goToProjects()
.goToProject(projectName)
.gotoSettingsTab()
.gotoSettingsPermissionsTab();
projectPermissionsTab.clickRemoveOn(username)
.waitForMaintainersNotContains(username);
return new ProjectPermissionsTab(driver);
}
}