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.

GridEditorFrozenColumnsUITest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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;
  17. import java.io.IOException;
  18. import org.junit.Test;
  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.elements.GridElement;
  25. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  26. import com.vaadin.testbench.parallel.TestCategory;
  27. import com.vaadin.tests.tb3.MultiBrowserTest;
  28. @TestCategory("grid")
  29. public class GridEditorFrozenColumnsUITest extends MultiBrowserTest {
  30. @Test
  31. public void testEditorWithFrozenColumns() throws IOException {
  32. openTestURL();
  33. openEditor(10);
  34. compareScreen("noscroll");
  35. scrollGridHorizontallyTo(100);
  36. compareScreen("scrolled");
  37. }
  38. private void openEditor(int rowIndex) {
  39. GridElement grid = $(GridElement.class).first();
  40. GridCellElement cell = grid.getCell(rowIndex, 1);
  41. new Actions(driver).moveToElement(cell).doubleClick().build().perform();
  42. }
  43. private void scrollGridHorizontallyTo(double px) {
  44. executeScript("arguments[0].scrollLeft = " + px,
  45. getGridHorizontalScrollbar());
  46. }
  47. private Object executeScript(String script, WebElement element) {
  48. final WebDriver driver = getDriver();
  49. if (driver instanceof JavascriptExecutor) {
  50. final JavascriptExecutor je = (JavascriptExecutor) driver;
  51. return je.executeScript(script, element);
  52. } else {
  53. throw new IllegalStateException("current driver "
  54. + getDriver().getClass().getName() + " is not a "
  55. + JavascriptExecutor.class.getSimpleName());
  56. }
  57. }
  58. private WebElement getGridHorizontalScrollbar() {
  59. return getDriver()
  60. .findElement(
  61. By.xpath("//div[contains(@class, \"v-grid-scroller-horizontal\")]"));
  62. }
  63. }