package teste;

import static helper.SeleniumTestHelper.esperaPorCondicao;
import helper.Condicao;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.SeleneseTestCase;

public class TesteCapturaNumerosNumaRegex extends SeleneseTestCase {
	@Before
	public void setUp() throws Exception {
		setUp("http://www.rubular.com/", "*firefox");
	}

	@Override
	protected boolean isCaptureScreenShotOnFailure() {
		return true;
	}

	@After
	@Override
	public void tearDown() throws Exception {
		super.tearDown();
	}

	@Test
	public void testeBateRegexDeNumeros() throws Exception {
		selenium.open("/");
		selenium.type("test", "1 frase 10 com 3numeros");
		selenium.type("regex", "\\d");

		esperaPorCondicao(5000, new Condicao() {
			@Override
			public boolean verdade() {
				return !selenium.isElementPresent("start_instructions");
			}
		});

		assertEquals("1", selenium.getText("//div[@id='match_string']/span[1]"));
	}
}
