1 | package org.expressolivre.cte.pages.email; |
---|
2 | |
---|
3 | import org.apache.commons.lang.StringUtils; |
---|
4 | import org.expressolivre.cte.pages.common.Page; |
---|
5 | import org.openqa.selenium.Alert; |
---|
6 | import org.openqa.selenium.By; |
---|
7 | import org.openqa.selenium.JavascriptExecutor; |
---|
8 | import org.openqa.selenium.RenderedWebElement; |
---|
9 | import org.openqa.selenium.WebDriver; |
---|
10 | import org.openqa.selenium.WebElement; |
---|
11 | import org.openqa.selenium.support.FindBy; |
---|
12 | import org.openqa.selenium.support.PageFactory; |
---|
13 | import org.testng.Assert; |
---|
14 | |
---|
15 | /** |
---|
16 | * @author L.F.Estivalet (Serpro) |
---|
17 | * |
---|
18 | * Created on Dec 16, 2010 at 9:43:21 AM |
---|
19 | * |
---|
20 | */ |
---|
21 | public class MailPage extends Page { |
---|
22 | |
---|
23 | /** Botao para criar novo email. */ |
---|
24 | @FindBy(xpath = "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span") |
---|
25 | private WebElement newEmail; |
---|
26 | |
---|
27 | /** Campo "Para:". */ |
---|
28 | @FindBy(id = "to_1") |
---|
29 | private WebElement to; |
---|
30 | |
---|
31 | /** Campo "Assunto:". */ |
---|
32 | @FindBy(id = "subject_1") |
---|
33 | private WebElement subject; |
---|
34 | |
---|
35 | /** Botao para enviar email. */ |
---|
36 | @FindBy(id = "send_button_1") |
---|
37 | private WebElement send; |
---|
38 | |
---|
39 | /** Flag de importante no momento de compor um email. */ |
---|
40 | @FindBy(id = "important_message_1") |
---|
41 | private WebElement important; |
---|
42 | |
---|
43 | /** Flag de importante de um email aberto. */ |
---|
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 | |
---|
47 | /** Filtra emails importantes. */ |
---|
48 | @FindBy(id = "span_flag_FLAGGED") |
---|
49 | private WebElement importantFilter; |
---|
50 | |
---|
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 | |
---|
61 | /** Flag normal de um email aberto. */ |
---|
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 | |
---|
65 | /** Flag nao lido de um email aberto. */ |
---|
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 | |
---|
69 | /** Checkbox de confirmacao de leitura. */ |
---|
70 | @FindBy(id = "return_receipt_1") |
---|
71 | private WebElement returnReceipt; |
---|
72 | |
---|
73 | /** Link para acionar exibicao do campo copia oculta Cco. */ |
---|
74 | @FindBy(id = "a_cco_link_1") |
---|
75 | private WebElement blindCarbonCopyLink; |
---|
76 | |
---|
77 | /** Campo copia oculta "Cco:". */ |
---|
78 | @FindBy(id = "cco_1") |
---|
79 | private WebElement blindCarbonCopy; |
---|
80 | |
---|
81 | /** Link para acionar exibicao do campo copia Cc. */ |
---|
82 | @FindBy(id = "a_cc_link_1") |
---|
83 | private WebElement carbonCopyLink; |
---|
84 | |
---|
85 | /** Campo copia "Cc:". */ |
---|
86 | @FindBy(id = "cc_1") |
---|
87 | private WebElement carbonCopy; |
---|
88 | |
---|
89 | /** Link para salvar email. */ |
---|
90 | @FindBy(id = "save_message_options_1") |
---|
91 | private WebElement saveEmail; |
---|
92 | |
---|
93 | /** Link para adicionar anexos ao email. */ |
---|
94 | @FindBy(linkText = "Anexos: adicionar+") |
---|
95 | private WebElement attachmentLink; |
---|
96 | |
---|
97 | /** Link para adicionar 1o anexo. */ |
---|
98 | @FindBy(id = "inputFile_1_1") |
---|
99 | private WebElement attachment; |
---|
100 | |
---|
101 | /** Link para adicionar 2o anexo. */ |
---|
102 | @FindBy(id = "inputFile_1_2") |
---|
103 | private WebElement attachment2; |
---|
104 | |
---|
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. */ |
---|
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 | |
---|
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 | |
---|
116 | /** Link para pasta lixeira. */ |
---|
117 | @FindBy(id = "lINBOX/Trashtree_folders") |
---|
118 | private WebElement trashFolder; |
---|
119 | |
---|
120 | /** Link para limpar lixeira. */ |
---|
121 | @FindBy(id = "empty_trash") |
---|
122 | private WebElement emptyTrashLink; |
---|
123 | |
---|
124 | /** Campo contendo total de emails de uma pasta. */ |
---|
125 | @FindBy(id = "tot_m") |
---|
126 | private WebElement totalEmails; |
---|
127 | |
---|
128 | /** Checkbox para selecao de todos emails de uma pasta. */ |
---|
129 | @FindBy(id = "chk_box_select_all_messages") |
---|
130 | private WebElement selectAllEmails; |
---|
131 | |
---|
132 | /** Link para acionar o menu Ferramentas. */ |
---|
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 | |
---|
139 | @FindBy(xpath = "//div[@id='menu_tools']/table/tbody/tr[3]/td") |
---|
140 | private WebElement editFilter; |
---|
141 | |
---|
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 | |
---|
149 | /** Link para encaminhar em email aberto. */ |
---|
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 | |
---|
153 | /** Link para responder em email aberto. */ |
---|
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 | |
---|
157 | /** Link para responder a todos em email aberto. */ |
---|
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 | |
---|
161 | /** Link para responder sem historico em email aberto. */ |
---|
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 | |
---|
165 | /** Link para responder a todos sem historico em email aberto. */ |
---|
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 | |
---|
169 | /** Link para editar email na pasta de rascunhos. */ |
---|
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 | |
---|
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 | |
---|
179 | /** |
---|
180 | * Esse botao eh no alerta ao fechar uma mensagem nao salva e nao o botao |
---|
181 | * salvar para rascunhos. |
---|
182 | */ |
---|
183 | @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[3]") |
---|
184 | private WebElement saveNewEmail; |
---|
185 | |
---|
186 | @FindBy(xpath = "//table[@id='folders_tbl']/tbody/tr[1]/td/table/tbody/tr[1]/td/a[1]") |
---|
187 | private WebElement searchMessages; |
---|
188 | |
---|
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 | |
---|
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 | |
---|
201 | /** |
---|
202 | * @param driver |
---|
203 | */ |
---|
204 | public MailPage(WebDriver driver) { |
---|
205 | super(driver); |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | * Cria um novo email. |
---|
210 | */ |
---|
211 | public void createNewEmail() { |
---|
212 | this.newEmail.click(); |
---|
213 | waitForElement(By.id("to_1")); |
---|
214 | } |
---|
215 | |
---|
216 | /** |
---|
217 | * Cancela criacao de novo email. |
---|
218 | */ |
---|
219 | public void cancelNewEmail() { |
---|
220 | this.cancelNewEmail.click(); |
---|
221 | } |
---|
222 | |
---|
223 | public MailSearchPage openSearchMessageWindow() { |
---|
224 | this.searchMessages.click(); |
---|
225 | super.waitForElement(By.id("flagged")); |
---|
226 | |
---|
227 | return PageFactory.initElements(driver, MailSearchPage.class); |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | public void setSearchBox(String text) { |
---|
232 | this.searchBox.sendKeys(text); |
---|
233 | } |
---|
234 | |
---|
235 | public void searchStart() { |
---|
236 | this.searchStart.click(); |
---|
237 | } |
---|
238 | |
---|
239 | /** |
---|
240 | * Descarta criacao de novo email. |
---|
241 | */ |
---|
242 | public void discardNewEmail() { |
---|
243 | this.discardNewEmail.click(); |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
247 | * Salva email na pasta rascunhos. |
---|
248 | */ |
---|
249 | public void saveNewEmail() { |
---|
250 | this.saveNewEmail.click(); |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * Preenche campo assunto. |
---|
255 | * |
---|
256 | * @param subject |
---|
257 | * Assunto a ser preenchido. |
---|
258 | */ |
---|
259 | public void setSubject(String subject) { |
---|
260 | this.subject.sendKeys(subject != null ? subject : ""); |
---|
261 | } |
---|
262 | |
---|
263 | /** |
---|
264 | * Preenche corpo (texto) do email. |
---|
265 | * |
---|
266 | * @param body |
---|
267 | * Texto a ser preenchido. |
---|
268 | */ |
---|
269 | public void setBody(String body) { |
---|
270 | // Foi o unico jeito que consegui pegar o richtexteditor... |
---|
271 | if (body != null) { |
---|
272 | // Troca CR&|LF por <br> |
---|
273 | body = body.replaceAll("(\r\n|\r|\n|\n\r)", "<br>"); |
---|
274 | ((JavascriptExecutor) driver) |
---|
275 | .executeScript("document.getElementById('body_1').contentWindow.document.body.innerHTML='" |
---|
276 | + body + "';"); |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
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) { |
---|
293 | // waitForElementByXpath("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]"); |
---|
294 | String id = findEmailIdBySubject(subject); |
---|
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; |
---|
299 | } |
---|
300 | |
---|
301 | public void editEmail() { |
---|
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]")); |
---|
304 | // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1] |
---|
305 | this.editEmail.click(); |
---|
306 | } |
---|
307 | |
---|
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 | |
---|
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) { |
---|
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]")); |
---|
327 | this.forwardEmail.click(); |
---|
328 | super.waitForElement(By.id("to_" + id)); |
---|
329 | driver.findElement(By.id("to_" + id)).sendKeys(to); |
---|
330 | driver.findElement(By.id("send_button_" + id)).click(); |
---|
331 | } |
---|
332 | |
---|
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(); |
---|
359 | this.waitLoading(); |
---|
360 | Alert alert = driver.switchTo().alert(); |
---|
361 | assert (message.equals(alert.getText())); |
---|
362 | alert.accept(); |
---|
363 | } |
---|
364 | |
---|
365 | protected void waitLoading() { |
---|
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 | |
---|
374 | private void reply(String id) { |
---|
375 | super.waitForElement(By.id("to_" + id)); |
---|
376 | driver.findElement(By.id("send_button_" + id)).click(); |
---|
377 | } |
---|
378 | |
---|
379 | /** |
---|
380 | * Responde uma mensagem. |
---|
381 | * |
---|
382 | * @param id |
---|
383 | * Id da mensagem a ser respondida |
---|
384 | */ |
---|
385 | public void replyEmail(String id) { |
---|
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]")); |
---|
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"); |
---|
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]")); |
---|
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"); |
---|
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]")); |
---|
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"); |
---|
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]")); |
---|
430 | this.replyAllEmail.click(); |
---|
431 | this.reply(id); |
---|
432 | } |
---|
433 | |
---|
434 | /** |
---|
435 | * Abre uma pasta de email especifica. |
---|
436 | * |
---|
437 | * @param folder |
---|
438 | * Pasta de email a ser aberta. |
---|
439 | */ |
---|
440 | public void openFolder(String folder, boolean waitEmail) { |
---|
441 | waitForElement(By.id(folder)); |
---|
442 | clickElement(By.id(folder)); |
---|
443 | // Espera pelo "Carregando..." aparecer. |
---|
444 | waitForElement(By.id("divProgressBar")); |
---|
445 | waitForElement(By.id("divScrollMain_0")); |
---|
446 | // Espera pelo "Carregando..." desaparecer. |
---|
447 | isNotDisplayed(this |
---|
448 | .waitFindElement(By.id("divProgressBar"), 5000, 1000)); |
---|
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 | } |
---|
453 | } |
---|
454 | |
---|
455 | public void openFolder(String folder) { |
---|
456 | openFolder(folder, true); |
---|
457 | } |
---|
458 | |
---|
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(); |
---|
467 | waitForElement(By.id("divScrollMain_0")); |
---|
468 | } |
---|
469 | |
---|
470 | /** |
---|
471 | * Filtra somente as mensagens importantes. |
---|
472 | */ |
---|
473 | public void setImportantFilter() { |
---|
474 | this.importantFilter.click(); |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
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 | /** |
---|
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 | |
---|
513 | /** |
---|
514 | * Move email para um pasta no servidor. |
---|
515 | * |
---|
516 | * @param folderName |
---|
517 | * Nome da pasta pre-existente no servidor. |
---|
518 | */ |
---|
519 | public void moveEmail(String folderName) { |
---|
520 | this.moveEmailLink.click(); |
---|
521 | super.findAndClickElement("lINBOX/" + folderName + "wfolders_tree"); |
---|
522 | this.moveEmailButton.click(); |
---|
523 | } |
---|
524 | |
---|
525 | /** |
---|
526 | * Edita nome de pasta. |
---|
527 | */ |
---|
528 | public MailFolderPage editFolder() { |
---|
529 | this.toolsMenu.click(); |
---|
530 | this.waitForElement(By |
---|
531 | .xpath("//div[@id='menu_tools']/table/tbody/tr[4]/td")); |
---|
532 | this.editFolder.click(); |
---|
533 | |
---|
534 | return PageFactory.initElements(driver, MailFolderPage.class); |
---|
535 | } |
---|
536 | |
---|
537 | /** |
---|
538 | * Edita filtros. |
---|
539 | */ |
---|
540 | public MailFilterPage editFilter() { |
---|
541 | this.toolsMenu.click(); |
---|
542 | this.waitForElement(By |
---|
543 | .xpath("//div[@id='menu_tools']/table/tbody/tr[3]/td")); |
---|
544 | this.editFilter.click(); |
---|
545 | this.waitForElement(By.id("set_rules_img")); |
---|
546 | |
---|
547 | return PageFactory.initElements(driver, MailFilterPage.class); |
---|
548 | } |
---|
549 | |
---|
550 | /** |
---|
551 | * Marca email sendo composto como importante. |
---|
552 | */ |
---|
553 | public void checkImportantFlag() { |
---|
554 | this.important.click(); |
---|
555 | } |
---|
556 | |
---|
557 | /** |
---|
558 | * Marca email como importante apos ler. |
---|
559 | */ |
---|
560 | public void setImportantFlag() { |
---|
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]")); |
---|
563 | this.importantFlag.click(); |
---|
564 | } |
---|
565 | |
---|
566 | /** |
---|
567 | * Marca email como normal apos ler. |
---|
568 | */ |
---|
569 | public void setNormalFlag() { |
---|
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]")); |
---|
572 | this.normalFlag.click(); |
---|
573 | } |
---|
574 | |
---|
575 | /** |
---|
576 | * Marca email como nao lido apos ler. |
---|
577 | */ |
---|
578 | public void setNotReadFlag() { |
---|
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]")); |
---|
581 | this.notReadFlag.click(); |
---|
582 | } |
---|
583 | |
---|
584 | /** |
---|
585 | * Marca solicitacao de confirmacao de leitura do email sendo composto. |
---|
586 | */ |
---|
587 | public void checkReturnReceipt() { |
---|
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 | |
---|
608 | /** |
---|
609 | * Exporta email previamente selecionado. |
---|
610 | */ |
---|
611 | public void exportEmail() { |
---|
612 | this.exportEmailLink.click(); |
---|
613 | } |
---|
614 | |
---|
615 | /** |
---|
616 | * Seleciona todos emails da pasta corrente. |
---|
617 | */ |
---|
618 | public void selectAllEmails() { |
---|
619 | this.selectAllEmails.click(); |
---|
620 | } |
---|
621 | |
---|
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 | |
---|
655 | /** |
---|
656 | * Remove anexo do email sendo composto. |
---|
657 | */ |
---|
658 | public void removeAttachment() { |
---|
659 | this.removeAttachmentLink.click(); |
---|
660 | } |
---|
661 | |
---|
662 | public void addAttachment2(String attachment) { |
---|
663 | this.attachmentLink.click(); |
---|
664 | this.attachment2.sendKeys(attachment); |
---|
665 | } |
---|
666 | |
---|
667 | /** |
---|
668 | * Envia email sendo composto. |
---|
669 | */ |
---|
670 | public void sendMail() { |
---|
671 | this.send.click(); |
---|
672 | } |
---|
673 | |
---|
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 | |
---|
681 | /** |
---|
682 | * @param discardEmail |
---|
683 | */ |
---|
684 | public void closeMail(boolean discardEmail) { |
---|
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 | |
---|
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]")); |
---|
704 | } |
---|
705 | } |
---|
706 | |
---|
707 | public void closeMail(String id, boolean discardEmail) { |
---|
708 | super.clickElement(By.xpath("//td[@id='border_id_" + id + "']//img")); |
---|
709 | // Clica em cancelar |
---|
710 | if (discardEmail) { |
---|
711 | super.clickElement(By |
---|
712 | .xpath("//div[@id='lertWindow']/div[@id='lertButtons']/a[2]")); |
---|
713 | } |
---|
714 | } |
---|
715 | |
---|
716 | /** |
---|
717 | * Envia email. |
---|
718 | * |
---|
719 | * @param id |
---|
720 | * Id do email a ser enviado. |
---|
721 | */ |
---|
722 | public void sendMail(String id) { |
---|
723 | super.findAndClickElement("send_button_" + id); |
---|
724 | } |
---|
725 | |
---|
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? |
---|
748 | * @return "id" do email se encontrar, <code>null</code> se nao encontrar. |
---|
749 | */ |
---|
750 | public String findEmailIdBySuject(String subject, boolean select) { |
---|
751 | // System.out.println("searching for --------->" + subject); |
---|
752 | String html = driver.getPageSource(); |
---|
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); |
---|
760 | // System.out.println(id); |
---|
761 | if (select) { |
---|
762 | // Marca checkbox correspondente ao id da mensagem. |
---|
763 | clickElement(By.id("check_box" + id.substring(1))); |
---|
764 | } |
---|
765 | return id; |
---|
766 | } |
---|
767 | System.out.println("email not found"); |
---|
768 | return null; |
---|
769 | } |
---|
770 | |
---|
771 | /** |
---|
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 | |
---|
800 | /** |
---|
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 | /** |
---|
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) { |
---|
853 | return findEmailIdBySuject(subject, false); |
---|
854 | } |
---|
855 | |
---|
856 | /** |
---|
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 | /** |
---|
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) { |
---|
878 | Assert.assertEquals(getDisplayedElementContent("em_div_write_msg"), |
---|
879 | message); |
---|
880 | } |
---|
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 | |
---|
916 | /** |
---|
917 | * @param id |
---|
918 | * Id do email. |
---|
919 | * @return Texto do email. |
---|
920 | */ |
---|
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 | |
---|
928 | } |
---|