source: devel/testlink/automation2.0/src/test/java/org/expressolivre/cte/common/BaseTestCase.java @ 4780

Revision 4780, 4.3 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1771 - Refactoring, criadas novas classes para Pasta, Filtro, Pesquisa

Line 
1package org.expressolivre.cte.common;
2
3import java.io.IOException;
4
5import org.expressolivre.cte.pages.common.LoginPage;
6import org.expressolivre.cte.pages.common.PreferencesPage;
7import org.expressolivre.cte.pages.email.MailAdminPreferencesPage;
8import org.expressolivre.cte.pages.email.MailPreferencesPage;
9import org.openqa.selenium.By;
10import org.openqa.selenium.WebDriver;
11import org.openqa.selenium.firefox.FirefoxDriver;
12import org.openqa.selenium.support.PageFactory;
13import org.testng.SkipException;
14import org.testng.annotations.AfterClass;
15import org.testng.annotations.AfterSuite;
16import org.testng.annotations.BeforeClass;
17import org.testng.annotations.BeforeSuite;
18
19/**
20 * @author L.F.Estivalet (Serpro)
21 *
22 *         Created on Jan 4, 2011 at 3:53:19 PM
23 *
24 */
25public class BaseTestCase implements Constants {
26
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.
35         *
36         */
37        @BeforeSuite
38        public void beforeSuite() {
39                driver = new FirefoxDriver();
40                driver.get(URL);
41        }
42
43        /**
44         * Antes de cada classe de teste o login na aplicacao eh realizado.
45         */
46        @BeforeClass
47        public void login() {
48                LoginPage page = PageFactory.initElements(driver, LoginPage.class);
49                page.login(USER, PASS);
50        }
51
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();
58        }
59
60        /**
61         * Ao final da suite de testes fecha-se o driver (navegador).
62         */
63        @AfterSuite
64        public void afterSuite() {
65                driver.close();
66        }
67
68        /**
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        /**
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        /**
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        /**
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
167}
Note: See TracBrowser for help on using the repository browser.