Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.List; import java.util.concurrent.TimeUnit; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; import org.junit.runners.MethodSorters; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import resources.ScreenShotRule; /** * * @author favl */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class Filter2002Test { private static WebDriver driver; @BeforeClass public static void setUp() throws Exception { System.setProperty("webdriver.gecko.driver", "/Users/favl/Downloads/geckodriver"); driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("http://localhost:3000"); } @AfterClass public static void tearDown() throws Exception { driver.quit(); } /** * Takes a screenshot when a test fails. */ @Rule public ScreenShotRule screenShotRule = new ScreenShotRule(driver); @Test public void test_1() { WebElement filter = driver.findElement(By.id("filter")); filter.sendKeys("2002"); List<WebElement> tableRows = driver.findElements(By.tagName("tr")); // asserting that if content is filtered the amount of table rows must // be three including the table header's row. assertThat(tableRows.size(), is(3)); } @Test public void test_2() { WebElement filter = driver.findElement(By.id("filter")); filter.sendKeys(Keys.BACK_SPACE); WebElement table = driver.findElement(By.id("tbodycars")); List<WebElement> tableRows = table.findElements(By.tagName("tr")); // There should be five rows of data. assertThat(tableRows.size(), is(5)); } }