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

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