View Javadoc

1   package br.com.caelum.seleniumdsl.table.layout;
2   
3   import com.thoughtworks.selenium.Selenium;
4   
5   public class TableLayoutChooser {
6   
7   	private Selenium selenium;
8   	private String id;
9   	private String type;
10  
11  	private static final String testThead = "id('%s')/thead";
12  	private static final String testTh = "id('%s')//th";
13  
14  	public TableLayoutChooser(Selenium selenium, String id, String type) {
15  		super();
16  		this.selenium = selenium;
17  		this.id = id;
18  		this.type = type;
19  	}
20  
21  	public TableLayout choose() {
22  		int theadCount = selenium.getXpathCount(String.format(testThead, id))
23  				.intValue();
24  		int thCount = selenium.getXpathCount(String.format(testTh, id))
25  				.intValue();
26  
27  		TableLayout layout = null;
28  		if (theadCount <= 0 && thCount <= 0)
29  			layout = new PlainTableLayout(selenium, id, type);
30  		else if (theadCount <= 0 && thCount > 0)
31  			layout = new PlainPlusThTableLayout(selenium, id, type);
32  		else
33  			layout = new FullTableLayout(selenium, id, type);
34  
35  		return layout;
36  	}
37  }