/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. package org.sigmah.endtoend.page;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.support.ui.SystemClock;
  9. import org.sigmah.endtoend.xpath.Predicate;
  10. import org.sigmah.endtoend.xpath.Step;
  11. import org.sigmah.endtoend.xpath.XPath;
  12. import static org.sigmah.endtoend.xpath.XPath.*;
  13. import static org.sigmah.endtoend.xpath.ext.HtmlXPath.ofClass;
  14. public class GxtComponent {
  15. protected final WebElement element;
  16. private String text;
  17. public GxtComponent(WebElement element) {
  18. this.element = element;
  19. }
  20. public GxtComponent find(Step... steps) {
  21. String xpath = XPath.relative(steps);
  22. System.err.println("query = " + xpath);
  23. return new GxtComponent(findElementByXpath(xpath));
  24. }
  25. public GxtComponent find(Predicate... predicate) {
  26. return find(descendant(predicate));
  27. }
  28. public GxtComponent findAbsolute(Step... steps) {
  29. return new GxtComponent(findElementByXpath(absolute(steps)));
  30. }
  31. public void assertTextIsPresent(String text) {
  32. find(descendant(containingText(text)));
  33. }
  34. public WebElement findElementByXpath(String xpath, Object... args) {
  35. return findElement(By.xpath(String.format(xpath, args)));
  36. }
  37. public WebElement findElement(By by) {
  38. return new SlowLoadableElement(new SystemClock(), 10, element, by).get().getElement();
  39. }
  40. public void clickOn(String text) {
  41. GxtComponent child = find(descendant(havingTextEqualTo(text)));
  42. System.err.println("element.getText() = " + child.getText());
  43. child.click();
  44. }
  45. public void click() {
  46. element.click();
  47. }
  48. public WebElement onInputWithLabel(String label) {
  49. return find(
  50. descendant(havingTextEqualTo(label)),
  51. following(element("input"))
  52. ).getElement();
  53. }
  54. public WebElement getElement() {
  55. return element;
  56. }
  57. public String getText() {
  58. return text;
  59. }
  60. public GxtGrid asGrid() {
  61. return new GxtGrid(element);
  62. }
  63. public GxtComboBox asComboBox() {
  64. return new GxtComboBox(element);
  65. }
  66. public GxtComponent sendKeys(CharSequence keysToSend) {
  67. element.sendKeys(keysToSend);
  68. return this;
  69. }
  70. public GxtComponent activeWindow() {
  71. return findAbsolute(descendant(ofClass("x-window")));
  72. }
  73. }