1 | package br.gov.serpro.cte.common; |
---|
2 | |
---|
3 | import 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 | */ |
---|
13 | public 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 | |
---|
55 | if (select) { |
---|
56 | // Marca checkbox correspondente ao id da mensagem. |
---|
57 | selenium.click("check_box" + id.substring(1)); |
---|
58 | } |
---|
59 | |
---|
60 | return id; |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Cria um novo email informando destinatario e assunto. |
---|
65 | * |
---|
66 | * @param to |
---|
67 | * Destinatário (campo Para:). |
---|
68 | * @param subject |
---|
69 | * Assunto do email. |
---|
70 | * @throws Exception |
---|
71 | */ |
---|
72 | public void composeEmail(String to, String subject) throws Exception { |
---|
73 | this.composeEmail(); |
---|
74 | selenium.type(Campo.PARA_1.getValue(), to); |
---|
75 | selenium.type(Campo.ASSUNTO_1.getValue(), subject); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * Cria um novo email. |
---|
81 | * |
---|
82 | * @throws Exception |
---|
83 | */ |
---|
84 | public void composeEmail() throws Exception { |
---|
85 | this.enterExpressoMail(); |
---|
86 | selenium.click(Campo.NOVA_MENSAGEM.getValue()); |
---|
87 | super.waitForElement(Campo.PARA_1.getValue()); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * Simula o envio de email ao pressionar o botao Enviar. |
---|
92 | */ |
---|
93 | public void sendEmail() { |
---|
94 | selenium.click(Campo.ENVIAR_EMAIL_1.getValue()); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * Verifica se a mensagem ao usuario foi informada pelo Expresso. |
---|
99 | * |
---|
100 | * @param message |
---|
101 | * Mensagem a verificar. |
---|
102 | * @throws Exception |
---|
103 | */ |
---|
104 | public void assertMessage(String message) throws Exception { |
---|
105 | // Espera pela mensagem de erro. |
---|
106 | super.waitForElement("em_div_write_msg"); |
---|
107 | assertEquals(message, selenium.getText("em_div_write_msg")); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * Procura o email pelo assunto e abre para leitura. |
---|
112 | * |
---|
113 | * @param subject |
---|
114 | * Assunto do email. |
---|
115 | * @return "id" do email. |
---|
116 | * @throws Exception |
---|
117 | */ |
---|
118 | public String readEmail(String subject) throws Exception { |
---|
119 | this.enterExpressoMail(); |
---|
120 | String id = this.findEmailIdBySuject(subject); |
---|
121 | selenium.click(id); |
---|
122 | // Espera ate aba da mensagem abrir. |
---|
123 | super.waitForElement("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]"); |
---|
124 | |
---|
125 | // Retorna somente o "id" do email. |
---|
126 | id = id.substring(id.lastIndexOf("_")); |
---|
127 | |
---|
128 | return id; |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | * Apaga o email previamente selecionado. |
---|
133 | */ |
---|
134 | public void deleteEmail() { |
---|
135 | selenium.click("//div[@id='footer_menu']/table[@id='footer_box']/tbody/tr[@id='table_message']/td[@id='span_options']/span[1]/span"); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * @return Numero de emails na pasta selecionada. |
---|
140 | */ |
---|
141 | public int getTotalEmails() { |
---|
142 | return Integer |
---|
143 | .valueOf(selenium |
---|
144 | .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']")); |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | * @return Ids de todos os emails da pasta selecionada. |
---|
149 | */ |
---|
150 | public String[] getEmailIds() { |
---|
151 | String[] ids = new String[this.getTotalEmails()]; |
---|
152 | for (int i = 1; i <= this.getTotalEmails(); i++) { |
---|
153 | String id = selenium |
---|
154 | .getAttribute("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[" |
---|
155 | + i + "]/td[1]/input[1]@id"); |
---|
156 | ids[i - 1] = id.substring(id.lastIndexOf("_") + 1); |
---|
157 | } |
---|
158 | return ids; |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * @param emailId |
---|
163 | * Id do email. |
---|
164 | * @return <code>true</code> se email importante, <code>false</code> caso |
---|
165 | * contrario. |
---|
166 | */ |
---|
167 | public boolean isImportant(String emailId) { |
---|
168 | return selenium |
---|
169 | .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='" |
---|
170 | + emailId + "']/td[5]/img"); |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * @param emailId |
---|
175 | * Id do email. |
---|
176 | * @return <code>true</code> se email lido, <code>false</code> caso |
---|
177 | * contrario. |
---|
178 | */ |
---|
179 | public boolean isRead(String emailId) { |
---|
180 | return "Lida" |
---|
181 | .equals(selenium |
---|
182 | .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='" |
---|
183 | + emailId + "']/td[7]/img@title")); |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * Abre uma pasta de email especifica. |
---|
188 | * |
---|
189 | * @param folder |
---|
190 | * Pasta de email a ser aberta. |
---|
191 | * @throws Exception |
---|
192 | */ |
---|
193 | public void openFolder(String folder) throws Exception { |
---|
194 | selenium.click(folder); |
---|
195 | this.waitForElement("divScrollMain_0"); |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * Responder email. |
---|
200 | * |
---|
201 | * @param id |
---|
202 | * Id do email a ser respondido. |
---|
203 | * @throws Exception |
---|
204 | */ |
---|
205 | public void replyEmail(String id) throws Exception { |
---|
206 | // Clicar na opcao para responder. |
---|
207 | selenium.click(Campo.RESPONDER_EMAIL.getValue()); |
---|
208 | this.reply(id); |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * Responder email a todos destinatarios. |
---|
213 | * |
---|
214 | * @param id |
---|
215 | * Id do email a ser respondido. |
---|
216 | * @throws Exception |
---|
217 | */ |
---|
218 | public void replyAllEmail(String id) throws Exception { |
---|
219 | // Clicar na opcao para responder. |
---|
220 | selenium.click("msg_opt_reply_options" + id + "_r"); |
---|
221 | selenium.click("//span[@onclick='new_message(\"reply_to_all_with_history\",\"" |
---|
222 | + id.substring(1) + "_r\");']"); |
---|
223 | |
---|
224 | this.reply(id); |
---|
225 | } |
---|
226 | |
---|
227 | /** |
---|
228 | * Responder email a todos destinatarios sem historico. |
---|
229 | * |
---|
230 | * @param id |
---|
231 | * Id do email a ser respondido. |
---|
232 | * @throws Exception |
---|
233 | */ |
---|
234 | public void replyAllEmailWithoutHistory(String id) throws Exception { |
---|
235 | // Clicar na opcao para responder. |
---|
236 | selenium.click("msg_opt_reply_options" + id + "_r"); |
---|
237 | selenium.click("//span[@onclick='new_message(\"reply_without_history\",\"" |
---|
238 | + id.substring(1) + "_r\");']"); |
---|
239 | |
---|
240 | this.reply(id); |
---|
241 | } |
---|
242 | |
---|
243 | /** |
---|
244 | * Responder email sem historico. |
---|
245 | * |
---|
246 | * @param id |
---|
247 | * Id do email a ser respondido. |
---|
248 | * @throws Exception |
---|
249 | */ |
---|
250 | public void replyEmailWithoutHistory(String id) throws Exception { |
---|
251 | // Clicar na opcao para responder. |
---|
252 | selenium.click("//span[@onclick='new_message(\"reply_without_history\",\"" |
---|
253 | + id.substring(1) + "_r\");']"); |
---|
254 | this.reply(id); |
---|
255 | } |
---|
256 | |
---|
257 | /** |
---|
258 | * Responder email, serve apenas para clicar na opcao "Enviar". |
---|
259 | * |
---|
260 | * @param id |
---|
261 | * Id do email a ser respondido. |
---|
262 | * @throws Exception |
---|
263 | */ |
---|
264 | private void reply(String id) throws Exception { |
---|
265 | // Espera carregar aba para responder email. |
---|
266 | super.waitForElement("to" + id); |
---|
267 | selenium.click("send_button" + id); |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * Encaminha uma mensagem. |
---|
272 | * |
---|
273 | * @param id |
---|
274 | * Id da mensagem a ser encaminhada |
---|
275 | * @param to |
---|
276 | * Destinatario |
---|
277 | * @throws Exception |
---|
278 | */ |
---|
279 | public void forwardEmail(String id, String to) throws Exception { |
---|
280 | // Clicar na opcao para encaminhar. |
---|
281 | selenium.click(Campo.ENCAMINHAR_EMAIL.getValue()); |
---|
282 | |
---|
283 | // Espera carregar aba para encaminhar email. |
---|
284 | super.waitForElement("to" + id); |
---|
285 | selenium.type("to" + id, to); |
---|
286 | |
---|
287 | selenium.click("send_button" + id); |
---|
288 | } |
---|
289 | |
---|
290 | public enum Mensagem { |
---|
291 | PASTA_VAZIA("Esta pasta está vazia"), // |
---|
292 | SEM_DESTINATARIO( |
---|
293 | "Você deve fornecer pelo menos um endereço de destinatário de email."), // |
---|
294 | SEM_ASSUNTO("^Enviar esta mensagem sem assunto[\\s\\S]$"), // |
---|
295 | DESTINATARIO_INVALIDO( |
---|
296 | "Erro de SMTP: Os endereços de destinatário a seguir falharam: bla@"), // |
---|
297 | SALVA_RASCUNHO( |
---|
298 | "Sua mensagem foi salva como rascunho na pasta Rascunhos."), // |
---|
299 | LIMPAR_LIXEIRA( |
---|
300 | "^Você tem certeza que deseja limpar sua lixeira[\\s\\S]$"), // |
---|
301 | LIXEIRA_LIMPA("Sua pasta Lixeira foi limpa."), // |
---|
302 | APAGAR_UMA_MENSAGEM("Mensagem movida para a pasta Lixeira"), // |
---|
303 | APAGAR_MENSAGEM("Mensagens movidas para pasta Lixeira"); |
---|
304 | private String value; |
---|
305 | |
---|
306 | private Mensagem(String value) { |
---|
307 | this.value = value; |
---|
308 | } |
---|
309 | |
---|
310 | public String getValue() { |
---|
311 | return value; |
---|
312 | } |
---|
313 | |
---|
314 | }; |
---|
315 | |
---|
316 | public enum Campo { |
---|
317 | ADICIONAR_ANEXO("link=exact:Anexos: adicionar+"), // |
---|
318 | ANEXO_1("inputFile_1_1"), // |
---|
319 | ANEXO_2("inputFile_1_2"), // |
---|
320 | NOVA_MENSAGEM( |
---|
321 | "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span"), // |
---|
322 | PARA_1("to_1"), // |
---|
323 | ASSUNTO_1("subject_1"), // |
---|
324 | ENVIAR_EMAIL_1("send_button_1"), // |
---|
325 | CONFIRMACAO_LEITURA("return_receipt_1"), // |
---|
326 | IMPORTANTE( |
---|
327 | "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"), // |
---|
328 | NORMAL( |
---|
329 | "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"), // |
---|
330 | NAO_LIDO( |
---|
331 | "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]"), // |
---|
332 | IMPORTANTE_CHECKBOX("important_message_1"), // |
---|
333 | COPIA_1("a_cc_link_1"), // |
---|
334 | SALVAR("save_message_options_1"), // |
---|
335 | COPIA_CAMPO_1("cc_1"), // |
---|
336 | COPIA_OCULTA_1("a_cco_link_1"), // |
---|
337 | COPIA_OCULTA_CAMPO_1("cco_1"), // |
---|
338 | PASTA_LIXEIRA("lINBOX/Trashtree_folders"), // |
---|
339 | LIMPAR_LIXEIRA("empty_trash"), // |
---|
340 | SELECIONAR_TODOS_EMAILS("chk_box_select_all_messages"), // |
---|
341 | ENCAMINHAR_EMAIL( |
---|
342 | "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]"), // |
---|
343 | RESPONDER_EMAIL( |
---|
344 | "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]"), // |
---|
345 | MOVER_EMAIL("//span[@onclick='wfolders.makeWindow(\"\",\"move_to\")']"), // |
---|
346 | MSG_INFO("msg_info"), // |
---|
347 | MENSAGEM("em_div_write_msg"); |
---|
348 | private String value; |
---|
349 | |
---|
350 | private Campo(String value) { |
---|
351 | this.value = value; |
---|
352 | } |
---|
353 | |
---|
354 | public String getValue() { |
---|
355 | return value; |
---|
356 | } |
---|
357 | |
---|
358 | }; |
---|
359 | |
---|
360 | public enum Valor { |
---|
361 | EMAIL_TESTE_1("luiz-fernando.estivalet@cte.serpro.gov.br"), // |
---|
362 | EMAIL_TESTE_2("luiz.f.estivalet@gmail.com"), // |
---|
363 | EMAIL_TESTE_3("luizfernando_estivalet@yahoo.com"), // |
---|
364 | EMAIL_INVALIDO("bla"), // |
---|
365 | EMAIL_TESTE_MULTIPLOS( |
---|
366 | "luiz-fernando.estivalet@cte.serpro.gov.br, luizfernando_estivalet@yahoo.com"), // |
---|
367 | ANEXO_1("/home/luiz/Desktop/arquivo.txt"), // |
---|
368 | ANEXO_2("/home/luiz/Desktop/arquivo2.txt"), // |
---|
369 | ASSUNTO("[SELENIUM] Teste envio mensagem"), // |
---|
370 | ASSUNTO_SALVAR("[SELENIUM] Teste salvar mensagem"), // |
---|
371 | ASSUNTO_EMAIL_INVALIDO( |
---|
372 | "[SELENIUM] Teste envio mensagem com destinatário inválido"), // |
---|
373 | ASSUNTO_SEM_DESTINATARIO( |
---|
374 | "[SELENIUM] Teste envio mensagem sem destinatário"), // |
---|
375 | ASSUNTO_MULTIPLOS_DESTINATARIOS( |
---|
376 | "[SELENIUM] Teste envio mensagem para múltiplos destinatários"), // |
---|
377 | ASSUNTO_ANEXO("[SELENIUM] Teste envio mensagem com anexo"), // |
---|
378 | ASSUNTO_IMPORTANTE("[SELENIUM] Teste envio mensagem importante"), // |
---|
379 | ASSUNTO_MULTIPLOS_ANEXOS( |
---|
380 | "[SELENIUM] Teste envio mensagem com múltiplos anexos"), // |
---|
381 | ASSUNTO_CONFIRMACAO_LEITURA( |
---|
382 | "[SELENIUM] Teste envio mensagem com confirmação de leitura"), // |
---|
383 | ASSUNTO_COPIA("[SELENIUM] Teste envio mensagem com cópia"), // |
---|
384 | ASSUNTO_COPIA_OCULTA("[SELENIUM] Teste envio mensagem com cópia oculta"), ASSUNTO_SOMENTE_COPIA( |
---|
385 | "[SELENIUM] Teste envio mensagem somente cópia"), // |
---|
386 | ASSUNTO_SOMENTE_COPIA_OCULTA( |
---|
387 | "[SELENIUM] Teste envio mensagem somente cópia oculta"); |
---|
388 | private String value; |
---|
389 | |
---|
390 | private Valor(String value) { |
---|
391 | this.value = value; |
---|
392 | } |
---|
393 | |
---|
394 | public String getValue() { |
---|
395 | return value; |
---|
396 | } |
---|
397 | |
---|
398 | }; |
---|
399 | |
---|
400 | } |
---|