source: devel/testlink/automation/src/test/java/br/gov/serpro/cte/common/BaseTestCase.java @ 3521

Revision 3521, 2.3 KB checked in by luiz-fernando, 13 years ago (diff)

Ticket #1402 - Automacao dos casos de teste do Expresso documentados no Testlink

Line 
1package br.gov.serpro.cte.common;
2
3import org.junit.After;
4import org.junit.Before;
5
6import br.gov.serpro.cte.connection.DAOSelenium;
7
8import com.thoughtworks.selenium.SeleneseTestCase;
9
10/**
11 * Contem metodos comuns a todos os casos de teste do Expresso.
12 *
13 * @author L.F.Estivalet (Serpro)
14 *
15 *         Created on Nov 12, 2010 at 11:50:55 AM
16 *
17 */
18public class BaseTestCase extends SeleneseTestCase {
19        @Before
20        public void setUp() throws Exception {
21                String url = "https://cte.serpro.gov.br";
22                DAOSelenium conn = new DAOSelenium("localhost", 4444, "*firefox", url);
23                selenium = conn.newConnection();
24        }
25
26        /**
27         * Executa o login no Expresso.
28         */
29        public void login() {
30                selenium.open("/login.php");
31                selenium.type("user", "luiz-fernando.estivalet");
32                selenium.type("passwd", "senha");
33                selenium.click("submitit");
34                selenium.waitForPageToLoad("30000");
35        }
36
37        /**
38         * Aguarda por um elemento aparecer na pagina.
39         *
40         * @param element
41         *            Elemento a aguardar.
42         * @throws Exception
43         *             Elemento nao encontrado
44         */
45        public void waitForElement(String element) throws Exception {
46                waitForElement(element, false);
47        }
48
49        /**
50         * Aguarda por um elemento aparecer na pagina.
51         *
52         * @param element
53         *            Elemento a aguardar.
54         * @param click
55         *            Se elemento encontrado, deseja clicar sobre o mesmo?
56         * @throws Exception
57         *             Elemento nao encontrado
58         */
59        public void waitForElement(String element, boolean click) throws Exception {
60                for (int second = 0;; second++) {
61                        if (second >= 60)
62                                fail("timeout");
63                        try {
64                                if (selenium.isElementPresent(element))
65                                        break;
66                        } catch (Exception e) {
67                        }
68                        Thread.sleep(1000);
69                }
70                if (click) {
71                        selenium.click(element);
72                }
73        }
74
75        /**
76         * TODO Rever esse metodo. Foi o unico jeito que consegui fazer pegar o
77         * numero total de mensagens importantes. O metodo apenas aguarda 5 segundos
78         * antes de continuar a execucao.
79         *
80         * @throws Exception
81         *
82         * @see br.gov.serpro.cte.email.listar.ListarEmailsImportantesTestCase
83         */
84        public void dummyWait() throws Exception {
85                for (int second = 0;; second++) {
86                        if (second >= 5) {
87                                System.out.println("timeout");
88                                return;
89                        }
90                        Thread.sleep(1000);
91                }
92
93        }
94
95        @After
96        public void tearDown() throws Exception {
97                selenium.stop();
98        }
99
100}
Note: See TracBrowser for help on using the repository browser.