View Javadoc

1   package br.com.caelum.seleniumdsl.table;
2   
3   import com.thoughtworks.selenium.Selenium;
4   import com.thoughtworks.selenium.SeleniumException;
5   
6   public class DefaultCell implements Cell {
7   
8   	private final Table table;
9   	private final int row;
10  	private final int col;
11  	private final Selenium selenium;
12  
13  	public DefaultCell(Selenium selenium, Table table, int row, int col) {
14  		this.selenium = selenium;
15  		this.table = table;
16  		this.row = row;
17  		this.col = col;
18  	}
19  
20  	public String value() {
21  		return table.getLayout().value(row, col);
22  	}
23  
24  	public String getLink() {
25  		return selenium.getEval("dom=selenium.page().findElement(\"" + getXPath() + "/a\").href");
26  	}
27  
28  	public String headerValue() {
29  		try {
30  			return table.getLayout().headerValue(col);
31  		} catch (SeleniumException e) {
32  			return headerLinkValue();
33  		}
34  	}
35  
36  	public String headerLinkValue() {
37  		return table.getLayout().headerLinkValue(col);
38  	}
39  
40  	private String getXPath() {
41  		return "//table[@" + table.getType() + "='" + table.getId() + "']/*/tr[" + row + "]/td[" + col + "]";
42  	}
43  
44  	public Cell check() {
45  		selenium.check(getXPath() + "/input");
46  		return this;
47  	}
48  
49  	public Cell uncheck() {
50  		selenium.uncheck(getXPath() + "/input");
51  		return this;
52  	}
53  
54  	public boolean checked() {
55  		return selenium.isChecked(getXPath() + "/input");
56  	}
57  
58  	public boolean contains(String content) {
59  		return content.equals(value());
60  	}
61  
62  }