forked from cucumber/cucumber-java-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLinksSteps.java
197 lines (183 loc) · 7.85 KB
/
LinksSteps.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
/**
* ownCloud Android Scenario Tests
*
* @author Jesús Recio Rincón (@jesmrec)
*/
package io.cucumber;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.logging.Level;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.ParameterType;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import utils.entities.OCShare;
import utils.log.Log;
public class LinksSteps {
private World world;
public LinksSteps(World world) {
this.world = world;
}
@ParameterType("item|file|folder")
public String itemtype(String type) {
return type;
}
@Given("{word} has shared the {itemtype} {word} by link")
public void user_has_shared_the_item_by_link(String sharingUser, String type, String itemName)
throws Throwable {
String stepName = new Object() {}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.shareAPI.createShare(sharingUser, itemName, "", "3", "1", itemName, "aa55AA.." + " link", 0);
}
@When("Alice creates link on {word} {word} with the following fields")
public void user_creates_link_with_fields(String type, String itemName, DataTable table) {
String stepName = new Object() {}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.sharePage.addPublicLink();
List<List<String>> listItems = table.asLists();
for (List<String> rows : listItems) {
switch (rows.get(0)) {
case "name": {
world.publicLinksPage.addLinkName(rows.get(1));
break;
}
case "password": {
world.publicLinksPage.typePassword(itemName, rows.get(1));
break;
}
case "password-auto": {
world.publicLinksPage.generatePassword();
break;
}
case "permission": {
world.publicLinksPage.setPermission(rows.get(1));
break;
}
case "expiration days": {
world.publicLinksPage.setExpiration(rows.get(1));
break;
}
default:
break;
}
}
world.publicLinksPage.submitLink();
}
@When("Alice edits the link on {word} with the following fields")
public void user_edits_public_link_with_fields(String itemName, DataTable table) {
String stepName = new Object() {}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
List<List<String>> listItems = table.asLists();
world.sharePage.openPublicLink(itemName);
for (List<String> rows : listItems) {
switch (rows.get(0)) {
case "name": {
world.publicLinksPage.addLinkName(rows.get(1));
break;
}
case "permissions": {
switch (rows.get(1)) {
case ("1"): { //Download / View
Log.log(Level.FINE, "Select Download / View");
world.publicLinksPage.selectDownloadView();
break;
}
case ("15"): { //Download / View / Upload
Log.log(Level.FINE, "Select Download / View / Upload");
world.publicLinksPage.selectDownloadViewUpload();
break;
}
case ("4"): { //Upload Only (File Drop)
Log.log(Level.FINE, "Select Upload Only (File Drop)");
world.publicLinksPage.selectUploadOnly();
break;
}
default:
break;
}
break;
}
case "password": {
world.publicLinksPage.typePassword(itemName, rows.get(1));
break;
}
case "expiration days": {
world.publicLinksPage.setExpiration(rows.get(1));
break;
}
default:
break;
}
}
world.publicLinksPage.submitLink();
}
@When("Alice deletes the link on {word}")
public void user_deletes_link(String itemName) {
String stepName = new Object() {}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
world.sharePage.deletePublicShare();
world.sharePage.acceptDeletion();
}
@Then("link should be created/edited on {word} with the following fields")
public void link_should_be_created_with_fields(String itemName, DataTable table)
throws Throwable {
String stepName = new Object() {}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
//Asserts in UI
Log.log(Level.FINE, "Checking UI asserts");
List<List<String>> listItems = table.asLists();
for (List<String> rows : listItems) {
switch (rows.get(0)) {
case "name": {
Log.log(Level.FINE, "Checking name: " + rows.get(1));
assertTrue(world.sharePage.isItemInListPublicShares(rows.get(1)));
break;
}
case "password-auto":
case "password": {
world.sharePage.openPublicLink(itemName);
assertTrue(world.publicLinksPage.isPasswordEnabled());
world.publicLinksPage.close();
break;
}
case "user": {
Log.log(Level.FINE, "checking user: " + itemName);
assertTrue(world.sharePage.isItemInListPublicShares(itemName));
break;
}
case "permission": {
Log.log(Level.FINE, "checking permissions: " + rows.get(1));
world.sharePage.openPublicLink(itemName);
assertTrue(world.publicLinksPage.arePermissionsCorrect(rows.get(1)));
world.publicLinksPage.close();
break;
}
case "expiration days": {
Log.log(Level.FINE, "checking expirations day: " + rows.get(1));
world.sharePage.openPublicLink(itemName);
assertTrue(world.publicLinksPage.isExpirationCorrect(rows.get(1)));
world.publicLinksPage.close();
break;
}
default:
break;
}
}
//Asserts in server via API
Log.log(Level.FINE, "Checking API/server asserts");
OCShare share = world.shareAPI.getShare(itemName);
assertTrue(world.sharePage.isShareCorrect(share, listItems));
}
@Then("link on {word} should not exist anymore")
public void link_should_not_exist_anymore(String itemName)
throws Throwable {
String stepName = new Object() {}.getClass().getEnclosingMethod().getName().toUpperCase();
Log.log(Level.FINE, "----STEP----: " + stepName);
Log.log(Level.FINE, "Checking if item exists: " + itemName);
assertTrue(world.sharePage.isListPublicLinksEmpty());
assertTrue(world.shareAPI.getLinksByDefault().isEmpty());
assertFalse(world.sharePage.isItemInListPublicShares(itemName + " link"));
}
}