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.

GridBasicFeaturesTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.grid.basicfeatures;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import org.openqa.selenium.By;
  20. import org.openqa.selenium.JavascriptExecutor;
  21. import org.openqa.selenium.WebDriver;
  22. import org.openqa.selenium.WebElement;
  23. import org.openqa.selenium.interactions.Actions;
  24. import com.vaadin.testbench.TestBenchElement;
  25. import com.vaadin.testbench.elements.GridElement;
  26. import com.vaadin.testbench.parallel.TestCategory;
  27. import com.vaadin.tests.tb3.MultiBrowserTest;
  28. @TestCategory("grid")
  29. public abstract class GridBasicFeaturesTest extends MultiBrowserTest {
  30. @Override
  31. protected boolean requireWindowFocusForIE() {
  32. return true;
  33. }
  34. @Override
  35. protected Class<?> getUIClass() {
  36. return GridBasicFeatures.class;
  37. }
  38. protected void selectSubMenu(String menuCaption) {
  39. selectMenu(menuCaption);
  40. new Actions(getDriver()).moveByOffset(100, 0).build().perform();
  41. }
  42. protected void selectMenu(String menuCaption) {
  43. getDriver().findElement(
  44. By.xpath("//span[text() = '" + menuCaption + "']")).click();
  45. }
  46. protected void selectMenuPath(String... menuCaptions) {
  47. selectMenu(menuCaptions[0]);
  48. for (int i = 1; i < menuCaptions.length; i++) {
  49. selectSubMenu(menuCaptions[i]);
  50. }
  51. }
  52. protected GridElement getGridElement() {
  53. return ((TestBenchElement) findElement(By.id("testComponent")))
  54. .wrap(GridElement.class);
  55. }
  56. protected void scrollGridVerticallyTo(double px) {
  57. executeScript("arguments[0].scrollTop = " + px,
  58. getGridVerticalScrollbar());
  59. }
  60. protected int getGridVerticalScrollPos() {
  61. return ((Number) executeScript("return arguments[0].scrollTop",
  62. getGridVerticalScrollbar())).intValue();
  63. }
  64. protected List<TestBenchElement> getGridHeaderRowCells() {
  65. List<TestBenchElement> headerCells = new ArrayList<TestBenchElement>();
  66. for (int i = 0; i < getGridElement().getHeaderCount(); ++i) {
  67. headerCells.addAll(getGridElement().getHeaderCells(i));
  68. }
  69. return headerCells;
  70. }
  71. protected List<TestBenchElement> getGridFooterRowCells() {
  72. List<TestBenchElement> footerCells = new ArrayList<TestBenchElement>();
  73. for (int i = 0; i < getGridElement().getFooterCount(); ++i) {
  74. footerCells.addAll(getGridElement().getFooterCells(i));
  75. }
  76. return footerCells;
  77. }
  78. protected WebElement getEditor() {
  79. List<WebElement> elems = getGridElement().findElements(
  80. By.className("v-grid-editor"));
  81. assertLessThanOrEqual("number of editors", elems.size(), 1);
  82. return elems.isEmpty() ? null : elems.get(0);
  83. }
  84. private Object executeScript(String script, WebElement element) {
  85. final WebDriver driver = getDriver();
  86. if (driver instanceof JavascriptExecutor) {
  87. final JavascriptExecutor je = (JavascriptExecutor) driver;
  88. return je.executeScript(script, element);
  89. } else {
  90. throw new IllegalStateException("current driver "
  91. + getDriver().getClass().getName() + " is not a "
  92. + JavascriptExecutor.class.getSimpleName());
  93. }
  94. }
  95. protected WebElement getGridVerticalScrollbar() {
  96. return getDriver()
  97. .findElement(
  98. By.xpath("//div[contains(@class, \"v-grid-scroller-vertical\")]"));
  99. }
  100. /**
  101. * Reloads the page without restartApplication. This occasionally breaks
  102. * stuff.
  103. */
  104. protected void reopenTestURL() {
  105. String testUrl = getTestUrl();
  106. testUrl = testUrl.replace("?restartApplication", "?");
  107. testUrl = testUrl.replace("?&", "?");
  108. driver.get(testUrl);
  109. }
  110. }