[3782] | 1 | package org.expressolivre.cte.common; |
---|
[3663] | 2 | |
---|
[3782] | 3 | import org.expressolivre.cte.pages.common.LoginPage; |
---|
| 4 | import org.expressolivre.cte.pages.common.PreferencesPage; |
---|
[4627] | 5 | import org.expressolivre.cte.pages.email.MailAdminPreferencesPage; |
---|
| 6 | import org.expressolivre.cte.pages.email.MailPreferencesPage; |
---|
[3766] | 7 | import org.openqa.selenium.By; |
---|
[3663] | 8 | import org.openqa.selenium.WebDriver; |
---|
| 9 | import org.openqa.selenium.firefox.FirefoxDriver; |
---|
| 10 | import org.openqa.selenium.support.PageFactory; |
---|
| 11 | import org.testng.annotations.AfterClass; |
---|
[3766] | 12 | import org.testng.annotations.AfterSuite; |
---|
[3663] | 13 | import org.testng.annotations.BeforeClass; |
---|
[3766] | 14 | import org.testng.annotations.BeforeSuite; |
---|
[3663] | 15 | |
---|
| 16 | /** |
---|
| 17 | * @author L.F.Estivalet (Serpro) |
---|
| 18 | * |
---|
| 19 | * Created on Jan 4, 2011 at 3:53:19 PM |
---|
| 20 | * |
---|
| 21 | */ |
---|
| 22 | public class BaseTestCase implements Constants { |
---|
| 23 | |
---|
[3766] | 24 | /** Driver utilizado para rodar os testes. */ |
---|
| 25 | protected static WebDriver driver; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Antes de comecar a suite de testes abrir o navegador. |
---|
| 29 | * |
---|
| 30 | * TODO Parametrizar o driver de forma a abrir outros navegadores como o |
---|
| 31 | * Internet Explorer por exemplo. |
---|
[3789] | 32 | * |
---|
[3766] | 33 | */ |
---|
| 34 | @BeforeSuite |
---|
| 35 | public void beforeSuite() { |
---|
[3663] | 36 | driver = new FirefoxDriver(); |
---|
| 37 | driver.get(URL); |
---|
| 38 | } |
---|
| 39 | |
---|
[3766] | 40 | /** |
---|
| 41 | * Antes de cada classe de teste o login na aplicacao eh realizado. |
---|
| 42 | */ |
---|
| 43 | @BeforeClass |
---|
[3663] | 44 | public void login() { |
---|
| 45 | LoginPage page = PageFactory.initElements(driver, LoginPage.class); |
---|
| 46 | page.login(USER, PASS); |
---|
| 47 | } |
---|
| 48 | |
---|
[3766] | 49 | /** |
---|
| 50 | * Ao final de cada classe de teste o logout na aplicacao eh realizado. |
---|
| 51 | */ |
---|
| 52 | @AfterClass |
---|
| 53 | public void logout() { |
---|
| 54 | driver.findElement(By.id("logout_id")).click(); |
---|
[3745] | 55 | } |
---|
| 56 | |
---|
[3766] | 57 | /** |
---|
| 58 | * Ao final da suite de testes fecha-se o driver (navegador). |
---|
| 59 | */ |
---|
| 60 | @AfterSuite |
---|
| 61 | public void afterSuite() { |
---|
[3663] | 62 | driver.close(); |
---|
| 63 | } |
---|
| 64 | |
---|
[3708] | 65 | /** |
---|
[3766] | 66 | * Abre a pagina de preferencias do usuario. |
---|
| 67 | * |
---|
| 68 | * @return |
---|
| 69 | */ |
---|
| 70 | public PreferencesPage openPreferencesPage() { |
---|
| 71 | driver.get(URL_PREFERENCES); |
---|
| 72 | return PageFactory.initElements(driver, PreferencesPage.class); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | /** |
---|
[4627] | 76 | * Abre pagina de preferencias do modulo ExpressoMail |
---|
| 77 | * |
---|
| 78 | * @return |
---|
| 79 | */ |
---|
| 80 | public MailPreferencesPage openEmailPreferencesPage() { |
---|
| 81 | driver.get(URL_PREFERENCES_EMAIL); |
---|
| 82 | return PageFactory.initElements(driver, MailPreferencesPage.class); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * Abre pagina de preferencias administrativas do modulo ExpressoMail. |
---|
| 87 | * |
---|
| 88 | * @return |
---|
| 89 | */ |
---|
| 90 | public MailAdminPreferencesPage openEmailAdminPreferencesPage() { |
---|
| 91 | driver.get(URL_PREFERENCES_EMAIL); |
---|
| 92 | return PageFactory.initElements(driver, MailAdminPreferencesPage.class); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * Abre pagina de preferencias administrativas do modulo ExpressoMail. |
---|
| 97 | * |
---|
| 98 | * @return |
---|
| 99 | */ |
---|
| 100 | public MailAdminPreferencesPage openEmailAdminDefaultPreferencesPage() { |
---|
| 101 | driver.get(URL_DEFAULT_PREFERENCES_EMAIL); |
---|
| 102 | return PageFactory.initElements(driver, MailAdminPreferencesPage.class); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Abre pagina de preferencias administrativas do modulo ExpressoMail. |
---|
| 107 | * |
---|
| 108 | * @return |
---|
| 109 | */ |
---|
| 110 | public MailAdminPreferencesPage openEmailAdminForcedPreferencesPage() { |
---|
| 111 | driver.get(URL_FORCED_PREFERENCES_EMAIL); |
---|
| 112 | return PageFactory.initElements(driver, MailAdminPreferencesPage.class); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
[3708] | 116 | * TODO Rever esse metodo. Foi o unico jeito que consegui fazer pegar o |
---|
| 117 | * numero total de mensagens importantes. O metodo apenas aguarda 5 segundos |
---|
| 118 | * antes de continuar a execucao. |
---|
| 119 | * |
---|
| 120 | * @throws Exception |
---|
| 121 | * |
---|
| 122 | * @see br.gov.serpro.cte.email.listar.ListarEmailsImportantesTestCase |
---|
| 123 | */ |
---|
| 124 | public void dummyWait() throws Exception { |
---|
| 125 | dummyWait(5); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | /** |
---|
| 129 | * @param seconds |
---|
| 130 | * @throws Exception |
---|
| 131 | */ |
---|
| 132 | public void dummyWait(int seconds) throws Exception { |
---|
| 133 | for (int second = 0;; second++) { |
---|
| 134 | if (second >= seconds) { |
---|
| 135 | System.out.println("timeout"); |
---|
| 136 | return; |
---|
| 137 | } |
---|
| 138 | Thread.sleep(1000); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | } |
---|
| 142 | |
---|
[3663] | 143 | } |
---|