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.

DetachOldUIOnReloadTest.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.vaadin.tests.application;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import java.util.List;
  5. import org.junit.Test;
  6. import com.vaadin.testbench.elements.ButtonElement;
  7. import com.vaadin.testbench.elements.LabelElement;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. public class DetachOldUIOnReloadTest extends MultiBrowserTest {
  10. private static final String RELOAD = "Reload page";
  11. private static final String READ_LOG = "Read log messages from session";
  12. @Test
  13. public void testDetachesUIOnReload() throws InterruptedException {
  14. openTestURL();
  15. List<LabelElement> labels = $(LabelElement.class).all();
  16. assertEquals("initial label incorrect", "This is UI 0",
  17. lastLabelText(labels));
  18. assertFalse("reloading button not found",
  19. $(ButtonElement.class).caption(RELOAD).all().isEmpty());
  20. openTestURL();
  21. click(READ_LOG);
  22. checkLabels("first", 1);
  23. click(RELOAD);
  24. click(READ_LOG);
  25. checkLabels("second", 2);
  26. openTestURL();
  27. click(READ_LOG);
  28. checkLabels("third", 3);
  29. // restarting reverts to 0
  30. openTestURL("restartApplication");
  31. checkLabels("final", 0);
  32. }
  33. private void checkLabels(String descriptor, int index) {
  34. List<LabelElement> labels = $(LabelElement.class).all();
  35. assertEquals(
  36. String.format("label incorrect after %s reload", descriptor),
  37. String.format("This is UI %s", index), lastLabelText(labels));
  38. if (!"final".equals(descriptor)) {
  39. assertEquals(
  40. String.format("log message incorrect after %s reload",
  41. descriptor),
  42. String.format("%s. UI %s has been detached", index,
  43. index - 1),
  44. labels.get(0).getText());
  45. }
  46. }
  47. private String lastLabelText(List<LabelElement> labels) {
  48. return labels.get(labels.size() - 1).getText();
  49. }
  50. private void click(String caption) {
  51. $(ButtonElement.class).caption(caption).first().click();
  52. }
  53. }