You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridThemeUITest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.vaadin.v7.tests.components.grid;
  2. import org.junit.Test;
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.Keys;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8. import org.openqa.selenium.support.ui.ExpectedCondition;
  9. import com.vaadin.testbench.elements.ButtonElement;
  10. import com.vaadin.testbench.elements.DateFieldElement;
  11. import com.vaadin.testbench.elements.GridElement;
  12. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  13. import com.vaadin.testbench.elements.GridElement.GridEditorElement;
  14. import com.vaadin.testbench.elements.NativeSelectElement;
  15. import com.vaadin.testbench.elements.TextFieldElement;
  16. import com.vaadin.testbench.parallel.TestCategory;
  17. import com.vaadin.tests.tb3.MultiBrowserThemeTest;
  18. @TestCategory("grid")
  19. public class GridThemeUITest extends MultiBrowserThemeTest {
  20. private GridElement grid;
  21. @Test
  22. public void grid() throws Exception {
  23. openTestURL();
  24. selectPage("Editor");
  25. compareScreen("basic");
  26. }
  27. @Test
  28. public void headerAndFooter() throws Exception {
  29. openTestURL();
  30. selectPage("HeaderFooter");
  31. compareScreen("basic");
  32. grid.getHeaderCell(0, 6).$(ButtonElement.class).first().click();
  33. compareScreen("additional-header");
  34. grid.getHeaderCell(2, 1).click();
  35. compareScreen("sorted-last-name");
  36. grid.getHeaderCell(2, 4).click();
  37. compareScreen("sorted-age");
  38. }
  39. @Test
  40. public void editor() throws Exception {
  41. openTestURL();
  42. selectPage("Editor");
  43. GridCellElement ritaBirthdate = grid.getCell(2, 3);
  44. // Open editor row
  45. openEditor(ritaBirthdate);
  46. compareScreen("initial");
  47. GridEditorElement editor = grid.getEditor();
  48. DateFieldElement dateField = editor.$(DateFieldElement.class).first();
  49. WebElement input = dateField.findElement(By.xpath("input"));
  50. input.sendKeys("Invalid", Keys.TAB);
  51. editor.save();
  52. compareScreen("one-invalid");
  53. TextFieldElement age = editor.$(TextFieldElement.class).caption("Age")
  54. .first();
  55. age.sendKeys("abc", Keys.TAB);
  56. editor.save();
  57. compareScreen("two-invalid");
  58. }
  59. private void openEditor(GridCellElement targetCell) {
  60. new Actions(getDriver()).doubleClick(targetCell).perform();
  61. try {
  62. waitForElementPresent(By.className("v-grid-editor"));
  63. } catch (Exception e) {
  64. // Double-click is flaky, try again...
  65. new Actions(getDriver()).doubleClick(targetCell).perform();
  66. waitForElementPresent(By.className("v-grid-editor"));
  67. }
  68. WebElement editor = findElement(By.className("v-grid-editor"));
  69. waitUntil(new ExpectedCondition<Boolean>() {
  70. @Override
  71. public Boolean apply(WebDriver arg0) {
  72. int current = editor.getSize().getHeight();
  73. // it's actually expected to be the height of two rows plus one
  74. // pixel, but giving it 2 pixels of leeway
  75. int expected = targetCell.getSize().getHeight() * 2 - 1;
  76. return current >= expected;
  77. }
  78. @Override
  79. public String toString() {
  80. // Expected condition failed: waiting for ...
  81. return "editor to become visible, current height: "
  82. + editor.getSize().getHeight() + ", row height: "
  83. + targetCell.getSize().getHeight();
  84. }
  85. });
  86. }
  87. private void selectPage(String string) {
  88. $(NativeSelectElement.class).id("page").selectByText(string);
  89. grid = $(GridElement.class).first();
  90. waitUntilLoadingIndicatorNotVisible();
  91. }
  92. }