source: devel/testlink/automation2.0/src/test/java/org/expressolivre/cte/pages/email/MailPage.java @ 4527

Revision 4527, 31.2 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1402 - Novos casos de teste para pesquisa avançada de email

Line 
1package org.expressolivre.cte.pages.email;
2
3import org.apache.commons.lang.StringUtils;
4import org.expressolivre.cte.pages.common.Page;
5import org.openqa.selenium.Alert;
6import org.openqa.selenium.By;
7import org.openqa.selenium.JavascriptExecutor;
8import org.openqa.selenium.RenderedWebElement;
9import org.openqa.selenium.WebDriver;
10import org.openqa.selenium.WebElement;
11import org.openqa.selenium.support.FindBy;
12
13/**
14 * @author L.F.Estivalet (Serpro)
15 *
16 *         Created on Dec 16, 2010 at 9:43:21 AM
17 *
18 */
19public class MailPage extends Page {
20
21        /** Botao para criar novo email. */
22        @FindBy(xpath = "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span")
23        private WebElement newEmail;
24
25        /** Campo "Para:". */
26        @FindBy(id = "to_1")
27        private WebElement to;
28
29        /** Campo "Assunto:". */
30        @FindBy(id = "subject_1")
31        private WebElement subject;
32
33        /** Botao para enviar email. */
34        @FindBy(id = "send_button_1")
35        private WebElement send;
36
37        /** Flag de importante no momento de compor um email. */
38        @FindBy(id = "important_message_1")
39        private WebElement important;
40
41        /** Flag de importante de um email aberto. */
42        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]")
43        private WebElement importantFlag;
44
45        /** Filtra emails importantes. */
46        @FindBy(id = "span_flag_FLAGGED")
47        private WebElement importantFilter;
48
49        /** Filtra emails lidos. */
50        @FindBy(id = "span_flag_SEEN")
51        private WebElement readFilter;
52
53        @FindBy(id = "span_flag_UNSEEN")
54        private WebElement notReadFilter;
55
56        @FindBy(id = "span_flag_ANSWERED")
57        private WebElement answeredFilter;
58
59        /** Flag normal de um email aberto. */
60        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]")
61        private WebElement normalFlag;
62
63        /** Flag nao lido de um email aberto. */
64        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]")
65        private WebElement notReadFlag;
66
67        /** Checkbox de confirmacao de leitura. */
68        @FindBy(id = "return_receipt_1")
69        private WebElement returnReceipt;
70
71        /** Link para acionar exibicao do campo copia oculta Cco. */
72        @FindBy(id = "a_cco_link_1")
73        private WebElement blindCarbonCopyLink;
74
75        /** Campo copia oculta "Cco:". */
76        @FindBy(id = "cco_1")
77        private WebElement blindCarbonCopy;
78
79        /** Link para acionar exibicao do campo copia Cc. */
80        @FindBy(id = "a_cc_link_1")
81        private WebElement carbonCopyLink;
82
83        /** Campo copia "Cc:". */
84        @FindBy(id = "cc_1")
85        private WebElement carbonCopy;
86
87        /** Link para salvar email. */
88        @FindBy(id = "save_message_options_1")
89        private WebElement saveEmail;
90
91        /** Link para adicionar anexos ao email. */
92        @FindBy(linkText = "Anexos: adicionar+")
93        private WebElement attachmentLink;
94
95        /** Link para adicionar 1o anexo. */
96        @FindBy(id = "inputFile_1_1")
97        private WebElement attachment;
98
99        /** Link para adicionar 2o anexo. */
100        @FindBy(id = "inputFile_1_2")
101        private WebElement attachment2;
102
103        /** Link para remover anexo. */
104        @FindBy(id = "linkFile_1_1")
105        private WebElement removeAttachmentLink;
106
107        /** Link para apagar email quando este estiver aberto. */
108        @FindBy(xpath = "//div[@id='footer_menu']/table[@id='footer_box']/tbody/tr[@id='table_message']/td[@id='span_options']/span[1]/span")
109        private WebElement deleteEmailLink;
110
111        @FindBy(xpath = "//div[@id='footer_menu']/table[@id='footer_box']/tbody/tr[@id='table_message']/td[@id='span_options']/span[4]/span")
112        private WebElement exportEmailLink;
113
114        /** Link para pasta lixeira. */
115        @FindBy(id = "lINBOX/Trashtree_folders")
116        private WebElement trashFolder;
117
118        /** Link para limpar lixeira. */
119        @FindBy(id = "empty_trash")
120        private WebElement emptyTrashLink;
121
122        @FindBy(id = "divScrollMain_0")
123        private WebElement emailsListDiv;
124
125        /** Campo contendo total de emails de uma pasta. */
126        @FindBy(id = "tot_m")
127        private WebElement totalEmails;
128
129        @FindBy(xpath = "//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]")
130        private WebElement emailTab;
131
132        /** Checkbox para selecao de todos emails de uma pasta. */
133        @FindBy(id = "chk_box_select_all_messages")
134        private WebElement selectAllEmails;
135
136        /** Link para acionar o menu Ferramentas. */
137        @FindBy(xpath = "//td[@id='link_tools']/div/span")
138        private WebElement toolsMenu;
139
140        @FindBy(xpath = "//div[@id='menu_tools']/table/tbody/tr[4]/td")
141        private WebElement editFolder;
142
143        @FindBy(xpath = "//div[@id='menu_tools']/table/tbody/tr[3]/td")
144        private WebElement editFilter;
145
146        @FindBy(xpath = "//input[@value='Nova Pasta']")
147        private WebElement createNewFolder;
148
149        @FindBy(xpath = "//input[@value='Excluir pasta']")
150        private WebElement deleteFolder;
151
152        @FindBy(xpath = "//input[@value='Renomear pasta']")
153        private WebElement renameFolder;
154
155        @FindBy(xpath = "//span[@onclick='wfolders.makeWindow(\"\",\"move_to\")']")
156        /** Opcao de mover do rodape. */
157        private WebElement moveEmailLink;
158
159        @FindBy(id = "dJSWin_wfolders_bok")
160        private WebElement moveEmailButton;
161
162        /** Link para encaminhar em email aberto. */
163        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]")
164        private WebElement forwardEmail;
165
166        /** Link para responder em email aberto. */
167        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]")
168        private WebElement replyEmail;
169
170        /** Link para responder a todos em email aberto. */
171        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[1]")
172        private WebElement replyAllEmail;
173
174        /** Link para responder sem historico em email aberto. */
175        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[2]")
176        private WebElement replyEmailWithoutHistory;
177
178        /** Link para responder a todos sem historico em email aberto. */
179        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[3]")
180        private WebElement replyAllEmailWithoutHistory;
181
182        /** Link para editar email na pasta de rascunhos. */
183        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]")
184        private WebElement editEmail;
185
186        @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[1]")
187        private WebElement cancelNewEmail;
188
189        @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[2]")
190        private WebElement discardNewEmail;
191
192        /**
193         * Esse botao eh no alerta ao fechar uma mensagem nao salva e nao o botao
194         * salvar para rascunhos.
195         */
196        @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[3]")
197        private WebElement saveNewEmail;
198
199        @FindBy(xpath = "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[1]/td/a[1]")
200        private WebElement searchMessages;
201
202        @FindBy(id = "txt_de")
203        private WebElement searchRemetente;
204
205        @FindBy(id = "txt_para")
206        private WebElement searchTo;
207        @FindBy(id = "txt_cc")
208        private WebElement searchCopy;
209        @FindBy(id = "txt_ass")
210        private WebElement searchSubject;
211        @FindBy(id = "txt_body")
212        private WebElement searchBody;
213        @FindBy(id = "since_date")
214        private WebElement searchSinceDate;
215        @FindBy(id = "before_date")
216        private WebElement searchBeforeDate;
217        @FindBy(id = "on_date")
218        private WebElement searchOnDate;
219        @FindBy(id = "flagged")
220        private WebElement searchImportantFilter;
221        @FindBy(id = "seen")
222        private WebElement searchSeenFilter;
223        @FindBy(id = "answered")
224        private WebElement searchAnsweredFilter;
225        @FindBy(id = "recent")
226        private WebElement searchRecentFilter;
227
228        @FindBy(id = "incluir")
229        private WebElement includeFolderForSearch;
230
231        @FindBy(xpath = "//div[@id='window_search']/div[@id='div_button_search']/table/tbody/tr/td[1]/input")
232        private WebElement searchButton;
233
234        @FindBy(xpath = "//div[@id='window_search']/div[@id='div_button_search']/table/tbody/tr/td[3]/input")
235        private WebElement closeSearchButton;
236
237        /** Nome da pasta "Caixa de Entrada". */
238        public static final String INBOX_FOLDER = "lINBOXtree_folders";
239
240        /** Nome da pasta "Enviados". */
241        public static final String SENT_FOLDER = "lINBOX/Senttree_folders";
242
243        /**
244         * @param driver
245         */
246        public MailPage(WebDriver driver) {
247                super(driver);
248        }
249
250        /**
251         * Cria um novo email.
252         */
253        public void createNewEmail() {
254                this.newEmail.click();
255                waitForElement(By.id("to_1"));
256        }
257
258        /**
259         * Cancela criacao de novo email.
260         */
261        public void cancelNewEmail() {
262                this.cancelNewEmail.click();
263        }
264
265        public void setSearchRemetente(String searchRemetente) {
266                this.searchRemetente.sendKeys(searchRemetente);
267        }
268
269        public void setSearchTo(String searchTo) {
270                this.searchTo.sendKeys(searchTo);
271        }
272
273        public void setSearchCopy(String searchCopy) {
274                this.searchCopy.sendKeys(searchCopy);
275        }
276
277        public void setSearchSubject(String searchSubject) {
278                this.searchSubject.sendKeys(searchSubject);
279        }
280
281        public void setSearchBody(String searchBody) {
282                this.searchBody.sendKeys(searchBody);
283        }
284
285        public void setSearchSinceDate(String searchSinceDate) {
286                this.searchSinceDate.sendKeys(searchSinceDate);
287        }
288
289        public void setSearchBeforeDate(String searchBeforeDate) {
290                this.searchBeforeDate.sendKeys(searchBeforeDate);
291        }
292
293        public void setSearchOnDate(String searchOnDate) {
294                this.searchOnDate.sendKeys(searchOnDate);
295        }
296
297        public void setSearchSeenFilter(String searchSeenFilter) {
298                super.setComboValue(this.searchSeenFilter, searchSeenFilter);
299        }
300
301        public void setSearchAnsweredFilter(String searchAnsweredFilter) {
302                super.setComboValue(this.searchAnsweredFilter, searchAnsweredFilter);
303        }
304
305        public void setSearchRecentFilter(String searchRecentFilter) {
306                super.setComboValue(this.searchRecentFilter, searchRecentFilter);
307        }
308
309        public void openSearchMessageWindow() {
310                this.searchMessages.click();
311                super.waitForElement(By.id("flagged"));
312        }
313
314        /**
315         * Pesquisa apenas mensagens importantes.
316         *
317         * @param flag
318         */
319        public void searchImportantMessage(String flag) {
320                super.setComboValue(searchImportantFilter, flag);
321        }
322
323        /**
324         * Pesquisa apenas mensagens lidas.
325         *
326         * @param flag
327         */
328        public void searchSeenMessage(String flag) {
329                super.setComboValue(searchSeenFilter, flag);
330        }
331
332        /**
333         * Escolhe pastas a serem pesquisadas.
334         *
335         * @param folder
336         */
337        public void setSearchFolders(String folder) {
338                super.clickElement(By.id(folder));
339                includeFolderForSearch.click();
340        }
341
342        public void doSearch() {
343                searchButton.click();
344        }
345
346        public void closeSearchWindow() {
347                closeSearchButton.click();
348        }
349
350        /**
351         * Descarta criacao de novo email.
352         */
353        public void discardNewEmail() {
354                this.discardNewEmail.click();
355        }
356
357        /**
358         * Salva email na pasta rascunhos.
359         */
360        public void saveNewEmail() {
361                this.saveNewEmail.click();
362        }
363
364        /**
365         * Preenche campo assunto.
366         *
367         * @param subject
368         *            Assunto a ser preenchido.
369         */
370        public void setSubject(String subject) {
371                this.subject.sendKeys(subject != null ? subject : "");
372        }
373
374        /**
375         * Preenche corpo (texto) do email.
376         *
377         * @param body
378         *            Texto a ser preenchido.
379         */
380        public void setBody(String body) {
381                // Foi o unico jeito que consegui pegar o richtexteditor...
382                if (body != null) {
383                        // Troca CR&|LF por <br>
384                        body = body.replaceAll("(\r\n|\r|\n|\n\r)", "<br>");
385                        ((JavascriptExecutor) driver)
386                                        .executeScript("document.getElementById('body_1').contentWindow.document.body.innerHTML='"
387                                                        + body + "';");
388                }
389        }
390
391        /**
392         * @param to
393         * @param subject
394         * @param body
395         */
396        public void composeEmail(String to, String subject, String body) {
397                this.createNewEmail();
398                this.to.sendKeys(to);
399                this.setSubject(subject);
400                this.setBody(body);
401        }
402
403        public String readEmail(String subject) {
404                // waitForElementByXpath("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]");
405                String id = findEmailIdBySubject(subject);
406                id = id.substring(id.lastIndexOf("_") + 1);
407                clickElement(By.id("td_who_" + id));
408                super.waitForElement(By.id("div_message_scroll_" + id + "_r"));
409                return id;
410        }
411
412        public void editEmail() {
413                super.waitForElement(By
414                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]"));
415                // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1]
416                this.editEmail.click();
417        }
418
419        public void editEmail(String id) {
420                super.waitForElement(By
421                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]"));
422                // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1]
423                this.editEmail.click();
424                waitForElement(By.id("content_id_" + id));
425        }
426
427        /**
428         * Encaminha uma mensagem.
429         *
430         * @param id
431         *            Id da mensagem a ser encaminhada
432         * @param to
433         *            Destinatario
434         */
435        public void forwardEmail(String id, String to) {
436                super.waitForElement(By
437                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]"));
438                this.forwardEmail.click();
439                super.waitForElement(By.id("to_" + id));
440                driver.findElement(By.id("to_" + id)).sendKeys(to);
441                driver.findElement(By.id("send_button_" + id)).click();
442        }
443
444        /**
445         * Mostra detalhes (cabecalho do email sendo lido).
446         *
447         * @param id
448         */
449        public void showDetails(String id) {
450                driver.findElement(By.id("option_hide_more_" + id + "_r")).click();
451        }
452
453        /**
454         * Remove anexos do email sendo lido.
455         */
456        public void removeAllAttachments() {
457                driver.findElement(
458                                By.xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[2]/td/div[1]/table[1]/tbody/tr[5]/td[2]/a[1]"))
459                                .click();
460                Alert alert = driver.switchTo().alert();
461                assert ("ATENÇÃO: Após a confirmação dessa mensagem, TODOS os anexos da mesma serão apagados. Tenha certeza de que possui uma cópia dos arquivos importantes. Deseja confirmar a operação?"
462                                .equals(alert.getText()));
463                alert.accept();
464        }
465
466        public void blockRecipient(String message) {
467                driver.findElement(
468                                By.xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[2]/td/div[1]/table[1]/tbody/tr[1]/td[1]/span[@id='tt_d']/img"))
469                                .click();
470                // Espera pelo "Carregando..." aparecer.
471                waitForElement(By.id("divProgressBar"));
472                waitForElement(By.id("divScrollMain_0"));
473                // Espera pelo "Carregando..." desaparecer.
474                isNotDisplayed(this
475                                .waitFindElement(By.id("divProgressBar"), 5000, 1000));
476                Alert alert = driver.switchTo().alert();
477                assert (message.equals(alert.getText()));
478                alert.accept();
479        }
480
481        private void reply(String id) {
482                super.waitForElement(By.id("to_" + id));
483                driver.findElement(By.id("send_button_" + id)).click();
484        }
485
486        /**
487         * Responde uma mensagem.
488         *
489         * @param id
490         *            Id da mensagem a ser respondida
491         */
492        public void replyEmail(String id) {
493                super.waitForElement(By
494                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]"));
495                this.replyEmail.click();
496                this.reply(id);
497        }
498
499        /**
500         * Responde uma mensagem.
501         *
502         * @param id
503         *            Id da mensagem a ser respondida
504         */
505        public void replyAllEmailWithoutHistory(String id) {
506                super.findAndClickElement("msg_opt_reply_options_" + id + "_r");
507                super.waitForElement(By
508                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[3]"));
509                this.replyAllEmailWithoutHistory.click();
510                this.reply(id);
511        }
512
513        /**
514         * Responde uma mensagem.
515         *
516         * @param id
517         *            Id da mensagem a ser respondida
518         */
519        public void replyEmailWithoutHistory(String id) {
520                super.findAndClickElement("msg_opt_reply_options_" + id + "_r");
521                super.waitForElement(By
522                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[2]"));
523                this.replyEmailWithoutHistory.click();
524                this.reply(id);
525        }
526
527        /**
528         * Responde uma mensagem.
529         *
530         * @param id
531         *            Id da mensagem a ser respondida
532         */
533        public void replyAllEmail(String id) {
534                super.findAndClickElement("msg_opt_reply_options_" + id + "_r");
535                super.waitForElement(By
536                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[1]"));
537                this.replyAllEmail.click();
538                this.reply(id);
539        }
540
541        /**
542         * Abre uma pasta de email especifica.
543         *
544         * @param folder
545         *            Pasta de email a ser aberta.
546         */
547        public void openFolder(String folder, boolean waitEmail) {
548                waitForElement(By.id(folder));
549                clickElement(By.id(folder));
550                // Espera pelo "Carregando..." aparecer.
551                waitForElement(By.id("divProgressBar"));
552                waitForElement(By.id("divScrollMain_0"));
553                // Espera pelo "Carregando..." desaparecer.
554                isNotDisplayed(this
555                                .waitFindElement(By.id("divProgressBar"), 5000, 1000));
556                if (waitEmail) {
557                        waitForElement(By
558                                        .xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[1]/td[1]/input[1]"));
559                }
560        }
561
562        public void openFolder(String folder) {
563                openFolder(folder, true);
564        }
565
566        /**
567         * Abre uma pasta de email especifica.
568         *
569         * @param folder
570         *            Pasta de email a ser aberta.
571         */
572        public void openFolder(WebElement folder) {
573                folder.click();
574                waitForElement(By.id("divScrollMain_0"));
575        }
576
577        /**
578         * Filtra somente as mensagens importantes.
579         */
580        public void setImportantFilter() {
581                this.importantFilter.click();
582        }
583
584        /**
585         * Filtra somente as mensagens lidas.
586         */
587        public void setReadFilter() {
588                this.readFilter.click();
589        }
590
591        /**
592         * Filtra somente as mensagens nao lidas.
593         */
594        public void setNotReadFilter() {
595                this.notReadFilter.click();
596        }
597
598        /**
599         * Filtra somente as mensagens respondidas.
600         */
601        public void setAnsweredFilter() {
602                this.answeredFilter.click();
603        }
604
605        /**
606         * Limpa a lixeira.
607         */
608        public void cleanupTrash() {
609                this.openFolder(this.trashFolder);
610                this.emptyTrashLink.click();
611        }
612
613        /**
614         * @return Numero de emails na pasta selecionada.
615         */
616        public int getTotalEmails() {
617                return Integer.valueOf(this.totalEmails.getText());
618        }
619
620        /**
621         * Move email para um pasta no servidor.
622         *
623         * @param folderName
624         *            Nome da pasta pre-existente no servidor.
625         */
626        public void moveEmail(String folderName) {
627                this.moveEmailLink.click();
628                super.findAndClickElement("lINBOX/" + folderName + "wfolders_tree");
629                this.moveEmailButton.click();
630        }
631
632        /**
633         * Edita nome de pasta.
634         */
635        public void editFolder() {
636                this.toolsMenu.click();
637                this.waitForElement(By
638                                .xpath("//div[@id='menu_tools']/table/tbody/tr[4]/td"));
639                this.editFolder.click();
640        }
641
642        /**
643         * Edita filtros.
644         */
645        public void editFilter() {
646                this.toolsMenu.click();
647                this.waitForElement(By
648                                .xpath("//div[@id='menu_tools']/table/tbody/tr[3]/td"));
649                this.editFilter.click();
650        }
651
652        /**
653         * Apaga uma regra do filtro.
654         *
655         * @param id
656         */
657        public void deleteRule(int id) {
658                this.waitForElement(By.id("rule_" + id));
659                driver.findElement(By.id("rule_" + id)).click();
660                driver.findElement(By.xpath("//div[@id='form_buttons']/input[3]"))
661                                .click();
662                driver.findElement(By.xpath("//div[@id='form_buttons']/input[4]"))
663                                .click();
664        }
665
666        /**
667         * Cria nova pasta.
668         *
669         * @param folderName
670         *            Nome da pasta a ser criada.
671         */
672        public void createNewFolder(String folderName) {
673                this.editFolder();
674                this.createFolder(folderName);
675        }
676
677        private void createFolder(String folderName) {
678                this.createNewFolder.click();
679                Alert newFolder = driver.switchTo().alert();
680                assert "Insira o nome da nova pasta: ".equals(newFolder.getText());
681                newFolder.sendKeys(folderName);
682                newFolder.accept();
683        }
684
685        /**
686         * Cria sub pasta.
687         *
688         * @param rootFolderName
689         *            Pasta pai.
690         * @param subFolderName
691         *            Nome da sub pasta a ser criada.
692         */
693        public void createSubFolder(String rootFolderName, String subFolderName) {
694                this.editFolder();
695                this.driver.findElement(
696                                By.id("lINBOX/" + rootFolderName + "folders_tree")).click();
697                this.createFolder(subFolderName);
698        }
699
700        /**
701         * Renomeia pasta.
702         *
703         * @param folderName
704         *            Nome da pasta a ser renomeada.
705         * @param newName
706         *            Novo nome da pasta.
707         */
708        public void renameFolder(String folderName, String newName) {
709                this.editFolder();
710                this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree"))
711                                .click();
712                this.renameFolder.click();
713                Alert newFolder = driver.switchTo().alert();
714                assert "Entre com um nome para a pasta:".equals(newFolder.getText());
715                newFolder.sendKeys(newName);
716                newFolder.accept();
717        }
718
719        /**
720         * @param folderName
721         */
722        public void renameFolderInUse(String folderName) {
723                this.editFolder();
724                this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree"))
725                                .click();
726                this.renameFolder.click();
727                Alert newFolder = driver.switchTo().alert();
728                assert "Não é possível renomear esta pasta, pois está em uso no momento!"
729                                .equals(newFolder.getText());
730                newFolder.accept();
731        }
732
733        /**
734         * Exclui pasta.
735         *
736         * @param folderName
737         *            Nome da pasta a ser excluida.
738         */
739        public void deleteFolder(String folderName) {
740                this.editFolder();
741                this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree"))
742                                .click();
743                this.deleteFolder.click();
744        }
745
746        /**
747         * Exclui pasta.
748         *
749         * @param folderName
750         *            Nome da pasta a ser excluida.
751         */
752        public void deleteFolder(String folderName, boolean inUse) {
753                this.editFolder();
754                this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree"))
755                                .click();
756                this.deleteFolder.click();
757                Alert confirm = driver.switchTo().alert();
758                if (!inUse) {
759                        assert ("Você gostaria de excluir a pasta: " + folderName + "?")
760                                        .equals(confirm.getText());
761                } else {
762                        assert ("Não é possível remover esta pasta, pois está em uso no momento!")
763                                        .equals(confirm.getText());
764                }
765                confirm.accept();
766        }
767
768        /**
769         * Exclui pasta.
770         *
771         * @param folderName
772         *            Nome da pasta a ser excluida.
773         */
774        public void deleteSubFolder(String rootFolderName, String subFolderName) {
775                this.editFolder();
776                this.driver.findElement(
777                                By.id("pINBOX/" + rootFolderName + "folders_tree")).click();
778                this.driver.findElement(
779                                By.id("lINBOX/" + rootFolderName + "/" + subFolderName
780                                                + "folders_tree")).click();
781                this.deleteFolder.click();
782                Alert confirm = driver.switchTo().alert();
783                assert ("Você gostaria de excluir a pasta: " + subFolderName + "?")
784                                .equals(confirm.getText());
785                confirm.accept();
786        }
787
788        /**
789         * Marca email sendo composto como importante.
790         */
791        public void checkImportantFlag() {
792                this.important.click();
793        }
794
795        /**
796         * Marca email como importante apos ler.
797         */
798        public void setImportantFlag() {
799                this.waitForElement(By
800                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"));
801                this.importantFlag.click();
802        }
803
804        /**
805         * Marca email como normal apos ler.
806         */
807        public void setNormalFlag() {
808                this.waitForElement(By
809                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"));
810                this.normalFlag.click();
811        }
812
813        /**
814         * Marca email como nao lido apos ler.
815         */
816        public void setNotReadFlag() {
817                this.waitForElement(By
818                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]"));
819                this.notReadFlag.click();
820        }
821
822        /**
823         * Marca solicitacao de confirmacao de leitura do email sendo composto.
824         */
825        public void checkReturnReceipt() {
826                this.returnReceipt.click();
827        }
828
829        /**
830         * Salva email sendo composto (devera ir para a pasta de Rascunhos).
831         *
832         * TODO adicionar teste para verificar se o email realmente esta presente na
833         * pasta Rascunhos??
834         */
835        public void saveEmail() {
836                this.saveEmail.click();
837        }
838
839        /**
840         * Apaga email previamente selecionado.
841         */
842        public void deleteEmail() {
843                this.deleteEmailLink.click();
844        }
845
846        /**
847         * Exporta email previamente selecionado.
848         */
849        public void exportEmail() {
850                this.exportEmailLink.click();
851        }
852
853        /**
854         * Seleciona todos emails da pasta corrente.
855         */
856        public void selectAllEmails() {
857                this.selectAllEmails.click();
858        }
859
860        /**
861         * Adiciona email no campo de copia oculta.
862         *
863         * @param email
864         *            Email a ser adicionado.
865         */
866        public void setBlindCarbonCopy(String email) {
867                this.blindCarbonCopyLink.click();
868                this.blindCarbonCopy.sendKeys(email);
869        }
870
871        /**
872         * Adiciona email no campo de copia.
873         *
874         * @param email
875         *            Email a ser adicionado.
876         */
877        public void setCarbonCopy(String email) {
878                this.carbonCopyLink.click();
879                this.carbonCopy.sendKeys(email);
880        }
881
882        /**
883         * Anexo um arquivo no email sendo composto.
884         *
885         * @param attachment
886         *            Caminho para o arquivo a ser anexado.
887         */
888        public void addAttachment(String attachment) {
889                this.attachmentLink.click();
890                this.attachment.sendKeys(attachment);
891        }
892
893        /**
894         * Remove anexo do email sendo composto.
895         */
896        public void removeAttachment() {
897                this.removeAttachmentLink.click();
898        }
899
900        public void addAttachment2(String attachment) {
901                this.attachmentLink.click();
902                this.attachment2.sendKeys(attachment);
903        }
904
905        /**
906         * Envia email sendo composto.
907         */
908        public void sendMail() {
909                this.send.click();
910        }
911
912        /**
913         * Fecha aba do email sendo composto e confirma que email nao esta salvo.
914         */
915        public void closeMail() {
916                this.closeMail(true);
917        }
918
919        /**
920         * @param discardEmail
921         */
922        public void closeMail(boolean discardEmail) {
923
924                // Na versao Serpro:
925                // td[@id='border_id_1']/table/tbody/tr/td[2]/img
926
927                // Na versao Comunidade:
928                // td[@id='border_id_1']/div/div[2]/img
929
930                // Resolvi usando o xpath abaixo:
931                super.clickElement(By.xpath("//td[@id='border_id_1']//img"));
932
933                // if (checkAlert) {
934                // Alert closeAlert = driver.switchTo().alert();
935                // closeAlert.accept();
936                // }
937
938                // Clica em descartar.
939                if (discardEmail) {
940                        super.clickElement(By
941                                        .xpath("//div[@id='lertWindow']/div[@id='lertButtons']/a[2]"));
942                }
943        }
944
945        public void closeMail(String id, boolean discardEmail) {
946                super.clickElement(By.xpath("//td[@id='border_id_" + id + "']//img"));
947                // Clica em cancelar
948                if (discardEmail) {
949                        super.clickElement(By
950                                        .xpath("//div[@id='lertWindow']/div[@id='lertButtons']/a[2]"));
951                }
952        }
953
954        /**
955         * Envia email.
956         *
957         * @param id
958         *            Id do email a ser enviado.
959         */
960        public void sendMail(String id) {
961                super.findAndClickElement("send_button_" + id);
962        }
963
964        /**
965         * @param to
966         * @param subject
967         */
968        public void composeEmail(String to, String subject) {
969                composeEmail(to, subject, null);
970        }
971
972        /**
973         * @param to
974         */
975        public void composeEmail(String to) {
976                composeEmail(to, null, null);
977        }
978
979        /**
980         * Procura um email pelo assunto.
981         *
982         * @param subject
983         *            Assunto a ser procurado.
984         * @param select
985         *            Se email encontrado, deseja seleciona-lo?
986         * @return "id" do email se encontrar, <code>null</code> se nao encontrar.
987         */
988        public String findEmailIdBySuject(String subject, boolean select) {
989                // System.out.println("searching for --------->" + subject);
990                String html = driver.getPageSource();
991                // System.out.println(html.indexOf(subject));
992                // System.out.println(html);
993                if (html.indexOf(subject) >= 0) {
994                        String part1 = StringUtils.substringBefore(html, subject);
995                        int start = StringUtils.lastIndexOf(part1, "id=\"") + 4;
996                        int last = StringUtils.indexOf(part1, "\"", start);
997                        String id = StringUtils.substring(part1, start, last);
998                        // System.out.println(id);
999                        if (select) {
1000                                // Marca checkbox correspondente ao id da mensagem.
1001                                clickElement(By.id("check_box" + id.substring(1)));
1002                        }
1003                        return id;
1004                }
1005                System.out.println("email not found");
1006                return null;
1007        }
1008
1009        /**
1010         * @return Ids de todos os emails da pasta selecionada.
1011         */
1012        public String[] getEmailIds() {
1013                String[] ids = new String[this.getTotalEmails()];
1014                for (int i = 1; i <= this.getTotalEmails(); i++) {
1015                        String id = driver
1016                                        .findElement(
1017                                                        By.xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr["
1018                                                                        + i + "]/td[1]/input[1]")).getAttribute(
1019                                                        "id");
1020                        ids[i - 1] = id.substring(id.lastIndexOf("_") + 1);
1021                }
1022                return ids;
1023        }
1024
1025        /**
1026         * @param emailId
1027         *            Id do email.
1028         * @return <code>true</code> se email importante, <code>false</code> caso
1029         *         contrario.
1030         */
1031        public boolean isImportant(String emailId) {
1032                return super
1033                                .isDisplayed((RenderedWebElement) driver.findElement(By
1034                                                .xpath("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='"
1035                                                                + emailId + "']/td[5]/img")));
1036        }
1037
1038        /**
1039         * @param emailId
1040         *            Id do email.
1041         * @return <code>true</code> se email lido, <code>false</code> caso
1042         *         contrario.
1043         */
1044        public boolean isRead(String emailId) {
1045                return super
1046                                .isDisplayed((RenderedWebElement) driver.findElement(By
1047                                                .xpath("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='"
1048                                                                + emailId
1049                                                                + "']/td[@id='td_message_unseen_"
1050                                                                + emailId + "']/img")));
1051        }
1052
1053        /**
1054         * @param emailId
1055         *            Id do email.
1056         * @return <code>true</code> se email nao lido, <code>false</code> caso
1057         *         contrario.
1058         */
1059        public boolean isNotRead(String emailId) {
1060                return super
1061                                .isDisplayed((RenderedWebElement) driver.findElement(By
1062                                                .xpath("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='"
1063                                                                + emailId
1064                                                                + "']/td[@id='td_message_unseen_"
1065                                                                + emailId + "']/img")));
1066        }
1067
1068        /**
1069         * @param emailId
1070         *            Id do email.
1071         * @return <code>true</code> se email respondido, <code>false</code> caso
1072         *         contrario.
1073         */
1074        public boolean isAnswered(String emailId) {
1075                return super
1076                                .isDisplayed((RenderedWebElement) driver.findElement(By
1077                                                .xpath("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='"
1078                                                                + emailId
1079                                                                + "']/td[@id='td_message_answered_"
1080                                                                + emailId + "']/img")));
1081        }
1082
1083        /**
1084         * Procura email baseado no assunto na pasta corrente.
1085         *
1086         * @param subject
1087         *            Assunto a ser pesquisado.
1088         * @return Id do email encontrado.
1089         */
1090        public String findEmailIdBySubject(String subject) {
1091                return findEmailIdBySuject(subject, false);
1092        }
1093
1094        /**
1095         * Procura email baseado no assunto em uma pasta especifica.
1096         *
1097         * @param folder
1098         *            Pasta de pesquisa.
1099         * @param subject
1100         *            Assunto a ser pesquisado.
1101         * @return Id do email encontrado.
1102         */
1103        public String findEmailIdBySubject(String folder, String subject) {
1104                this.openFolder(folder);
1105                return findEmailIdBySuject(subject, false);
1106        }
1107
1108        /**
1109         * Verifica se mensagem informada corresponde ao exibido pelo Expresso na
1110         * div onde sao exibidas mensagens ao usuario.
1111         *
1112         * @param message
1113         *            Mensagem a ser validada.
1114         */
1115        public void assertMessage(String message) {
1116                assert message.equals(getDisplayedElementContent("em_div_write_msg"));
1117        }
1118
1119        /**
1120         * @return the to
1121         */
1122        public WebElement getTo(String id) {
1123                waitForElement(By.id("to_" + id));
1124                // findAndClickElement("to_" + id);
1125                // return getDisplayedElementContent(id);
1126                return driver.findElement(By.id("to_" + id));
1127        }
1128
1129        /**
1130         * @return the subject
1131         */
1132        public WebElement getSubject(String id) {
1133                waitForElement(By.id("subject_" + id));
1134                return driver.findElement(By.id("subject_" + id));
1135        }
1136
1137        /**
1138         * @return the blindCarbonCopy
1139         */
1140        public WebElement getBlindCarbonCopy(String id) {
1141                waitForElement(By.id("cco_" + id));
1142                return driver.findElement(By.id("cco_" + id));
1143        }
1144
1145        /**
1146         * @return the carbonCopy
1147         */
1148        public WebElement getCarbonCopy(String id) {
1149                waitForElement(By.id("cc_" + id));
1150                return driver.findElement(By.id("cc_" + id));
1151        }
1152
1153        /**
1154         * @param id
1155         *            Id do email.
1156         * @return Texto do email.
1157         */
1158        public Object getBody(String id) {
1159                waitForElement(By.id("body_" + id));
1160                return ((JavascriptExecutor) driver)
1161                                .executeScript("return document.getElementById('body_" + id
1162                                                + "').contentWindow.document.body.innerHTML;");
1163        }
1164
1165}
Note: See TracBrowser for help on using the repository browser.