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

Revision 4962, 27.1 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1771 - Adicionado testes automatizados para modulo da agenda

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