Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BasicPushTest.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.Test;
  18. import org.openqa.selenium.WebDriver;
  19. import org.openqa.selenium.WebElement;
  20. import org.openqa.selenium.support.ui.ExpectedCondition;
  21. import com.vaadin.testbench.parallel.TestCategory;
  22. import com.vaadin.tests.tb3.AbstractTB3Test;
  23. import com.vaadin.tests.tb3.MultiBrowserTest;
  24. @TestCategory("push")
  25. public abstract class BasicPushTest extends MultiBrowserTest {
  26. @Override
  27. public void setup() throws Exception {
  28. super.setup();
  29. }
  30. @Test
  31. public void testPush() throws InterruptedException {
  32. openTestURL();
  33. getIncrementButton().click();
  34. testBench().disableWaitForVaadin();
  35. waitUntilClientCounterChanges(1);
  36. getIncrementButton().click();
  37. getIncrementButton().click();
  38. getIncrementButton().click();
  39. waitUntilClientCounterChanges(4);
  40. // Test server initiated push
  41. getServerCounterStartButton().click();
  42. waitUntilServerCounterChanges();
  43. }
  44. public static int getClientCounter(AbstractTB3Test t) {
  45. WebElement clientCounterElem = t
  46. .vaadinElementById(BasicPush.CLIENT_COUNTER_ID);
  47. return Integer.parseInt(clientCounterElem.getText());
  48. }
  49. private WebElement getIncrementButton() {
  50. return getIncrementButton(this);
  51. }
  52. private WebElement getServerCounterStartButton() {
  53. return getServerCounterStartButton(this);
  54. }
  55. public static int getServerCounter(AbstractTB3Test t) {
  56. WebElement serverCounterElem = t
  57. .vaadinElementById(BasicPush.SERVER_COUNTER_ID);
  58. return Integer.parseInt(serverCounterElem.getText());
  59. }
  60. public static WebElement getServerCounterStartButton(AbstractTB3Test t) {
  61. return t.vaadinElementById(BasicPush.START_TIMER_ID);
  62. }
  63. public static WebElement getServerCounterStopButton(AbstractTB3Test t) {
  64. return t.vaadinElementById(BasicPush.STOP_TIMER_ID);
  65. }
  66. public static WebElement getIncrementButton(AbstractTB3Test t) {
  67. return t.vaadinElementById(BasicPush.INCREMENT_BUTTON_ID);
  68. }
  69. private void waitUntilClientCounterChanges(final int expectedValue) {
  70. waitUntil(new ExpectedCondition<Boolean>() {
  71. @Override
  72. public Boolean apply(WebDriver input) {
  73. return BasicPushTest.getClientCounter(BasicPushTest.this) == expectedValue;
  74. }
  75. }, 10);
  76. }
  77. private void waitUntilServerCounterChanges() {
  78. final int counter = BasicPushTest.getServerCounter(this);
  79. waitUntil(new ExpectedCondition<Boolean>() {
  80. @Override
  81. public Boolean apply(WebDriver input) {
  82. return BasicPushTest.getServerCounter(BasicPushTest.this) > counter;
  83. }
  84. }, 10);
  85. }
  86. }