package br.gov.serpro.cte.common; import org.junit.After; import org.junit.Before; import br.gov.serpro.cte.connection.DAOSelenium; import com.thoughtworks.selenium.SeleneseTestCase; /** * Contem metodos comuns a todos os casos de teste do Expresso. * * @author L.F.Estivalet (Serpro) * * Created on Nov 12, 2010 at 11:50:55 AM * */ public class BaseTestCase extends SeleneseTestCase { @Before public void setUp() throws Exception { String url = "https://cte.serpro.gov.br"; DAOSelenium conn = new DAOSelenium("localhost", 4444, "*firefox", url); selenium = conn.newConnection(); } /** * Executa o login no Expresso. */ public void login() { selenium.open("/login.php"); selenium.type("user", "luiz-fernando.estivalet"); selenium.type("passwd", "senha"); selenium.click("submitit"); selenium.waitForPageToLoad("30000"); } /** * Aguarda por um elemento aparecer na pagina. * * @param element * Elemento a aguardar. * @throws Exception * Elemento nao encontrado */ public void waitForElement(String element) throws Exception { waitForElement(element, false); } /** * Aguarda por um elemento aparecer na pagina. * * @param element * Elemento a aguardar. * @param click * Se elemento encontrado, deseja clicar sobre o mesmo? * @throws Exception * Elemento nao encontrado */ public void waitForElement(String element, boolean click) throws Exception { for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (selenium.isElementPresent(element)) break; } catch (Exception e) { } Thread.sleep(1000); } if (click) { selenium.click(element); } } /** * TODO Rever esse metodo. Foi o unico jeito que consegui fazer pegar o * numero total de mensagens importantes. O metodo apenas aguarda 5 segundos * antes de continuar a execucao. * * @throws Exception * * @see br.gov.serpro.cte.email.listar.ListarEmailsImportantesTestCase */ public void dummyWait() throws Exception { for (int second = 0;; second++) { if (second >= 5) { System.out.println("timeout"); return; } Thread.sleep(1000); } } @After public void tearDown() throws Exception { selenium.stop(); } }