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

Revision 4620, 24.6 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1771 - Refactoring, criadas novas classes para Pasta, Filtro, Pesquisa

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