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

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