PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/src/test/java/org/sigmah/endtoend/page/GxtComponent.java

http://sigma-h.googlecode.com/
Java | 96 lines | 69 code | 23 blank | 4 comment | 0 complexity | 2bcda32404ecd178ebb6cdef9e87e0c9 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.endtoend.page;
 7
 8import org.openqa.selenium.By;
 9import org.openqa.selenium.WebElement;
10import org.openqa.selenium.support.ui.SystemClock;
11import org.sigmah.endtoend.xpath.Predicate;
12import org.sigmah.endtoend.xpath.Step;
13import org.sigmah.endtoend.xpath.XPath;
14
15import static org.sigmah.endtoend.xpath.XPath.*;
16import static org.sigmah.endtoend.xpath.ext.HtmlXPath.ofClass;
17
18public class GxtComponent {
19
20    protected final WebElement element;
21    private String text;
22
23    public GxtComponent(WebElement element) {
24        this.element = element;
25    }
26
27    public GxtComponent find(Step... steps) {
28        String xpath = XPath.relative(steps);
29        System.err.println("query = " + xpath);
30        return new GxtComponent(findElementByXpath(xpath));
31    }
32
33    public GxtComponent find(Predicate... predicate) {
34        return find(descendant(predicate));
35    }
36
37    public GxtComponent findAbsolute(Step... steps) {
38        return new GxtComponent(findElementByXpath(absolute(steps)));
39    }
40
41    public void assertTextIsPresent(String text) {
42        find(descendant(containingText(text)));
43    }
44
45    public WebElement findElementByXpath(String xpath, Object... args) {
46        return findElement(By.xpath(String.format(xpath, args)));
47    }
48
49    public WebElement findElement(By by) {
50        return new SlowLoadableElement(new SystemClock(), 10, element, by).get().getElement();
51    }
52
53    public void clickOn(String text) {
54        GxtComponent child = find(descendant(havingTextEqualTo(text)));
55        System.err.println("element.getText() = " + child.getText());
56
57        child.click();
58    }
59
60    public void click() {
61        element.click();
62    }
63
64    public WebElement onInputWithLabel(String label) {
65        return find(
66                descendant(havingTextEqualTo(label)),
67                following(element("input"))
68        ).getElement();
69    }
70
71    public WebElement getElement() {
72        return element;
73    }
74
75    public String getText() {
76        return text;
77    }
78
79    public GxtGrid asGrid() {
80        return new GxtGrid(element);
81    }
82
83    public GxtComboBox asComboBox() {
84        return new GxtComboBox(element);
85    }
86
87   public GxtComponent sendKeys(CharSequence keysToSend) {
88       element.sendKeys(keysToSend);
89       return this;
90   }
91
92    public GxtComponent activeWindow() {
93        return findAbsolute(descendant(ofClass("x-window")));
94    }
95
96}