source: devel/testlink/automation/src/test/java/br/gov/serpro/cte/common/ExpressoMailTestCase.java @ 3523

Revision 3523, 14.5 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1402 - Automacao dos casos de teste do Expresso documentados no Testlink

Line 
1package br.gov.serpro.cte.common;
2
3import org.apache.commons.lang.StringUtils;
4
5/**
6 * Contem metodos comuns a todos os casos de teste do ExpressoMail.
7 *
8 * @author L.F.Estivalet (Serpro)
9 *
10 *         Created on Nov 12, 2010 at 11:52:43 AM
11 *
12 */
13public class ExpressoMailTestCase extends BaseTestCase {
14
15        /**
16         * Entra no modulo ExpressoMail.
17         *
18         * @throws Exception
19         */
20        public void enterExpressoMail() throws Exception {
21                super.login();
22                selenium.open("/expressoMail1_2/index.php");
23                selenium.waitForPageToLoad("30000");
24                // Espera a caixa de entrada carregar.
25                this.waitForElement("divScrollMain_0");
26        }
27
28        /**
29         * Procura um email pelo seu assunto.
30         *
31         * @param subject
32         *            Assunto a ser procurado.
33         * @return "id" do email.
34         */
35        public String findEmailIdBySuject(String subject) {
36                return findEmailIdBySuject(subject, false);
37        }
38
39        /**
40         * Procura um email pelo seu assunto.
41         *
42         * @param subject
43         *            Assunto a ser procurado.
44         * @param select
45         *            Se email encontrado, deseja seleciona-lo?
46         * @return "id" do email.
47         */
48        public String findEmailIdBySuject(String subject, boolean select) {
49                String html = selenium.getHtmlSource();
50                String part1 = StringUtils.substringBefore(html, subject);
51                int start = StringUtils.lastIndexOf(part1, "id=\"") + 4;
52                int last = StringUtils.indexOf(part1, "\">", start);
53                String id = StringUtils.substring(part1, start, last);
54                if (select) {
55                        // Marca checkbox correspondente ao id da mensagem.
56                        selenium.click("check_box" + id.substring(1));
57                }
58
59                // Retorna somente o "id" do email.
60                // id = id.substring(id.lastIndexOf("_"));
61
62                return id;
63        }
64
65        /**
66         * Cria um novo email informando destinatario e assunto.
67         *
68         * @param to
69         *            Destinatário (campo Para:).
70         * @param subject
71         *            Assunto do email.
72         * @throws Exception
73         */
74        public void composeEmail(String to, String subject) throws Exception {
75                this.composeEmail();
76                selenium.type(Campo.PARA_1.getValue(), to);
77                selenium.type(Campo.ASSUNTO_1.getValue(), subject);
78        }
79
80        /**
81         * Cria um novo email.
82         *
83         * @throws Exception
84         */
85        public void composeEmail() throws Exception {
86                this.enterExpressoMail();
87                selenium.click(Campo.NOVA_MENSAGEM.getValue());
88                super.waitForElement(Campo.PARA_1.getValue());
89        }
90
91        /**
92         * @param remove
93         *            Se <code>true</code>, remove o logo apos o envio da Caixa de
94         *            Entrada, itens enviados e lixeira. Simula o envio de email ao
95         *            pressionar o botao Enviar.
96         */
97        public void sendEmail(String to, String subject, boolean remove)
98                        throws Exception {
99                this.composeEmail(to, subject);
100                selenium.click(Campo.ENVIAR_EMAIL_1.getValue());
101                this.assertMessage(Campo.MENSAGEM.value, Mensagem.EMAIL_ENVIADO.value);
102                if (remove) {
103                        this.removeEmail(subject);
104                }
105        }
106
107        /**
108         * Pressiona opcao para enviar o email.
109         */
110        public void sendEmail() {
111                selenium.click(Campo.ENVIAR_EMAIL_1.getValue());
112        }
113
114        /**
115         * Procura o email pelo assunto e abre para leitura.
116         *
117         * @param subject
118         *            Assunto do email.
119         * @return "id" do email.
120         * @throws Exception
121         */
122        public String readEmail(String subject) throws Exception {
123                this.enterExpressoMail();
124                String id = this.findEmailIdBySuject(subject);
125                selenium.click(id);
126                // Espera ate aba da mensagem abrir.
127                super.waitForElement("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]");
128
129                // Retorna somente o "id" do email.
130                id = id.substring(id.lastIndexOf("_"));
131
132                return id;
133        }
134
135        /**
136         * Apaga o email previamente selecionado.
137         */
138        public void deleteEmail() throws Exception {
139                selenium.click("//div[@id='footer_menu']/table[@id='footer_box']/tbody/tr[@id='table_message']/td[@id='span_options']/span[1]/span");
140                this.assertMessage(Campo.MENSAGEM.getValue(),
141                                Mensagem.APAGAR_UMA_MENSAGEM.getValue());
142        }
143
144        /**
145         * Apaga o email de acordo com o assunto.
146         *
147         * @param subject
148         *            Assunto a ser pesquisado. No caso da pesquisa encontrar varios
149         *            emails, apenas o primeiro sera selecionado e apagado.
150         * @throws Exception
151         */
152        public void deleteEmail(String subject) throws Exception {
153                this.findEmailIdBySuject(subject, true);
154                this.deleteEmail();
155        }
156
157        /**
158         * Apaga email de uma pasta de acordo com o assunto.
159         *
160         * @param folder
161         *            Pasta a ser pesquisada.
162         * @param subject
163         *            Assunto a ser pesquisado.
164         * @throws Exception
165         */
166        public void deleteEmail(String folder, String subject) throws Exception {
167                // Apaga email da pasta enviados.
168                this.openFolder(folder);
169                // Espera pelo primeiro checkbox da pasta aparecer.
170                super.waitForElement(Campo.CHECKBOX_EMAIL.getValue());
171                this.deleteEmail(subject);
172                this.waitForElement(Campo.MSG_INFO.getValue());
173                assertTrue(Mensagem.PASTA_VAZIA.getValue().equals(
174                                selenium.getText(Campo.MSG_INFO.getValue())));
175        }
176
177        /**
178         * Remove o email de acordo com o assunto da Caixa de Entrada, dos itens
179         * enviados e da lixeira.
180         *
181         * @param subject
182         *            Assunto a ser pesquisado. No caso da pesquisa encontrar varios
183         *            emails, apenas o primeiro sera selecionado e apagado.
184         * @throws Exception
185         */
186        public void removeEmail(String subject) throws Exception {
187                // Faz logout para dar tempo para o email chegar na Caixa de Entrada.
188                super.logout();
189
190                // Entra novamente no ExpressoMail e apaga o email da Caixa de Entrada.
191                this.enterExpressoMail();
192                this.deleteEmail(subject);
193
194                // Apaga email da pasta enviados.
195                this.deleteEmail(Campo.PASTA_ENVIADOS.getValue(), subject);
196
197                // Limpa a lixeira.
198                super.logout();
199                this.enterExpressoMail();
200                this.cleanupTrash();
201        }
202
203        /**
204         * Limpa a lixeira.
205         *
206         * @throws Exception
207         */
208        public void cleanupTrash() throws Exception {
209                this.openFolder(Campo.PASTA_LIXEIRA.getValue());
210                selenium.click(Campo.LIMPAR_LIXEIRA.getValue());
211                assertTrue(selenium.getConfirmation().matches(
212                                Mensagem.LIMPAR_LIXEIRA.getValue()));
213                super.waitForElement(Campo.MENSAGEM.getValue());
214                assertEquals(Mensagem.LIXEIRA_LIMPA.getValue(),
215                                selenium.getText(Campo.MENSAGEM.getValue()));
216                // Garantir que nao tem nenhum email na lixeira.
217                assertEquals("0", this.getTotalEmails());
218        }
219
220        /**
221         * @return Numero de emails na pasta selecionada.
222         */
223        public int getTotalEmails() {
224                return Integer
225                                .valueOf(selenium
226                                                .getText("//div[@id='exmail_main_body']/table[@id='border_table']/tbody[@id='border_tbody']/tr[@id='border_tr']/td[@id='border_id_0']/font/span[@id='tot_m']"));
227        }
228
229        /**
230         * @return Ids de todos os emails da pasta selecionada.
231         */
232        public String[] getEmailIds() {
233                String[] ids = new String[this.getTotalEmails()];
234                for (int i = 1; i <= this.getTotalEmails(); i++) {
235                        String id = selenium
236                                        .getAttribute("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr["
237                                                        + i + "]/td[1]/input[1]@id");
238                        ids[i - 1] = id.substring(id.lastIndexOf("_") + 1);
239                }
240                return ids;
241        }
242
243        /**
244         * @param emailId
245         *            Id do email.
246         * @return <code>true</code> se email importante, <code>false</code> caso
247         *         contrario.
248         */
249        public boolean isImportant(String emailId) {
250                return selenium
251                                .isElementPresent("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='"
252                                                + emailId + "']/td[5]/img");
253        }
254
255        /**
256         * @param emailId
257         *            Id do email.
258         * @return <code>true</code> se email lido, <code>false</code> caso
259         *         contrario.
260         */
261        public boolean isRead(String emailId) {
262                return "Lida"
263                                .equals(selenium
264                                                .getAttribute("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='"
265                                                                + emailId + "']/td[7]/img@title"));
266        }
267
268        /**
269         * Abre uma pasta de email especifica.
270         *
271         * @param folder
272         *            Pasta de email a ser aberta.
273         * @throws Exception
274         */
275        public void openFolder(String folder) throws Exception {
276                selenium.click(folder);
277                this.waitForElement("divScrollMain_0");
278        }
279
280        /**
281         * Responder email.
282         *
283         * @param id
284         *            Id do email a ser respondido.
285         * @throws Exception
286         */
287        public void replyEmail(String id) throws Exception {
288                // Clicar na opcao para responder.
289                selenium.click(Campo.RESPONDER_EMAIL.getValue());
290                this.reply(id);
291        }
292
293        /**
294         * Responder email a todos destinatarios.
295         *
296         * @param id
297         *            Id do email a ser respondido.
298         * @throws Exception
299         */
300        public void replyAllEmail(String id) throws Exception {
301                // Clicar na opcao para responder.
302                selenium.click("msg_opt_reply_options" + id + "_r");
303                selenium.click("//span[@onclick='new_message(\"reply_to_all_with_history\",\""
304                                + id.substring(1) + "_r\");']");
305
306                this.reply(id);
307        }
308
309        /**
310         * Responder email a todos destinatarios sem historico.
311         *
312         * @param id
313         *            Id do email a ser respondido.
314         * @throws Exception
315         */
316        public void replyAllEmailWithoutHistory(String id) throws Exception {
317                // Clicar na opcao para responder.
318                selenium.click("msg_opt_reply_options" + id + "_r");
319                selenium.click("//span[@onclick='new_message(\"reply_without_history\",\""
320                                + id.substring(1) + "_r\");']");
321
322                this.reply(id);
323        }
324
325        /**
326         * Responder email sem historico.
327         *
328         * @param id
329         *            Id do email a ser respondido.
330         * @throws Exception
331         */
332        public void replyEmailWithoutHistory(String id) throws Exception {
333                // Clicar na opcao para responder.
334                selenium.click("//span[@onclick='new_message(\"reply_without_history\",\""
335                                + id.substring(1) + "_r\");']");
336                this.reply(id);
337        }
338
339        /**
340         * Responder email, serve apenas para clicar na opcao "Enviar".
341         *
342         * @param id
343         *            Id do email a ser respondido.
344         * @throws Exception
345         */
346        private void reply(String id) throws Exception {
347                // Espera carregar aba para responder email.
348                super.waitForElement("to" + id);
349                selenium.click("send_button" + id);
350        }
351
352        /**
353         * Encaminha uma mensagem.
354         *
355         * @param id
356         *            Id da mensagem a ser encaminhada
357         * @param to
358         *            Destinatario
359         * @throws Exception
360         */
361        public void forwardEmail(String id, String to) throws Exception {
362                // Clicar na opcao para encaminhar.
363                selenium.click(Campo.ENCAMINHAR_EMAIL.getValue());
364
365                // Espera carregar aba para encaminhar email.
366                super.waitForElement("to" + id);
367                selenium.type("to" + id, to);
368
369                selenium.click("send_button" + id);
370        }
371
372        public enum Mensagem {
373                PASTA_VAZIA("Esta pasta está vazia"), //
374                SEM_DESTINATARIO(
375                                "Você deve fornecer pelo menos um endereço de destinatário de email."), //
376                SEM_ASSUNTO("^Enviar esta mensagem sem assunto[\\s\\S]$"), //
377                EMAIL_ENVIADO("Sua mensagem foi enviada e salva."), //
378                DESTINATARIO_INVALIDO(
379                                "Erro de SMTP: Os endereços de destinatário a seguir falharam: bla@"), //
380                SALVA_RASCUNHO(
381                                "Sua mensagem foi salva como rascunho na pasta Rascunhos."), //
382                LIMPAR_LIXEIRA(
383                                "^Você tem certeza que deseja limpar sua lixeira[\\s\\S]$"), //
384                LIXEIRA_LIMPA("Sua pasta Lixeira foi limpa."), //
385                APAGAR_UMA_MENSAGEM("Mensagem movida para a pasta Lixeira"), //
386                MARCAR_IMPORTANTE("Mensagem marcada como Importante"), //
387                MARCAR_NORMAL("Mensagem marcada como Normal"), //
388                MARCAR_NAO_LIDO("Mensagem marcada como Não lida"), //
389                APAGAR_MENSAGEM("Mensagens movidas para pasta Lixeira");
390                private String value;
391
392                private Mensagem(String value) {
393                        this.value = value;
394                }
395
396                public String getValue() {
397                        return value;
398                }
399
400        };
401
402        public enum Campo {
403                ADICIONAR_ANEXO("link=exact:Anexos: adicionar+"), //
404                ANEXO_1("inputFile_1_1"), //
405                ANEXO_2("inputFile_1_2"), //
406                NOVA_MENSAGEM(
407                                "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span"), //
408                PARA_1("to_1"), //
409                ASSUNTO_1("subject_1"), //
410                ENVIAR_EMAIL_1("send_button_1"), //
411                CHECKBOX_EMAIL(
412                                "//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[1]/td[1]/input[1]"), //
413                CONFIRMACAO_LEITURA("return_receipt_1"), //
414                IMPORTANTE(
415                                "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"), //
416                NORMAL(
417                                "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"), //
418                NAO_LIDO(
419                                "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]"), //
420                IMPORTANTE_CHECKBOX("important_message_1"), //
421                COPIA_1("a_cc_link_1"), //
422                SALVAR("save_message_options_1"), //
423                COPIA_CAMPO_1("cc_1"), //
424                COPIA_OCULTA_1("a_cco_link_1"), //
425                COPIA_OCULTA_CAMPO_1("cco_1"), //
426                PASTA_LIXEIRA("lINBOX/Trashtree_folders"), //
427                PASTA_ENVIADOS("lINBOX/Senttree_folders"), //
428                LIMPAR_LIXEIRA("empty_trash"), //
429                SELECIONAR_TODOS_EMAILS("chk_box_select_all_messages"), //
430                ENCAMINHAR_EMAIL(
431                                "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]"), //
432                RESPONDER_EMAIL(
433                                "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]"), //
434                MOVER_EMAIL("//span[@onclick='wfolders.makeWindow(\"\",\"move_to\")']"), //
435                MSG_INFO("msg_info"), //
436                MENSAGEM("em_div_write_msg");
437                private String value;
438
439                private Campo(String value) {
440                        this.value = value;
441                }
442
443                public String getValue() {
444                        return value;
445                }
446
447        };
448
449        public enum Valor {
450                EMAIL_TESTE_1("luiz-fernando.estivalet@cte.serpro.gov.br"), //
451                EMAIL_TESTE_2("luiz.f.estivalet@gmail.com"), //
452                EMAIL_TESTE_3("luizfernando_estivalet@yahoo.com"), //
453                EMAIL_INVALIDO("bla"), //
454                EMAIL_TESTE_MULTIPLOS(
455                                "luiz-fernando.estivalet@cte.serpro.gov.br, luizfernando_estivalet@yahoo.com"), //
456                ANEXO_1("/home/luiz/Desktop/arquivo.txt"), //
457                ANEXO_2("/home/luiz/Desktop/arquivo2.txt"), //
458                ASSUNTO("[SELENIUM] Teste envio mensagem"), //
459                ASSUNTO_SALVAR("[SELENIUM] Teste salvar mensagem"), //
460                ASSUNTO_EMAIL_INVALIDO(
461                                "[SELENIUM] Teste envio mensagem com destinatário inválido"), //
462                ASSUNTO_SEM_DESTINATARIO(
463                                "[SELENIUM] Teste envio mensagem sem destinatário"), //
464                ASSUNTO_MULTIPLOS_DESTINATARIOS(
465                                "[SELENIUM] Teste múltiplos destinatários"), //
466                ASSUNTO_ANEXO("[SELENIUM] Teste envio mensagem com anexo"), //
467                ASSUNTO_IMPORTANTE("[SELENIUM] Teste envio mensagem importante"), //
468                ASSUNTO_MULTIPLOS_ANEXOS("[SELENIUM] Teste com múltiplos anexos"), //
469                ASSUNTO_CONFIRMACAO_LEITURA(
470                                "[SELENIUM] Teste com confirmação de leitura"), //
471                ASSUNTO_COPIA("[SELENIUM] Teste envio mensagem com cópia"), //
472                ASSUNTO_COPIA_OCULTA("[SELENIUM] Teste envio mensagem com cópia oculta"), ASSUNTO_SOMENTE_COPIA(
473                                "[SELENIUM] Teste envio mensagem somente cópia"), //
474                ASSUNTO_SOMENTE_COPIA_OCULTA(
475                                "[SELENIUM] Teste mensagem somente cópia oculta");
476                private String value;
477
478                private Valor(String value) {
479                        this.value = value;
480                }
481
482                public String getValue() {
483                        return value;
484                }
485
486        };
487
488}
Note: See TracBrowser for help on using the repository browser.