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 | |
---|
13 | /** |
---|
14 | * @author L.F.Estivalet (Serpro) |
---|
15 | * |
---|
16 | * Created on Dec 16, 2010 at 9:43:21 AM |
---|
17 | * |
---|
18 | */ |
---|
19 | public 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 | @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[1]") |
---|
137 | private WebElement cancelNewEmail; |
---|
138 | |
---|
139 | @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[2]") |
---|
140 | private WebElement discardNewEmail; |
---|
141 | |
---|
142 | @FindBy(xpath = "//div[@id='lertContainer']/div[@id='lertWindow']/div[@id='lertButtons']/a[3]") |
---|
143 | /** Esse botao eh no alerta ao fechar uma mensagem nao salva e nao o botao salvar para rascunhos. */ |
---|
144 | private WebElement saveNewEmail; |
---|
145 | |
---|
146 | /** |
---|
147 | * @param driver |
---|
148 | */ |
---|
149 | public MailPage(WebDriver driver) { |
---|
150 | super(driver); |
---|
151 | } |
---|
152 | |
---|
153 | public void createNewEmail() { |
---|
154 | this.newEmail.click(); |
---|
155 | waitForElement(By.id("to_1")); |
---|
156 | } |
---|
157 | |
---|
158 | public void cancelNewEmail() { |
---|
159 | this.cancelNewEmail.click(); |
---|
160 | } |
---|
161 | |
---|
162 | public void discardNewEmail() { |
---|
163 | this.discardNewEmail.click(); |
---|
164 | } |
---|
165 | |
---|
166 | public void saveNewEmail() { |
---|
167 | this.saveNewEmail.click(); |
---|
168 | } |
---|
169 | |
---|
170 | public void setSubject(String subject) { |
---|
171 | this.subject.sendKeys(subject != null ? subject : ""); |
---|
172 | } |
---|
173 | |
---|
174 | public void setBody(String body) { |
---|
175 | // Foi o unico jeito que consegui pegar o richtexteditor... |
---|
176 | if (body != null) { |
---|
177 | ((JavascriptExecutor) driver) |
---|
178 | .executeScript("document.getElementById('body_1').contentWindow.document.body.innerHTML='" |
---|
179 | + body + "';"); |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | /** |
---|
184 | * @param to |
---|
185 | * @param subject |
---|
186 | * @param body |
---|
187 | */ |
---|
188 | public void composeEmail(String to, String subject, String body) { |
---|
189 | this.createNewEmail(); |
---|
190 | this.to.sendKeys(to); |
---|
191 | this.setSubject(subject); |
---|
192 | this.setBody(body); |
---|
193 | } |
---|
194 | |
---|
195 | public String readEmail(String subject) { |
---|
196 | // waitForElementByXpath("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]"); |
---|
197 | String id = findEmailIdBySuject(subject); |
---|
198 | id = id.substring(id.lastIndexOf("_") + 1); |
---|
199 | clickElement(By.id("td_who_" + id)); |
---|
200 | super.waitForElement(By.id("div_message_scroll_" + id + "_r")); |
---|
201 | return id; |
---|
202 | } |
---|
203 | |
---|
204 | public void editEmail() { |
---|
205 | super.waitForElement(By |
---|
206 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]")); |
---|
207 | // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1] |
---|
208 | this.editEmail.click(); |
---|
209 | } |
---|
210 | |
---|
211 | public void editEmail(String id) { |
---|
212 | super.waitForElement(By |
---|
213 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[2]/span[1]")); |
---|
214 | // div[@id='exmail_main_body']/div[@id='content_id_9_r']/table/tbody/tr[1]/td/table/tbody/tr/td[2]/span[1] |
---|
215 | this.editEmail.click(); |
---|
216 | waitForElement(By.id("content_id_" + id)); |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * Encaminha uma mensagem. |
---|
221 | * |
---|
222 | * @param id |
---|
223 | * Id da mensagem a ser encaminhada |
---|
224 | * @param to |
---|
225 | * Destinatario |
---|
226 | */ |
---|
227 | public void forwardEmail(String id, String to) { |
---|
228 | super.waitForElement(By |
---|
229 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]")); |
---|
230 | this.forwardEmail.click(); |
---|
231 | super.waitForElement(By.id("to_" + id)); |
---|
232 | driver.findElement(By.id("to_" + id)).sendKeys(to); |
---|
233 | driver.findElement(By.id("send_button_" + id)).click(); |
---|
234 | } |
---|
235 | |
---|
236 | private void reply(String id) { |
---|
237 | super.waitForElement(By.id("to_" + id)); |
---|
238 | driver.findElement(By.id("send_button_" + id)).click(); |
---|
239 | } |
---|
240 | |
---|
241 | /** |
---|
242 | * Responde uma mensagem. |
---|
243 | * |
---|
244 | * @param id |
---|
245 | * Id da mensagem a ser respondida |
---|
246 | */ |
---|
247 | public void replyEmail(String id) { |
---|
248 | super.waitForElement(By |
---|
249 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[5]")); |
---|
250 | this.replyEmail.click(); |
---|
251 | this.reply(id); |
---|
252 | } |
---|
253 | |
---|
254 | /** |
---|
255 | * Responde uma mensagem. |
---|
256 | * |
---|
257 | * @param id |
---|
258 | * Id da mensagem a ser respondida |
---|
259 | */ |
---|
260 | public void replyAllEmailWithoutHistory(String id) { |
---|
261 | super.findAndClickElement("msg_opt_reply_options_" + id + "_r"); |
---|
262 | super.waitForElement(By |
---|
263 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[3]")); |
---|
264 | this.replyAllEmailWithoutHistory.click(); |
---|
265 | this.reply(id); |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * Responde uma mensagem. |
---|
270 | * |
---|
271 | * @param id |
---|
272 | * Id da mensagem a ser respondida |
---|
273 | */ |
---|
274 | public void replyEmailWithoutHistory(String id) { |
---|
275 | super.findAndClickElement("msg_opt_reply_options_" + id + "_r"); |
---|
276 | super.waitForElement(By |
---|
277 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[2]")); |
---|
278 | this.replyEmailWithoutHistory.click(); |
---|
279 | this.reply(id); |
---|
280 | } |
---|
281 | |
---|
282 | /** |
---|
283 | * Responde uma mensagem. |
---|
284 | * |
---|
285 | * @param id |
---|
286 | * Id da mensagem a ser respondida |
---|
287 | */ |
---|
288 | public void replyAllEmail(String id) { |
---|
289 | super.findAndClickElement("msg_opt_reply_options_" + id + "_r"); |
---|
290 | super.waitForElement(By |
---|
291 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span[1]")); |
---|
292 | this.replyAllEmail.click(); |
---|
293 | this.reply(id); |
---|
294 | } |
---|
295 | |
---|
296 | /** |
---|
297 | * Abre uma pasta de email especifica. |
---|
298 | * |
---|
299 | * @param folder |
---|
300 | * Pasta de email a ser aberta. |
---|
301 | */ |
---|
302 | public void openFolder(String folder) { |
---|
303 | clickElement(By.id(folder)); |
---|
304 | waitForElement(By.id("divScrollMain_0")); |
---|
305 | waitForElement(By |
---|
306 | .xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[1]/td[1]/input[1]")); |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | * Abre uma pasta de email especifica. |
---|
311 | * |
---|
312 | * @param folder |
---|
313 | * Pasta de email a ser aberta. |
---|
314 | */ |
---|
315 | public void openFolder(WebElement folder) { |
---|
316 | folder.click(); |
---|
317 | waitForElement(By.id("divScrollMain_0")); |
---|
318 | } |
---|
319 | |
---|
320 | public void setImportantFilter() { |
---|
321 | this.importantFilter.click(); |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * Limpa a lixeira. |
---|
326 | */ |
---|
327 | public void cleanupTrash() { |
---|
328 | this.openFolder(this.trashFolder); |
---|
329 | this.emptyTrashLink.click(); |
---|
330 | } |
---|
331 | |
---|
332 | /** |
---|
333 | * @return Numero de emails na pasta selecionada. |
---|
334 | */ |
---|
335 | public int getTotalEmails() { |
---|
336 | return Integer.valueOf(this.totalEmails.getText()); |
---|
337 | } |
---|
338 | |
---|
339 | public void moveEmail(String folderName) { |
---|
340 | this.moveEmailLink.click(); |
---|
341 | super.findAndClickElement("lINBOX/" + folderName + "wfolders_tree"); |
---|
342 | this.moveEmailButton.click(); |
---|
343 | } |
---|
344 | |
---|
345 | public void editFolder() { |
---|
346 | this.toolsMenu.click(); |
---|
347 | this.waitForElement(By |
---|
348 | .xpath("//div[@id='menu_tools']/table/tbody/tr[4]/td")); |
---|
349 | this.editFolder.click(); |
---|
350 | } |
---|
351 | |
---|
352 | public void createNewFolder(String folderName) { |
---|
353 | this.editFolder(); |
---|
354 | this.createNewFolder.click(); |
---|
355 | Alert newFolder = driver.switchTo().alert(); |
---|
356 | assert "Insira o nome da nova pasta: ".equals(newFolder.getText()); |
---|
357 | newFolder.sendKeys(folderName); |
---|
358 | newFolder.accept(); |
---|
359 | } |
---|
360 | |
---|
361 | public void deleteFolder(String folderName) { |
---|
362 | this.editFolder(); |
---|
363 | this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree")) |
---|
364 | .click(); |
---|
365 | this.deleteFolder.click(); |
---|
366 | Alert confirm = driver.switchTo().alert(); |
---|
367 | assert ("Você gostaria de excluir a pasta: " + folderName + "?") |
---|
368 | .equals(confirm.getText()); |
---|
369 | confirm.accept(); |
---|
370 | } |
---|
371 | |
---|
372 | /** |
---|
373 | * Marca email sendo composto como importante. |
---|
374 | */ |
---|
375 | public void checkImportantFlag() { |
---|
376 | this.important.click(); |
---|
377 | } |
---|
378 | |
---|
379 | public void setImportantFlag() { |
---|
380 | this.waitForElement(By |
---|
381 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]")); |
---|
382 | this.importantFlag.click(); |
---|
383 | } |
---|
384 | |
---|
385 | public void setNormalFlag() { |
---|
386 | this.waitForElement(By |
---|
387 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]")); |
---|
388 | this.normalFlag.click(); |
---|
389 | } |
---|
390 | |
---|
391 | public void setNotReadFlag() { |
---|
392 | this.waitForElement(By |
---|
393 | .xpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]")); |
---|
394 | this.notReadFlag.click(); |
---|
395 | } |
---|
396 | |
---|
397 | /** |
---|
398 | * Marca solicitacao de confirmacao de leitura do email sendo composto. |
---|
399 | */ |
---|
400 | public void checkReturnReceipt() { |
---|
401 | this.returnReceipt.click(); |
---|
402 | } |
---|
403 | |
---|
404 | /** |
---|
405 | * Salva email sendo composto (devera ir para a pasta de Rascunhos). |
---|
406 | * |
---|
407 | * TODO adicionar teste para verificar se o email realmente esta presente na |
---|
408 | * pasta Rascunhos?? |
---|
409 | */ |
---|
410 | public void saveEmail() { |
---|
411 | this.saveEmail.click(); |
---|
412 | } |
---|
413 | |
---|
414 | /** |
---|
415 | * Apaga email previamente selecionado. |
---|
416 | */ |
---|
417 | public void deleteEmail() { |
---|
418 | this.deleteEmailLink.click(); |
---|
419 | } |
---|
420 | |
---|
421 | public void selectAllEmails() { |
---|
422 | this.selectAllEmails.click(); |
---|
423 | } |
---|
424 | |
---|
425 | /** |
---|
426 | * Adiciona email no campo de copia oculta. |
---|
427 | * |
---|
428 | * @param email |
---|
429 | * Email a ser adicionado. |
---|
430 | */ |
---|
431 | public void setBlindCarbonCopy(String email) { |
---|
432 | this.blindCarbonCopyLink.click(); |
---|
433 | this.blindCarbonCopy.sendKeys(email); |
---|
434 | } |
---|
435 | |
---|
436 | /** |
---|
437 | * Adiciona email no campo de copia. |
---|
438 | * |
---|
439 | * @param email |
---|
440 | * Email a ser adicionado. |
---|
441 | */ |
---|
442 | public void setCarbonCopy(String email) { |
---|
443 | this.carbonCopyLink.click(); |
---|
444 | this.carbonCopy.sendKeys(email); |
---|
445 | } |
---|
446 | |
---|
447 | /** |
---|
448 | * Anexo um arquivo no email sendo composto. |
---|
449 | * |
---|
450 | * @param attachment |
---|
451 | * Caminho para o arquivo a ser anexado. |
---|
452 | */ |
---|
453 | public void addAttachment(String attachment) { |
---|
454 | this.attachmentLink.click(); |
---|
455 | this.attachment.sendKeys(attachment); |
---|
456 | } |
---|
457 | |
---|
458 | public void addAttachment2(String attachment) { |
---|
459 | this.attachmentLink.click(); |
---|
460 | this.attachment2.sendKeys(attachment); |
---|
461 | } |
---|
462 | |
---|
463 | /** |
---|
464 | * Envia email sendo composto. |
---|
465 | */ |
---|
466 | public void sendMail() { |
---|
467 | this.send.click(); |
---|
468 | } |
---|
469 | |
---|
470 | /** |
---|
471 | * Fecha aba do email sendo composto e confirma que email nao esta salvo. |
---|
472 | */ |
---|
473 | public void closeMail() { |
---|
474 | this.closeMail(true); |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
478 | * @param checkAlert |
---|
479 | */ |
---|
480 | public void closeMail(boolean checkAlert) { |
---|
481 | |
---|
482 | // Na versao Serpro: |
---|
483 | // td[@id='border_id_1']/table/tbody/tr/td[2]/img |
---|
484 | |
---|
485 | // Na versao Comunidade: |
---|
486 | // td[@id='border_id_1']/div/div[2]/img |
---|
487 | |
---|
488 | // Resolvi usando o xpath abaixo: |
---|
489 | super.clickElement(By.xpath("//td[@id='border_id_1']//img")); |
---|
490 | |
---|
491 | if (checkAlert) { |
---|
492 | Alert closeAlert = driver.switchTo().alert(); |
---|
493 | closeAlert.accept(); |
---|
494 | } |
---|
495 | } |
---|
496 | |
---|
497 | public void closeMail(String id) { |
---|
498 | super.clickElement(By.xpath("//td[@id='border_id_" + id + "']//img")); |
---|
499 | } |
---|
500 | |
---|
501 | public void sendMail(String id) { |
---|
502 | super.findAndClickElement("send_button_" + id); |
---|
503 | } |
---|
504 | |
---|
505 | /** |
---|
506 | * @param to |
---|
507 | * @param subject |
---|
508 | */ |
---|
509 | public void composeEmail(String to, String subject) { |
---|
510 | composeEmail(to, subject, null); |
---|
511 | } |
---|
512 | |
---|
513 | /** |
---|
514 | * @param to |
---|
515 | */ |
---|
516 | public void composeEmail(String to) { |
---|
517 | composeEmail(to, null, null); |
---|
518 | } |
---|
519 | |
---|
520 | /** |
---|
521 | * Procura um email pelo assunto. |
---|
522 | * |
---|
523 | * @param subject |
---|
524 | * Assunto a ser procurado. |
---|
525 | * @param select |
---|
526 | * Se email encontrado, deseja seleciona-lo? |
---|
527 | * @return "id" do email. |
---|
528 | */ |
---|
529 | public String findEmailIdBySuject(String subject, boolean select) { |
---|
530 | String html = driver.getPageSource(); |
---|
531 | String part1 = StringUtils.substringBefore(html, subject); |
---|
532 | int start = StringUtils.lastIndexOf(part1, "id=\"") + 4; |
---|
533 | int last = StringUtils.indexOf(part1, "\"", start); |
---|
534 | String id = StringUtils.substring(part1, start, last); |
---|
535 | |
---|
536 | if (select) { |
---|
537 | // Marca checkbox correspondente ao id da mensagem. |
---|
538 | clickElement(By.id("check_box" + id.substring(1))); |
---|
539 | } |
---|
540 | return id; |
---|
541 | } |
---|
542 | |
---|
543 | /** |
---|
544 | * @return Ids de todos os emails da pasta selecionada. |
---|
545 | */ |
---|
546 | public String[] getEmailIds() { |
---|
547 | String[] ids = new String[this.getTotalEmails()]; |
---|
548 | for (int i = 1; i <= this.getTotalEmails(); i++) { |
---|
549 | String id = driver |
---|
550 | .findElement( |
---|
551 | By.xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[" |
---|
552 | + i + "]/td[1]/input[1]")).getAttribute( |
---|
553 | "id"); |
---|
554 | ids[i - 1] = id.substring(id.lastIndexOf("_") + 1); |
---|
555 | } |
---|
556 | return ids; |
---|
557 | } |
---|
558 | |
---|
559 | /** |
---|
560 | * @param emailId |
---|
561 | * Id do email. |
---|
562 | * @return <code>true</code> se email importante, <code>false</code> caso |
---|
563 | * contrario. |
---|
564 | */ |
---|
565 | public boolean isImportant(String emailId) { |
---|
566 | return super |
---|
567 | .isDisplayed((RenderedWebElement) driver.findElement(By |
---|
568 | .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='" |
---|
569 | + emailId + "']/td[5]/img"))); |
---|
570 | } |
---|
571 | |
---|
572 | public String findEmailIdBySuject(String subject) { |
---|
573 | return findEmailIdBySuject(subject, false); |
---|
574 | } |
---|
575 | |
---|
576 | /** |
---|
577 | * Verifica se mensagem informada corresponde ao exibido pelo Expresso na |
---|
578 | * div onde sao exibidas mensagens ao usuario. |
---|
579 | * |
---|
580 | * @param message |
---|
581 | * Mensagem a ser validada. |
---|
582 | */ |
---|
583 | public void assertMessage(String message) { |
---|
584 | assert message.equals(getDisplayedElementContent("em_div_write_msg")); |
---|
585 | } |
---|
586 | |
---|
587 | /** |
---|
588 | * @return the to |
---|
589 | */ |
---|
590 | public WebElement getTo(String id) { |
---|
591 | waitForElement(By.id("to_" + id)); |
---|
592 | // findAndClickElement("to_" + id); |
---|
593 | // return getDisplayedElementContent(id); |
---|
594 | return driver.findElement(By.id("to_" + id)); |
---|
595 | } |
---|
596 | |
---|
597 | /** |
---|
598 | * @return the subject |
---|
599 | */ |
---|
600 | public WebElement getSubject(String id) { |
---|
601 | waitForElement(By.id("subject_" + id)); |
---|
602 | return driver.findElement(By.id("subject_" + id)); |
---|
603 | } |
---|
604 | |
---|
605 | /** |
---|
606 | * @return the blindCarbonCopy |
---|
607 | */ |
---|
608 | public WebElement getBlindCarbonCopy(String id) { |
---|
609 | waitForElement(By.id("cco_" + id)); |
---|
610 | return driver.findElement(By.id("cco_" + id)); |
---|
611 | } |
---|
612 | |
---|
613 | /** |
---|
614 | * @return the carbonCopy |
---|
615 | */ |
---|
616 | public WebElement getCarbonCopy(String id) { |
---|
617 | waitForElement(By.id("cc_" + id)); |
---|
618 | return driver.findElement(By.id("cc_" + id)); |
---|
619 | } |
---|
620 | |
---|
621 | public Object getBody(String id) { |
---|
622 | waitForElement(By.id("body_" + id)); |
---|
623 | return ((JavascriptExecutor) driver) |
---|
624 | .executeScript("return document.getElementById('body_" + id |
---|
625 | + "').contentWindow.document.body.innerHTML;"); |
---|
626 | } |
---|
627 | |
---|
628 | } |
---|