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