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

Revision 3799, 16.1 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1402 - Novos casos de teste para Salvar Email no Rascunho

Line 
1package org.expressolivre.cte.pages.email;
2
3import org.apache.commons.lang.StringUtils;
4import org.expressolivre.cte.pages.common.Page;
5import org.openqa.selenium.Alert;
6import org.openqa.selenium.By;
7import org.openqa.selenium.JavascriptExecutor;
8import org.openqa.selenium.RenderedWebElement;
9import org.openqa.selenium.WebDriver;
10import org.openqa.selenium.WebElement;
11import org.openqa.selenium.support.FindBy;
12
13/**
14 * @author L.F.Estivalet (Serpro)
15 *
16 *         Created on Dec 16, 2010 at 9:43:21 AM
17 *
18 */
19public class MailPage extends Page {
20
21        @FindBy(xpath = "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span")
22        private WebElement newEmail;
23
24        @FindBy(id = "to_1")
25        private WebElement to;
26
27        @FindBy(id = "subject_1")
28        private WebElement subject;
29
30        @FindBy(id = "send_button_1")
31        private WebElement send;
32
33        @FindBy(id = "important_message_1")
34        /** Flag de importante no momento de compor um email. */
35        private WebElement important;
36
37        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]")
38        /** Flag de importante de um email aberto. */
39        private WebElement importantFlag;
40
41        @FindBy(id = "span_flag_FLAGGED")
42        /** Filtra emails importantes. */
43        private WebElement importantFilter;
44
45        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]")
46        private WebElement normalFlag;
47
48        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]")
49        private WebElement notReadFlag;
50
51        @FindBy(id = "return_receipt_1")
52        private WebElement returnReceipt;
53
54        @FindBy(id = "a_cco_link_1")
55        private WebElement blindCarbonCopyLink;
56
57        @FindBy(id = "cco_1")
58        private WebElement blindCarbonCopy;
59
60        @FindBy(id = "a_cc_link_1")
61        private WebElement carbonCopyLink;
62
63        @FindBy(id = "cc_1")
64        private WebElement carbonCopy;
65
66        @FindBy(id = "save_message_options_1")
67        private WebElement saveEmail;
68
69        @FindBy(linkText = "Anexos: adicionar+")
70        private WebElement attachmentLink;
71
72        @FindBy(id = "inputFile_1_1")
73        private WebElement attachment;
74
75        @FindBy(id = "inputFile_1_2")
76        private WebElement attachment2;
77
78        @FindBy(xpath = "//div[@id='footer_menu']/table[@id='footer_box']/tbody/tr[@id='table_message']/td[@id='span_options']/span[1]/span")
79        private WebElement deleteEmailLink;
80
81        @FindBy(id = "lINBOX/Trashtree_folders")
82        private WebElement trashFolder;
83
84        @FindBy(id = "empty_trash")
85        private WebElement emptyTrashLink;
86
87        @FindBy(id = "divScrollMain_0")
88        private WebElement emailsListDiv;
89
90        @FindBy(id = "tot_m")
91        private WebElement totalEmails;
92
93        @FindBy(xpath = "//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]")
94        private WebElement emailTab;
95
96        @FindBy(id = "chk_box_select_all_messages")
97        private WebElement selectAllEmails;
98
99        @FindBy(xpath = "//td[@id='link_tools']/div/span")
100        private WebElement toolsMenu;
101
102        @FindBy(xpath = "//div[@id='menu_tools']/table/tbody/tr[4]/td")
103        private WebElement editFolder;
104
105        @FindBy(xpath = "//input[@value='Nova Pasta']")
106        private WebElement createNewFolder;
107
108        @FindBy(xpath = "//input[@value='Excluir pasta']")
109        private WebElement deleteFolder;
110
111        @FindBy(xpath = "//span[@onclick='wfolders.makeWindow(\"\",\"move_to\")']")
112        /** Opcao de mover do rodape. */
113        private WebElement moveEmailLink;
114
115        @FindBy(id = "dJSWin_wfolders_bok")
116        private WebElement moveEmailButton;
117
118        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]")
119        private WebElement forwardEmail;
120
121        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]")
122        private WebElement replyEmail;
123
124        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[1]")
125        private WebElement replyAllEmail;
126
127        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[2]")
128        private WebElement replyEmailWithoutHistory;
129
130        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[3]")
131        private WebElement replyAllEmailWithoutHistory;
132
133        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]")
134        private WebElement editEmail;
135
136        /**
137         * @param driver
138         */
139        public MailPage(WebDriver driver) {
140                super(driver);
141        }
142
143        public void createNewEmail() {
144                this.newEmail.click();
145                waitForElement(By.id("to_1"));
146        }
147
148        public void setSubject(String subject) {
149                this.subject.sendKeys(subject != null ? subject : "");
150        }
151
152        public void setBody(String body) {
153                // Foi o unico jeito que consegui pegar o richtexteditor...
154                if (body != null) {
155                        ((JavascriptExecutor) driver)
156                                        .executeScript("document.getElementById('body_1').contentWindow.document.body.innerHTML='"
157                                                        + body + "';");
158                }
159        }
160
161        /**
162         * @param to
163         * @param subject
164         * @param body
165         */
166        public void composeEmail(String to, String subject, String body) {
167                this.createNewEmail();
168                this.to.sendKeys(to);
169                this.setSubject(subject);
170                this.setBody(body);
171        }
172
173        public String readEmail(String subject) {
174                // waitForElementByXpath("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]");
175                String id = findEmailIdBySuject(subject);
176                id = id.substring(id.lastIndexOf("_") + 1);
177                clickElement(By.id("td_who_" + id));
178                super.waitForElement(By.id("div_message_scroll_" + id + "_r"));
179                return id;
180        }
181
182        public void editEmail() {
183                super.waitForElement(By
184                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]"));
185                // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1]
186                this.editEmail.click();
187        }
188
189        public void editEmail(String id) {
190                super.waitForElement(By
191                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]"));
192                // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1]
193                this.editEmail.click();
194                waitForElement(By.id("content_id_" + id));
195        }
196
197        /**
198         * Encaminha uma mensagem.
199         *
200         * @param id
201         *            Id da mensagem a ser encaminhada
202         * @param to
203         *            Destinatario
204         */
205        public void forwardEmail(String id, String to) {
206                super.waitForElement(By
207                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]"));
208                this.forwardEmail.click();
209                super.waitForElement(By.id("to_" + id));
210                driver.findElement(By.id("to_" + id)).sendKeys(to);
211                driver.findElement(By.id("send_button_" + id)).click();
212        }
213
214        private void reply(String id) {
215                super.waitForElement(By.id("to_" + id));
216                driver.findElement(By.id("send_button_" + id)).click();
217        }
218
219        /**
220         * Responde uma mensagem.
221         *
222         * @param id
223         *            Id da mensagem a ser respondida
224         */
225        public void replyEmail(String id) {
226                super.waitForElement(By
227                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]"));
228                this.replyEmail.click();
229                this.reply(id);
230        }
231
232        /**
233         * Responde uma mensagem.
234         *
235         * @param id
236         *            Id da mensagem a ser respondida
237         */
238        public void replyAllEmailWithoutHistory(String id) {
239                super.findAndClickElement("msg_opt_reply_options_" + id + "_r");
240                super.waitForElement(By
241                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[3]"));
242                this.replyAllEmailWithoutHistory.click();
243                this.reply(id);
244        }
245
246        /**
247         * Responde uma mensagem.
248         *
249         * @param id
250         *            Id da mensagem a ser respondida
251         */
252        public void replyEmailWithoutHistory(String id) {
253                super.findAndClickElement("msg_opt_reply_options_" + id + "_r");
254                super.waitForElement(By
255                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[2]"));
256                this.replyEmailWithoutHistory.click();
257                this.reply(id);
258        }
259
260        /**
261         * Responde uma mensagem.
262         *
263         * @param id
264         *            Id da mensagem a ser respondida
265         */
266        public void replyAllEmail(String id) {
267                super.findAndClickElement("msg_opt_reply_options_" + id + "_r");
268                super.waitForElement(By
269                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[1]"));
270                this.replyAllEmail.click();
271                this.reply(id);
272        }
273
274        /**
275         * Abre uma pasta de email especifica.
276         *
277         * @param folder
278         *            Pasta de email a ser aberta.
279         */
280        public void openFolder(String folder) {
281                clickElement(By.id(folder));
282                waitForElement(By.id("divScrollMain_0"));
283                waitForElement(By
284                                .xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[1]/td[1]/input[1]"));
285        }
286
287        /**
288         * Abre uma pasta de email especifica.
289         *
290         * @param folder
291         *            Pasta de email a ser aberta.
292         */
293        public void openFolder(WebElement folder) {
294                folder.click();
295                waitForElement(By.id("divScrollMain_0"));
296        }
297
298        public void setImportantFilter() {
299                this.importantFilter.click();
300        }
301
302        /**
303         * Limpa a lixeira.
304         */
305        public void cleanupTrash() {
306                this.openFolder(this.trashFolder);
307                this.emptyTrashLink.click();
308        }
309
310        /**
311         * @return Numero de emails na pasta selecionada.
312         */
313        public int getTotalEmails() {
314                return Integer.valueOf(this.totalEmails.getText());
315        }
316
317        public void moveEmail(String folderName) {
318                this.moveEmailLink.click();
319                super.findAndClickElement("lINBOX/" + folderName + "wfolders_tree");
320                this.moveEmailButton.click();
321        }
322
323        public void editFolder() {
324                this.toolsMenu.click();
325                this.waitForElement(By
326                                .xpath("//div[@id='menu_tools']/table/tbody/tr[4]/td"));
327                this.editFolder.click();
328        }
329
330        public void createNewFolder(String folderName) {
331                this.editFolder();
332                this.createNewFolder.click();
333                Alert newFolder = driver.switchTo().alert();
334                assert "Insira o nome da nova pasta: ".equals(newFolder.getText());
335                newFolder.sendKeys(folderName);
336                newFolder.accept();
337        }
338
339        public void deleteFolder(String folderName) {
340                this.editFolder();
341                this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree"))
342                                .click();
343                this.deleteFolder.click();
344                Alert confirm = driver.switchTo().alert();
345                assert ("Você gostaria de excluir a pasta: " + folderName + "?")
346                                .equals(confirm.getText());
347                confirm.accept();
348        }
349
350        /**
351         * Marca email sendo composto como importante.
352         */
353        public void checkImportantFlag() {
354                this.important.click();
355        }
356
357        public void setImportantFlag() {
358                this.waitForElement(By
359                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"));
360                this.importantFlag.click();
361        }
362
363        public void setNormalFlag() {
364                this.waitForElement(By
365                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"));
366                this.normalFlag.click();
367        }
368
369        public void setNotReadFlag() {
370                this.waitForElement(By
371                                .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]"));
372                this.notReadFlag.click();
373        }
374
375        /**
376         * Marca solicitacao de confirmacao de leitura do email sendo composto.
377         */
378        public void checkReturnReceipt() {
379                this.returnReceipt.click();
380        }
381
382        /**
383         * Salva email sendo composto (devera ir para a pasta de Rascunhos).
384         *
385         * TODO adicionar teste para verificar se o email realmente esta presente na
386         * pasta Rascunhos??
387         */
388        public void saveEmail() {
389                this.saveEmail.click();
390        }
391
392        /**
393         * Apaga email previamente selecionado.
394         */
395        public void deleteEmail() {
396                this.deleteEmailLink.click();
397        }
398
399        public void selectAllEmails() {
400                this.selectAllEmails.click();
401        }
402
403        /**
404         * Adiciona email no campo de copia oculta.
405         *
406         * @param email
407         *            Email a ser adicionado.
408         */
409        public void setBlindCarbonCopy(String email) {
410                this.blindCarbonCopyLink.click();
411                this.blindCarbonCopy.sendKeys(email);
412        }
413
414        /**
415         * Adiciona email no campo de copia.
416         *
417         * @param email
418         *            Email a ser adicionado.
419         */
420        public void setCarbonCopy(String email) {
421                this.carbonCopyLink.click();
422                this.carbonCopy.sendKeys(email);
423        }
424
425        /**
426         * Anexo um arquivo no email sendo composto.
427         *
428         * @param attachment
429         *            Caminho para o arquivo a ser anexado.
430         */
431        public void addAttachment(String attachment) {
432                this.attachmentLink.click();
433                this.attachment.sendKeys(attachment);
434        }
435
436        public void addAttachment2(String attachment) {
437                this.attachmentLink.click();
438                this.attachment2.sendKeys(attachment);
439        }
440
441        /**
442         * Envia email sendo composto.
443         */
444        public void sendMail() {
445                this.send.click();
446        }
447
448        /**
449         * Fecha aba do email sendo composto e confirma que email nao esta salvo.
450         */
451        public void closeMail() {
452                this.closeMail(true);
453        }
454
455        /**
456         * @param checkAlert
457         */
458        public void closeMail(boolean checkAlert) {
459
460                // Na versao Serpro:
461                // td[@id='border_id_1']/table/tbody/tr/td[2]/img
462
463                // Na versao Comunidade:
464                // td[@id='border_id_1']/div/div[2]/img
465
466                // Resolvi usando o xpath abaixo:
467                super.clickElement(By.xpath("//td[@id='border_id_1']//img"));
468
469                if (checkAlert) {
470                        Alert closeAlert = driver.switchTo().alert();
471                        closeAlert.accept();
472                }
473        }
474
475        public void sendMail(String id) {
476                super.findAndClickElement("send_button_" + id);
477        }
478
479        /**
480         * @param to
481         * @param subject
482         */
483        public void composeEmail(String to, String subject) {
484                composeEmail(to, subject, null);
485        }
486
487        /**
488         * @param to
489         */
490        public void composeEmail(String to) {
491                composeEmail(to, null, null);
492        }
493
494        /**
495         * Procura um email pelo assunto.
496         *
497         * @param subject
498         *            Assunto a ser procurado.
499         * @param select
500         *            Se email encontrado, deseja seleciona-lo?
501         * @return "id" do email.
502         */
503        public String findEmailIdBySuject(String subject, boolean select) {
504                String html = driver.getPageSource();
505                String part1 = StringUtils.substringBefore(html, subject);
506                int start = StringUtils.lastIndexOf(part1, "id=\"") + 4;
507                int last = StringUtils.indexOf(part1, "\"", start);
508                String id = StringUtils.substring(part1, start, last);
509
510                if (select) {
511                        // Marca checkbox correspondente ao id da mensagem.
512                        clickElement(By.id("check_box" + id.substring(1)));
513                }
514                return id;
515        }
516
517        /**
518         * @return Ids de todos os emails da pasta selecionada.
519         */
520        public String[] getEmailIds() {
521                String[] ids = new String[this.getTotalEmails()];
522                for (int i = 1; i <= this.getTotalEmails(); i++) {
523                        String id = driver
524                                        .findElement(
525                                                        By.xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr["
526                                                                        + i + "]/td[1]/input[1]")).getAttribute(
527                                                        "id");
528                        ids[i - 1] = id.substring(id.lastIndexOf("_") + 1);
529                }
530                return ids;
531        }
532
533        /**
534         * @param emailId
535         *            Id do email.
536         * @return <code>true</code> se email importante, <code>false</code> caso
537         *         contrario.
538         */
539        public boolean isImportant(String emailId) {
540                return super
541                                .isDisplayed((RenderedWebElement) driver.findElement(By
542                                                .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='"
543                                                                + emailId + "']/td[5]/img")));
544        }
545
546        public String findEmailIdBySuject(String subject) {
547                return findEmailIdBySuject(subject, false);
548        }
549
550        /**
551         * Verifica se mensagem informada corresponde ao exibido pelo Expresso na
552         * div onde sao exibidas mensagens ao usuario.
553         *
554         * @param message
555         *            Mensagem a ser validada.
556         */
557        public void assertMessage(String message) {
558                assert message.equals(getDisplayedElementContent("em_div_write_msg"));
559        }
560
561        /**
562         * @return the to
563         */
564        public WebElement getTo(String id) {
565                waitForElement(By.id("to_" + id));
566                // findAndClickElement("to_" + id);
567                // return getDisplayedElementContent(id);
568                return driver.findElement(By.id("to_" + id));
569        }
570
571        /**
572         * @return the subject
573         */
574        public WebElement getSubject(String id) {
575                waitForElement(By.id("subject_" + id));
576                return driver.findElement(By.id("subject_" + id));
577        }
578
579        /**
580         * @return the blindCarbonCopy
581         */
582        public WebElement getBlindCarbonCopy(String id) {
583                waitForElement(By.id("cco_" + id));
584                return driver.findElement(By.id("cco_" + id));
585        }
586
587        /**
588         * @return the carbonCopy
589         */
590        public WebElement getCarbonCopy(String id) {
591                waitForElement(By.id("cc_" + id));
592                return driver.findElement(By.id("cc_" + id));
593        }
594
595        public Object getBody(String id) {
596                waitForElement(By.id("body_" + id));
597                return ((JavascriptExecutor) driver)
598                                .executeScript("return document.getElementById('body_" + id
599                                                + "').contentWindow.document.body.innerHTML;");
600        }
601
602}
Note: See TracBrowser for help on using the repository browser.