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.

ReconnectDialogUITest.java 2.7KB

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.application;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.By;
  20. import org.openqa.selenium.WebDriver;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.support.ui.ExpectedCondition;
  23. import com.jcraft.jsch.JSchException;
  24. import com.vaadin.testbench.elements.ButtonElement;
  25. import com.vaadin.tests.tb3.MultiBrowserTestWithProxy;
  26. public class ReconnectDialogUITest extends MultiBrowserTestWithProxy {
  27. @Test
  28. public void reconnectDialogShownAndDisappears() throws JSchException {
  29. openTestURL();
  30. getButton().click();
  31. Assert.assertEquals("1. Hello from the server", getLogRow(0));
  32. disconnectProxy();
  33. getButton().click();
  34. waitForReconnectDialogWithText("Server connection lost, trying to reconnect...");
  35. connectProxy();
  36. waitForReconnectDialogToDisappear();
  37. Assert.assertEquals("2. Hello from the server", getLogRow(0));
  38. }
  39. @Test
  40. public void gaveUpMessageShown() {
  41. openTestURL("reconnectAttempts=3");
  42. getButton().click();
  43. Assert.assertEquals("1. Hello from the server", getLogRow(0));
  44. disconnectProxy();
  45. getButton().click();
  46. waitForReconnectDialogWithText("Server connection lost.");
  47. }
  48. private void waitForReconnectDialogWithText(final String text) {
  49. waitForReconnectDialogPresent();
  50. final WebElement reconnectDialog = findElement(ReconnectDialogThemeTest.reconnectDialogBy);
  51. waitUntil(new ExpectedCondition<Boolean>() {
  52. @Override
  53. public Boolean apply(WebDriver input) {
  54. return reconnectDialog.findElement(By.className("text"))
  55. .getText().equals(text);
  56. }
  57. }, 10);
  58. }
  59. private void waitForReconnectDialogToDisappear() {
  60. waitForElementNotPresent(ReconnectDialogThemeTest.reconnectDialogBy);
  61. }
  62. private void waitForReconnectDialogPresent() {
  63. waitForElementPresent(ReconnectDialogThemeTest.reconnectDialogBy);
  64. }
  65. private WebElement getButton() {
  66. return $(ButtonElement.class).first();
  67. }
  68. }