1 package br.com.caelum.seleniumdsl.table.layout;
2
3 import java.util.logging.Logger;
4
5 import br.com.caelum.seleniumdsl.table.Table;
6
7 import com.thoughtworks.selenium.Selenium;
8 import com.thoughtworks.selenium.SeleniumException;
9
10 class TableLayoutHelper {
11 private static final Logger log = Logger.getLogger(TableLayoutHelper.class.getName());
12
13 private Selenium selenium;
14 private String id;
15 private String type;
16
17 TableLayoutHelper(Selenium selenium, String id, String type) {
18 this.selenium = selenium;
19 this.id = id;
20 this.type = type;
21 }
22
23 int getRowCount() {
24 return countXPath("/*/tr");
25 }
26
27 int countXPath(String expr) {
28 return selenium.getXpathCount("//table[@" + type + "='" + id + "']/" + expr)
29 .intValue();
30 }
31
32 String getXPathText(String expr) {
33 try {
34 return selenium.getText("xpath=//table[@" + type + "='" + id + "']/" + expr);
35 } catch (SeleniumException e) {
36 log.info(e.getMessage());
37 }
38
39 return null;
40 }
41
42 boolean contains(Table table, String col, String content) {
43 for (int i = 1; i < table.getRowCount(); i++)
44 if (table.cell(i, col)
45 .contains(content))
46 return true;
47 return false;
48 }
49 }