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

Revision 4864, 3.6 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1771 - Adicionado testes automatizados para modulo da agenda

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.openqa.selenium.By;
8import org.openqa.selenium.WebDriver;
9import org.openqa.selenium.firefox.FirefoxDriver;
10import org.openqa.selenium.support.PageFactory;
11import org.testng.SkipException;
12import org.testng.annotations.AfterClass;
13import org.testng.annotations.AfterSuite;
14import org.testng.annotations.BeforeClass;
15import org.testng.annotations.BeforeSuite;
16
17/**
18 * @author L.F.Estivalet (Serpro)
19 *
20 *         Created on Jan 4, 2011 at 3:53:19 PM
21 *
22 */
23public class BaseTestCase implements Constants {
24
25        /** Driver utilizado para rodar os testes. */
26        protected static WebDriver driver;
27
28        /**
29         * Antes de comecar a suite de testes abrir o navegador.
30         *
31         * TODO Parametrizar o driver de forma a abrir outros navegadores como o
32         * Internet Explorer por exemplo.
33         *
34         */
35        @BeforeSuite
36        public void beforeSuite() {
37                // Use code below to run through a proxy.
38                // Value for network.proxy.http_port should be integer (no quotes should
39                // be used) and network.proxy.type should be set as 1 (ProxyType.MANUAL,
40                // Manual proxy settings)
41                // FirefoxProfile profile = new FirefoxProfile();
42                // profile.setPreference("network.proxy.type", 1);
43                // profile.setPreference("network.proxy.http", "10.200.113.61");
44                // profile.setPreference("network.proxy.http_port", 3128);
45                // driver = new FirefoxDriver(profile);
46
47                driver = new FirefoxDriver();
48                driver.get(URL);
49        }
50
51        /**
52         * Antes de cada classe de teste o login na aplicacao eh realizado.
53         */
54        @BeforeClass
55        public void login() {
56                LoginPage page = PageFactory.initElements(driver, LoginPage.class);
57                page.login(USER, PASS);
58        }
59
60        /**
61         * Ao final de cada classe de teste o logout na aplicacao eh realizado.
62         */
63        @AfterClass
64        public void logout() {
65                driver.findElement(By.id("logout_id")).click();
66        }
67
68        /**
69         * Ao final da suite de testes fecha-se o driver (navegador).
70         */
71        @AfterSuite
72        public void afterSuite() {
73                driver.close();
74        }
75
76        /**
77         * Abre a pagina de preferencias do usuario.
78         *
79         * @return
80         */
81        public PreferencesPage openPreferencesPage() {
82                driver.get(URL_PREFERENCES);
83                return PageFactory.initElements(driver, PreferencesPage.class);
84        }
85
86        /**
87         * Verifica a presenca de uma preferencia.
88         *
89         * @param preference
90         *            Preferencia a verificar
91         * @throws IOException
92         *             Problema ao ler arquivo temporario das preferencias
93         * @throws SkipException
94         *             Se a preferencia procurada nao existir, o caso de teste nao
95         *             deve ser executado pois a funcionalidade referente nao esta
96         *             disponivel na configuracao.
97         */
98        public void checkPreference(String preference) throws IOException,
99                        SkipException {
100                String contents = IOUtil.readFully("temppref.txt");
101                if (!contents.contains(preference)) {
102                        throw new SkipException("TESTE NÃO EXECUTADO. Preferência "
103                                        + preference + " não está disponível");
104                }
105        }
106
107        /**
108         * TODO Rever esse metodo. Foi o unico jeito que consegui fazer pegar o
109         * numero total de mensagens importantes. O metodo apenas aguarda 5 segundos
110         * antes de continuar a execucao.
111         *
112         * @throws Exception
113         *
114         * @see br.gov.serpro.cte.email.listar.ListarEmailsImportantesTestCase
115         */
116        public void dummyWait() throws Exception {
117                dummyWait(5);
118        }
119
120        /**
121         * @param seconds
122         * @throws Exception
123         */
124        public void dummyWait(int seconds) throws Exception {
125                for (int second = 0;; second++) {
126                        if (second >= seconds) {
127                                System.out.println("timeout");
128                                return;
129                        }
130                        Thread.sleep(1000);
131                }
132
133        }
134
135}
Note: See TracBrowser for help on using the repository browser.