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.

ResponsiveUITest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2000-2016 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.extensions;
  17. import static org.junit.Assert.assertEquals;
  18. import org.junit.Before;
  19. import org.junit.Test;
  20. import org.openqa.selenium.WebElement;
  21. import org.openqa.selenium.interactions.Actions;
  22. import org.openqa.selenium.support.ui.ExpectedConditions;
  23. import org.openqa.selenium.support.ui.WebDriverWait;
  24. import com.vaadin.testbench.By;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. public class ResponsiveUITest extends MultiBrowserTest {
  27. @Before
  28. public void setUp() throws Exception {
  29. // We need this in order to ensure that the initial width-range is
  30. // 401px-600px
  31. testBench().resizeViewPortTo(1024, 768);
  32. }
  33. // JQuery style selector
  34. private WebElement $(String cssSelector) {
  35. return getDriver().findElement(By.cssSelector(cssSelector));
  36. }
  37. @Test
  38. public void testResizingSplitPanelReflowsLayout() throws Exception {
  39. openTestURL();
  40. // IE sometimes has trouble waiting long enough.
  41. waitUntil(ExpectedConditions.presenceOfElementLocated(
  42. By.cssSelector(".v-csslayout-grid.first")), 30);
  43. assertEquals("401px-600px",
  44. $(".v-csslayout-grid.first").getAttribute("width-range"));
  45. assertEquals("501px-",
  46. $(".v-csslayout-grid.second").getAttribute("width-range"));
  47. moveSplitter(200);
  48. assertEquals("601-800",
  49. $(".v-csslayout-grid.first").getAttribute("width-range"));
  50. assertEquals("501px-",
  51. $(".v-csslayout-grid.second").getAttribute("width-range"));
  52. moveSplitter(-350);
  53. assertEquals("201px-400px",
  54. $(".v-csslayout-grid.first").getAttribute("width-range"));
  55. assertEquals("301px-400px",
  56. $(".v-csslayout-grid.second").getAttribute("width-range"));
  57. compareScreen("responsive");
  58. moveSplitter(-200);
  59. assertEquals("-200px",
  60. $(".v-csslayout-grid.first").getAttribute("width-range"));
  61. moveSplitter(-100);
  62. assertEquals("0-100px",
  63. $(".v-csslayout-grid.second").getAttribute("width-range"));
  64. }
  65. private void moveSplitter(int xOffset) {
  66. new Actions(getDriver()).clickAndHold($(".v-splitpanel-hsplitter"))
  67. .moveByOffset(xOffset, 0).release().build().perform();
  68. }
  69. @Test
  70. public void testResizingWindowReflowsLayout() throws Exception {
  71. openTestURL();
  72. assertEquals("401px-600px",
  73. $(".v-csslayout-grid.first").getAttribute("width-range"));
  74. assertEquals("501px-",
  75. $(".v-csslayout-grid.second").getAttribute("width-range"));
  76. testBench().resizeViewPortTo(1224, 768);
  77. assertEquals("601-800",
  78. $(".v-csslayout-grid.first").getAttribute("width-range"));
  79. assertEquals("501px-",
  80. $(".v-csslayout-grid.second").getAttribute("width-range"));
  81. testBench().resizeViewPortTo(674, 768);
  82. assertEquals("201px-400px",
  83. $(".v-csslayout-grid.first").getAttribute("width-range"));
  84. assertEquals("301px-400px",
  85. $(".v-csslayout-grid.second").getAttribute("width-range"));
  86. }
  87. }