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

Revision 4627, 25.0 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1771 - Modificacoes feitas em nomes de classes e metodos

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