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

Revision 4962, 4.0 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        }
86
87        /**
88         * Abre a pagina de preferencias do usuario.
89         *
90         * @return
91         */
92        public PreferencesPage openPreferencesPage() {
93                driver.get(URL_PREFERENCES);
94                return PageFactory.initElements(driver, PreferencesPage.class);
95        }
96
97        /**
98         * Verifica a presenca de uma preferencia.
99         *
100         * @param preference
101         *            Preferencia a verificar
102         * @throws IOException
103         *             Problema ao ler arquivo temporario das preferencias
104         * @throws SkipException
105         *             Se a preferencia procurada nao existir, o caso de teste nao
106         *             deve ser executado pois a funcionalidade referente nao esta
107         *             disponivel na configuracao.
108         */
109        public void checkPreference(String preference) throws IOException,
110                        SkipException {
111                String contents = IOUtil.readFully("temppref.txt");
112                if (!contents.contains(preference)) {
113                        throw new SkipException("TESTE NÃO EXECUTADO. Preferência "
114                                        + preference + " não está disponível");
115                }
116        }
117
118        /**
119         * TODO Rever esse metodo. Foi o unico jeito que consegui fazer pegar o
120         * numero total de mensagens importantes. O metodo apenas aguarda 5 segundos
121         * antes de continuar a execucao.
122         *
123         * @throws Exception
124         *
125         * @see br.gov.serpro.cte.email.listar.ListarEmailsImportantesTestCase
126         */
127        public void dummyWait() throws Exception {
128                dummyWait(5);
129        }
130
131        /**
132         * @param seconds
133         * @throws Exception
134         */
135        public void dummyWait(int seconds) throws Exception {
136                for (int second = 0;; second++) {
137                        if (second >= seconds) {
138                                System.out.println("timeout");
139                                return;
140                        }
141                        Thread.sleep(1000);
142                }
143
144        }
145
146}
Note: See TracBrowser for help on using the repository browser.