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