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

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