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.

SplitPositionChangeTest.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.splitpanel;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.By;
  20. import org.openqa.selenium.WebElement;
  21. import org.openqa.selenium.interactions.Actions;
  22. import com.vaadin.testbench.elements.HorizontalSplitPanelElement;
  23. import com.vaadin.testbench.elements.VerticalSplitPanelElement;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. /**
  26. * Test for {@link SplitPositionChangeListeners}.
  27. *
  28. * @author Vaadin Ltd
  29. */
  30. public class SplitPositionChangeTest extends MultiBrowserTest {
  31. @Override
  32. public void setup() throws Exception {
  33. super.setup();
  34. openTestURL();
  35. waitForElementPresent(By.className("v-splitpanel-horizontal"));
  36. }
  37. @Test
  38. public void testHorizontalSplit() {
  39. HorizontalSplitPanelElement split = $(HorizontalSplitPanelElement.class)
  40. .first();
  41. WebElement splitter = split.findElement(By
  42. .className("v-splitpanel-hsplitter"));
  43. int position = splitter.getLocation().getX();
  44. Actions actions = new Actions(driver);
  45. actions.clickAndHold(splitter).moveByOffset(50, 0).release().perform();
  46. assertPosition(position, splitter.getLocation().getX());
  47. assertLogText(true);
  48. }
  49. @Test
  50. public void testVerticalSplit() {
  51. VerticalSplitPanelElement split = $(VerticalSplitPanelElement.class)
  52. .first();
  53. WebElement splitter = split.findElement(By
  54. .className("v-splitpanel-vsplitter"));
  55. int position = splitter.getLocation().getY();
  56. Actions actions = new Actions(driver);
  57. actions.clickAndHold(splitter).moveByOffset(0, 50).release().perform();
  58. assertPosition(position, splitter.getLocation().getY());
  59. assertLogText(false);
  60. }
  61. private void assertPosition(int original, int current) {
  62. Assert.assertFalse("Position didn't change", original == current);
  63. }
  64. private void assertLogText(boolean horizontal) {
  65. String expected = String.format(
  66. "1. Split position changed: %s, position: .*",
  67. horizontal ? "horizontal" : "vertical");
  68. String actual = getLogRow(0);
  69. Assert.assertTrue(
  70. String.format(
  71. "Log content didn't match the expected format.\nexpected: '%s'\nwas: '%s'",
  72. expected, actual), actual.matches(expected));
  73. }
  74. }