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.

TogglePushTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.push;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.WebElement;
  20. import com.vaadin.testbench.parallel.TestCategory;
  21. import com.vaadin.tests.tb3.MultiBrowserTest;
  22. @TestCategory("push")
  23. public class TogglePushTest extends MultiBrowserTest {
  24. @Test
  25. public void togglePushInInit() throws Exception {
  26. setPush(true);
  27. String url = getTestUrl();
  28. // Open with push disabled
  29. driver.get(addParameter(url, "push=disabled"));
  30. Assert.assertFalse(getPushToggle().isSelected());
  31. getDelayedCounterUpdateButton().click();
  32. sleep(2000);
  33. Assert.assertEquals("Counter has been updated 0 times",
  34. getCounterText());
  35. // Open with push enabled
  36. driver.get(addParameter(url, "push=enabled"));
  37. Assert.assertTrue(getPushToggle().isSelected());
  38. getDelayedCounterUpdateButton().click();
  39. sleep(2000);
  40. Assert.assertEquals("Counter has been updated 1 times",
  41. getCounterText());
  42. }
  43. private String addParameter(String url, String queryParameter) {
  44. if (url.contains("?")) {
  45. return url + "&" + queryParameter;
  46. } else {
  47. return url + "?" + queryParameter;
  48. }
  49. }
  50. @Test
  51. public void togglePush() throws InterruptedException {
  52. setPush(true);
  53. openTestURL();
  54. getDelayedCounterUpdateButton().click();
  55. sleep(2000);
  56. // Push is enabled, so text gets updated
  57. Assert.assertEquals("Counter has been updated 1 times",
  58. getCounterText());
  59. // Disable push
  60. getPushToggle().click();
  61. getDelayedCounterUpdateButton().click();
  62. sleep(2000);
  63. // Push is disabled, so text is not updated
  64. Assert.assertEquals("Counter has been updated 1 times",
  65. getCounterText());
  66. getDirectCounterUpdateButton().click();
  67. // Direct update is visible, and includes previous update
  68. Assert.assertEquals("Counter has been updated 3 times",
  69. getCounterText());
  70. // Re-enable push
  71. getPushToggle().click();
  72. getDelayedCounterUpdateButton().click();
  73. sleep(2000);
  74. // Push is enabled again, so text gets updated
  75. Assert.assertEquals("Counter has been updated 4 times",
  76. getCounterText());
  77. }
  78. private WebElement getDirectCounterUpdateButton() {
  79. return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]");
  80. }
  81. private WebElement getPushToggle() {
  82. return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]");
  83. }
  84. private WebElement getDelayedCounterUpdateButton() {
  85. return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]");
  86. }
  87. private String getCounterText() {
  88. return vaadinElement(
  89. "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]")
  90. .getText();
  91. }
  92. }