Statistics
| Branch: | Tag: | Revision:

root / test / gr / ebs / gss / client / selenium / folder / FolderUtils.java @ 67a0315c

History | View | Annotate | Download (8.1 kB)

1
/*
2
 * Copyright 2011 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.client.selenium.folder;
20

    
21
import org.junit.After;
22
import org.junit.Before;
23
import org.openqa.selenium.By;
24
import org.openqa.selenium.WebDriver;
25
import org.openqa.selenium.firefox.FirefoxDriver;
26

    
27

    
28

    
29
/**
30
 * @author natasa
31
 *
32
 */
33
public class FolderUtils {
34
        
35
        public ActionUtils action;
36
        
37
        public WebDriver driver;
38
        
39
        protected String url = "http://127.0.0.1:8080/pithos/login?next=http://127.0.0.1:8080/pithos/";
40
        
41
        public String folderName = "Alderaan";
42
        
43
        public String userName = "lakis@ebs.gr";
44
                //"past@ebs.gr";
45
        
46
        protected String folderDestination = "Naboo";
47
        
48
        protected String newFolderName = "Mustafar";
49

    
50
        /**
51
         * Initialize the driver, the actionUtils, the application's url
52
         * @throws java.lang.Exception
53
         */
54
        @Before
55
        public void setUp() throws Exception {
56
                
57
                driver = new FirefoxDriver();
58
                
59
                action = new ActionUtils(driver);
60
                
61
                action.getUrl(url);
62
                
63
                // Necessary delay in order all dom elements to be created
64
                Thread.sleep(3000);
65
        }
66

    
67
        /**
68
         * Quit the driver
69
         * @throws java.lang.Exception
70
         */
71
        @After
72
        public void tearDown() throws Exception {
73
                action.quit();
74
        }
75
        
76
        /**
77
         * Select the user's home folder
78
         * 
79
         * @param aUserName
80
         */
81
        protected void selectHomeFolder(String aUserName){
82
                action.click(By.id(aUserName));
83
        }
84
        
85
        /**
86
         * Select any folder below the user's home folder
87
         * 
88
         * @param aUserName
89
         * @param aFolderName
90
         */
91
        public void selectFolderBelowHome(String aUserName, String aFolderName){
92
                action.click(By.id(aUserName+ "." + aFolderName));
93
        }
94
        
95
        /**
96
         * Select the Trash folder
97
         */
98
        protected void selectTrash(){
99
                action.click(By.id("Trash"));                
100
        }
101
        
102
        /**
103
         * Select the My Shared folder
104
         */
105
        protected void selectMyShared(){
106
                action.click(By.id("My Shared"));
107
        }
108
        
109
        /**
110
         * Select the Other's Shared folder
111
         */
112
        protected void selectOthersShared(){
113
                action.click(By.id("others"));
114
        }
115
        
116
        protected void expandTree(){
117
//                ERROR: Compound class names are not supported. Consider searching for one class name and filtering the results.
118
//                action.click(By.className("GK31MSKBDF GK31MSKBLF"));
119
//                action.click(By.xpath("//span[@id='Trash']/../../.."));
120
//                action.click(By.xpath("//div[@id='']/img"));
121
//                action.click(By.xpath("//span[@id='Trash']/.."));
122
//                action.click(By.xpath("ancestor:://span[@id='Trash']"));// Error not legal expression
123
//                action.click(By.xpath("//div[@class='GK31MSKBCF GK31MSKBKF gwtQuery-draggable gwtQuery-droppable']"));
124
                action.click(By.xpath("/html/body/table/tbody/tr[4]/td/div/div/div/div/div/div/div/div[2]/div/div"));
125
                //selenium.click("//*/img[contains(@src,'telpfeil.gif')]");
126
//                return action.clickAndSendText(By.xpath("//span[@id='Trash']/.."));
127
                
128
        }
129
        
130
        
131
        /**
132
         * Create a new folder under the root folder
133
         * @param aFolderName
134
         * @throws InterruptedException 
135
         */        
136
        protected void makeNewFolder(String aUserName, String aFolderName) throws InterruptedException{                
137
                //Click the home folder
138
                selectHomeFolder(aUserName);
139
                                
140
                //Click the top file menu
141
                action.click(By.id("topMenu.file"));                
142
                
143
                Thread.sleep(1000);
144
                
145
                //Click the New Folder option from the file menu
146
                action.click(By.id("topMenu.file.newFolder"));
147
                
148
                Thread.sleep(1000);
149
                
150
                //In the popup dialog click on the Name textBox and type the folder name                
151
                action.type(By.id("folderPropertiesDialog.textBox.name"), aFolderName);
152
                        
153
                //Submit 
154
                action.click(By.id("folderPropertiesDialog.button.ok"));                        
155
                
156
        }
157
        
158
        /**
159
         * Delete a folder with the given folderName 
160
         * that lies below the root folder 
161
         * 
162
         * @param aFolderName
163
         * @throws InterruptedException 
164
         */        
165
        protected void deleteFolder(String aUserName, String aFolderName) throws InterruptedException{
166
                //Click the home folder                
167
                selectFolderBelowHome(aUserName, aFolderName);
168
                
169
                //Click top edit menu
170
                action.click(By.id("topMenu.edit"));
171
                
172
                                        
173
                //Click move to trash option
174
                action.click(By.id("topMenu.edit.delete"));
175
                Thread.sleep(1000);
176
                
177
                //Click ok button in the confirmation dialog box
178
                action.click(By.id("confirmation.ok"));
179
        
180
        }
181
        /**
182
         * Moving a folder which lies under the root folder to trash folder
183
         * 
184
         * @param aFolderName
185
         */        
186
        protected void moveToTrash(String aUserName, String aFolderName){
187
                //Click the home folder
188
                selectFolderBelowHome(aUserName, aFolderName);
189
                
190
                //Click top edit menu
191
                action.click(By.id("topMenu.edit"));
192
                
193
                //Click move to trash option
194
                action.click(By.id("topMenu.edit.moveToTrash"));
195
                
196
        }
197
        
198
        /**
199
         * Emptying the trash folder using right click action
200
         * 
201
         * @throws InterruptedException
202
         */        
203
        protected void emptyTrash() throws InterruptedException{
204
                
205
                selectTrash();
206
                
207
                Thread.sleep(1000);
208
                
209
                action.click(By.id("topMenu.file"));
210
                
211
                Thread.sleep(1000);
212
                
213
                action.click(By.id("topMenu.file.emptyTrash"));
214

    
215
                /**
216
                 * TODO: Examine right click on a folder
217
                 */
218
                
219
//                action.sendRightClick(By.id("Trash"));
220
                
221
                //Select emptyTrash from context menu
222
//                action.click(By.id("folderContextMenu.emptyTrash"));
223

    
224
        }
225
        
226
        protected void refresh(String aUserName, String aFolderName){                
227
                //Click a folder
228
                selectFolderBelowHome(aUserName, aFolderName);
229
                
230
                //Click top edit menu
231
                action.click(By.id("topMenu.file"));
232
                
233
                //Click move to trash option
234
                action.click(By.id("topMenu.file.refresh"));
235
                
236
        }
237
        
238
        //TODO: upload file to a folder
239
        protected void upload(){
240
                
241
        }
242
        
243
        /**
244
         * Method that cuts a folder below home folder
245
         * using the top Edit menu
246
         * @param aUserName
247
         */
248
        protected void cutFolder(String aUserName, String aFolderName){
249
                
250
                //Click a folder
251
                selectFolderBelowHome(aUserName, aFolderName);
252
                                
253
                //Click the top file menu
254
                action.click(By.id("topMenu.edit"));                
255
                
256
                //Click the New Folder option from the file menu
257
                action.click(By.id("topMenu.edit.cut"));
258
                
259
        }
260
        
261
        /**
262
         * Method that copies a folder name 
263
         * @param aUserName
264
         * @param aFolderName
265
         */
266
        protected void copy(String aUserName, String aFolderName){
267
                //Click a folder
268
                selectFolderBelowHome(aUserName, aFolderName);
269
                                
270
                //Click the top file menu
271
                action.click(By.id("topMenu.edit"));                
272
                
273
                //Click the New Folder option from the file menu
274
                action.click(By.id("topMenu.edit.copy"));
275
                
276
        }
277
        
278
        /**
279
         * Method that pastes a folder of a user using @param aUserName
280
         * to a        @param aFolderDestination
281
         */
282
        protected void paste(String aUserName, String aFolderDestination){
283
                //Click on the folder destination which is below home folder
284
                selectFolderBelowHome(aUserName, aFolderDestination);
285
                
286
                //Click the top file menu
287
                action.click(By.id("topMenu.edit"));                
288
                
289
                //Click the New Folder option from the file menu
290
                action.click(By.id("topMenu.edit.paste"));
291
        }
292
        
293
        /**
294
         * Method that clicks on the folder and the from the top menu File > Properties
295
         * 
296
         * @param aUserName
297
         * @param aFolderName
298
         * @throws InterruptedException
299
         */
300
        protected void clickFolderProperties(String aUserName, String aFolderName) throws InterruptedException{
301
                //Click on a folder 
302
                selectFolderBelowHome(aUserName, aFolderName);
303
                                
304
                action.click(By.id("topMenu.file"));
305
                Thread.sleep(1000);
306
                action.click(By.id("topMenu.file.properties"));
307
                Thread.sleep(1000);
308
        }
309
        
310
        /**
311
         * Methods thats sends right click to the selected folder
312
         * @param aUserName
313
         * @param aFolderName
314
         */
315
        
316
        protected void rightClickOnFolder(String aUserName, String aFolderName){
317
                //Click on a folder 
318
                selectFolderBelowHome(aUserName, aFolderName);
319
                
320
                action.sendRightClick(By.id(aUserName+ "." + aFolderName));
321
                
322
        }
323
        
324
        protected void selectFolderContextMenuOption(String anOption){
325
                action.click(By.id("folderContextMenu." + anOption));
326
        }
327
        
328

    
329

    
330
}