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

http://sigma-h.googlecode.com/ · Java · 50 lines · 36 code · 10 blank · 4 comment · 2 complexity · 4dc8d07497f8b3f9d92677c917e362dc 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.sigmah.endtoend.xpath.XPath;
  9. import java.util.List;
  10. import static org.sigmah.endtoend.xpath.XPath.*;
  11. import static org.sigmah.endtoend.xpath.ext.GxtXPath.gridCell;
  12. import static org.sigmah.endtoend.xpath.ext.GxtXPath.gridRow;
  13. import static org.sigmah.endtoend.xpath.ext.HtmlXPath.ofClass;
  14. import static org.sigmah.endtoend.xpath.ext.HtmlXPath.ofClasses;
  15. public class GxtGrid extends GxtComponent {
  16. public GxtGrid(WebElement element) {
  17. super(element);
  18. }
  19. public WebElement cell(int row, int col) {
  20. return find(
  21. gridRow(row),
  22. gridCell(col)
  23. ).getElement();
  24. }
  25. public int columnIndexFromLabel(String label) {
  26. List<WebElement> headers = element.findElements(By.xpath(relative(
  27. descendant(XPath.element("td"), ofClasses("x-grid3-header", "x-grid3-cell"))
  28. )));
  29. for(int i=0;i!=headers.size(); ++i) {
  30. String text = headers.get(i).getText().trim();
  31. if(text.equalsIgnoreCase(label)) {
  32. return i+1;
  33. }
  34. }
  35. throw new AssertionError("Column labeled " + label + " does not exist.");
  36. }
  37. public GxtComponent editor() {
  38. return find(descendant(ofClass("x-grid-editor"), not(ofClass("x-hide-display"))));
  39. }
  40. }