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.

TableColumnResizeContentsWidthTest.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.table;
  17. import static org.junit.Assert.assertEquals;
  18. import java.util.List;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebDriver;
  22. import org.openqa.selenium.WebElement;
  23. import org.openqa.selenium.interactions.Actions;
  24. import org.openqa.selenium.remote.DesiredCapabilities;
  25. import org.openqa.selenium.support.ui.ExpectedCondition;
  26. import com.vaadin.testbench.elements.ButtonElement;
  27. import com.vaadin.testbench.elements.TableElement;
  28. import com.vaadin.tests.tb3.MultiBrowserTest;
  29. /**
  30. * Tests that components within table cells get resized when their column gets
  31. * resized.
  32. *
  33. * @author Vaadin Ltd
  34. */
  35. public class TableColumnResizeContentsWidthTest extends MultiBrowserTest {
  36. @Override
  37. public List<DesiredCapabilities> getBrowsersToTest() {
  38. return getBrowsersExcludingIE8();
  39. }
  40. @Test
  41. public void testResizing() throws InterruptedException {
  42. openTestURL();
  43. List<ButtonElement> buttons = $(ButtonElement.class).all();
  44. WebElement resizer = getTable().findElement(
  45. By.className("v-table-resizer"));
  46. assertEquals(100, getTextFieldWidth());
  47. moveResizer(resizer, -20);
  48. assertEquals(80, getTextFieldWidth());
  49. moveResizer(resizer, 40);
  50. assertEquals(120, getTextFieldWidth());
  51. // click the button for decreasing size
  52. buttons.get(1).click();
  53. waitUntilTextFieldWidthIs(80);
  54. // click the button for increasing size
  55. buttons.get(0).click();
  56. waitUntilTextFieldWidthIs(100);
  57. }
  58. private void waitUntilTextFieldWidthIs(final int width) {
  59. waitUntil(new ExpectedCondition<Object>() {
  60. @Override
  61. public Object apply(WebDriver input) {
  62. return getTextFieldWidth() == width;
  63. }
  64. });
  65. }
  66. private int getTextFieldWidth() {
  67. TableElement table = getTable();
  68. final WebElement textField = table.findElement(By
  69. .className("v-textfield"));
  70. return textField.getSize().width;
  71. }
  72. private TableElement getTable() {
  73. return $(TableElement.class).first();
  74. }
  75. private void moveResizer(WebElement resizer, int offset) {
  76. new Actions(driver).clickAndHold(resizer).moveByOffset(offset, 0)
  77. .release().perform();
  78. }
  79. }