Skip to content

Commit

Permalink
Column.contains and Column.containsValue now works with full table (w…
Browse files Browse the repository at this point in the history
…ith tfoot)
  • Loading branch information
luiz committed Mar 11, 2010
1 parent 2fa8e81 commit 418fcb3
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public String headerLinkValue(int col) {
}

public String value(int row, int col) {
if (row + 1 == getRowCount()) {
return helper.getXPathText("/tfoot/tr[1]/td[" + col + "]");
}
return helper.getXPathText("/tbody/tr[" + row + "]/td[" + col + "]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public String headerLinkValue(final int col) {
}

public String value(final int row, final int col) {
if (row + 1 == getRowCount()) {
return helper.getXPathText("/tfoot/tr[1]/td[" + col + "]");
}
return helper.getXPathText("/tbody/tr[" + row + "]/td[" + col + "]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class SeleniumTestCase {

@BeforeClass
public static void beforeStartup() {
String port = getProperty("cargo.servlet.port", "8080");
String port = getProperty("cargo.servlet.port", "9091");
String browser = getProperty("seleniumBrowserString", "*firefox");
String seleniumPort = getProperty("selenium.port", "4444");

Expand All @@ -31,8 +31,9 @@ public static void beforeStartup() {

private static String getProperty(String key, String standard) {
String value = System.getProperty(key);
if (value == null || value.equals(""))
if (value == null || value.equals("")) {
return standard;
}
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,22 @@ public void testUncheck() {
Assert.assertFalse(full.row(2).cell(3).uncheck().checked());
Assert.assertFalse(nested.row(2).cell(3).uncheck().checked());
}

@Test
public void testContainsPartialValueByColumnName() throws Exception {
Assert.assertTrue(plain.column("header_1").contains("cell_1_2"));
Assert.assertTrue(plainTh.column("header_1").contains("cell_1_2"));
Assert.assertTrue(full.column("header_1").contains("cell_1_2"));
Assert.assertTrue(nested.column("header_1").contains("cell_1_2"));

Assert.assertFalse(plain.column("header_2").contains("cell_1_2"));
Assert.assertFalse(plainTh.column("header_2").contains("cell_1_2"));
Assert.assertFalse(full.column("header_2").contains("cell_1_2"));
Assert.assertFalse(nested.column("header_2").contains("cell_1_2"));

Assert.assertTrue(plain.column("header_3").contains("footer_3"));
Assert.assertTrue(plainTh.column("header_3").contains("footer_3"));
Assert.assertTrue(full.column("header_3").contains("footer_3"));
Assert.assertTrue(nested.column("header_3").contains("footer_3"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package br.com.caelum.seleniumdsl.test.table.layout;

import junit.framework.Assert;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Before;
import org.junit.Test;

import br.com.caelum.seleniumdsl.table.layout.FullTableLayout;

import com.thoughtworks.selenium.Selenium;

public class FullTableLayoutTest {
private static final int ROW_COUNT = 5;

private Mockery mockery;
private Selenium mock;
private FullTableLayout tableLayout;

@Before
public void setUp() {
mockery = new Mockery();
mock = mockery.mock(Selenium.class);

mockery.checking(new Expectations() {
{
allowing(mock).getXpathCount("//table[@id='table']/*/tr");
will(returnValue(ROW_COUNT));
}
});

tableLayout = new FullTableLayout(mock, "table", "id");
}

@Test
public void testGetValueOfNormalRow() throws Exception {
mockery.checking(new Expectations() {
{
one(mock).getText("xpath=//table[@id='table']/tbody/tr[1]/td[1]");
will(returnValue("test"));
}
});
Assert.assertEquals("test", tableLayout.value(1, 1));
mockery.assertIsSatisfied();
}

@Test
public void testGetValueOfFooter() throws Exception {
mockery.checking(new Expectations() {
{
one(mock).getText("xpath=//table[@id='table']/tfoot/tr[1]/td[1]");
will(returnValue("test"));
}
});
Assert.assertEquals("test", tableLayout.value(ROW_COUNT - 1, 1));
mockery.assertIsSatisfied();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package br.com.caelum.seleniumdsl.test.table.layout;

import java.util.Arrays;
import java.util.List;

import junit.framework.Assert;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import br.com.caelum.seleniumdsl.webdriver.table.layout.WebDriverFullTableLayout;

public class WebDriverFullTableLayoutTest {
private Mockery mockery;
private WebDriver mock;
private WebDriverFullTableLayout tableLayout;
private WebElement header;
private WebElement row1;
private WebElement row2;
private WebElement footer;
private List<WebElement> rows;

@Before
public void setUp() {
mockery = new Mockery();
mock = mockery.mock(WebDriver.class);
header = mockery.mock(WebElement.class, "header");
row1 = mockery.mock(WebElement.class, "row1");
row2 = mockery.mock(WebElement.class, "row2");
footer = mockery.mock(WebElement.class, "footer");
rows = Arrays.asList(header, row1, row2, footer);

mockery.checking(new Expectations() {
{
allowing(mock).findElements(with(ByMatcher.byEqualTo(By.xpath("//table[@id='table']/*/tr"))));
will(returnValue(rows));
}
});

tableLayout = new WebDriverFullTableLayout(mock, "table", "id");
}

@Test
public void testGetValueOfNormalRow() throws Exception {
mockery.checking(new Expectations() {
{
one(mock).findElement(with(ByMatcher.byEqualTo(By.xpath("//table[@id='table']/tbody/tr[1]/td[1]"))));
will(returnValue(row1));

one(row1).getText();
will(returnValue("test"));
}
});
Assert.assertEquals("test", tableLayout.value(1, 1));
mockery.assertIsSatisfied();
}

@Test
public void testGetValueOfFooter() throws Exception {
mockery.checking(new Expectations() {
{
one(mock).findElement(with(ByMatcher.byEqualTo(By.xpath("//table[@id='table']/tfoot/tr[1]/td[1]"))));
will(returnValue(footer));

one(footer).getText();
will(returnValue("test"));
}
});
Assert.assertEquals("test", tableLayout.value(rows.size() - 1, 1));
mockery.assertIsSatisfied();
}
}

class ByMatcher extends TypeSafeMatcher<By> {

private final By expected;

public ByMatcher(By expected) {
this.expected = expected;
}

public void describeTo(Description desc) {
desc.appendText("By equal to " + expected.toString());
}

@Override
public boolean matchesSafely(By toMatch) {
return toMatch.toString().equals(expected.toString());
}

@Factory
public static Matcher<By> byEqualTo(By expected) {
return new ByMatcher(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,22 @@ public void testUncheck() {
Assert.assertFalse(full.row(2).cell(3).uncheck().checked());
Assert.assertFalse(nested.row(2).cell(3).uncheck().checked());
}

@Test
public void testContainsPartialValueByColumnName() throws Exception {
Assert.assertTrue(plain.column("header_1").contains("cell_1_2"));
Assert.assertTrue(plainTh.column("header_1").contains("cell_1_2"));
Assert.assertTrue(full.column("header_1").contains("cell_1_2"));
Assert.assertTrue(nested.column("header_1").contains("cell_1_2"));

Assert.assertFalse(plain.column("header_2").contains("cell_1_2"));
Assert.assertFalse(plainTh.column("header_2").contains("cell_1_2"));
Assert.assertFalse(full.column("header_2").contains("cell_1_2"));
Assert.assertFalse(nested.column("header_2").contains("cell_1_2"));

Assert.assertTrue(plain.column("header_3").contains("footer_3"));
Assert.assertTrue(plainTh.column("header_3").contains("footer_3"));
Assert.assertTrue(full.column("header_3").contains("footer_3"));
Assert.assertTrue(nested.column("header_3").contains("footer_3"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class WebDriverTestCase {

protected static WebDriver webDriver;
protected Browser browser;
protected static final String URL = "http://localhost:8080/";
protected static final String URL = "http://localhost:9091/";

@BeforeClass
public static void beforeStartup() {
Expand Down

0 comments on commit 418fcb3

Please sign in to comment.