Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ReconnectDialogThemeTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.application;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.fail;
  19. import java.awt.image.BufferedImage;
  20. import java.io.ByteArrayInputStream;
  21. import java.io.IOException;
  22. import javax.imageio.ImageIO;
  23. import org.junit.Test;
  24. import org.openqa.selenium.By;
  25. import org.openqa.selenium.OutputType;
  26. import org.openqa.selenium.TakesScreenshot;
  27. import org.openqa.selenium.WebDriver;
  28. import org.openqa.selenium.WebElement;
  29. import org.openqa.selenium.support.ui.ExpectedCondition;
  30. import com.vaadin.testbench.elements.ButtonElement;
  31. import com.vaadin.testbench.parallel.TestCategory;
  32. import com.vaadin.tests.tb3.CustomTestBenchCommandExecutor;
  33. import com.vaadin.tests.tb3.MultiBrowserThemeTestWithProxy;
  34. @TestCategory("communication")
  35. public class ReconnectDialogThemeTest extends MultiBrowserThemeTestWithProxy {
  36. static By reconnectDialogBy = By.className("v-reconnect-dialog");
  37. @Test
  38. public void reconnectDialogTheme() throws IOException {
  39. openTestURL();
  40. ButtonElement helloButton = $(ButtonElement.class).caption("Say hello")
  41. .first();
  42. helloButton.click();
  43. assertEquals("1. Hello from the server", getLogRow(0));
  44. disconnectProxy();
  45. helloButton.click();
  46. testBench().disableWaitForVaadin();
  47. waitUntil(driver -> isElementPresent(reconnectDialogBy));
  48. WebElement dialog = findElement(reconnectDialogBy);
  49. WebElement spinner = dialog.findElement(By.className("spinner"));
  50. // Hide spinner to make screenshot stable
  51. executeScript("arguments[0].style.visibility='hidden';", spinner);
  52. compareScreen("onscreen-without-spinner");
  53. // Show spinner and make sure it is shown by comparing to the screenshot
  54. // without a spinner
  55. executeScript("arguments[0].style.visibility='visible';", spinner);
  56. BufferedImage fullScreen = ImageIO
  57. .read(new ByteArrayInputStream(((TakesScreenshot) getDriver())
  58. .getScreenshotAs(OutputType.BYTES)));
  59. BufferedImage spinnerImage = CustomTestBenchCommandExecutor
  60. .cropToElement(spinner, fullScreen);
  61. assertHasManyColors("Spinner is not shown", spinnerImage);
  62. }
  63. @Test
  64. public void gaveUpTheme() throws IOException {
  65. openTestURL("reconnectAttempts=3");
  66. waitUntil(new ExpectedCondition<Boolean>() {
  67. @Override
  68. public Boolean apply(WebDriver input) {
  69. try {
  70. return $(ButtonElement.class).first() != null;
  71. } catch (Exception e) {
  72. return false;
  73. }
  74. }
  75. });
  76. disconnectProxy();
  77. $(ButtonElement.class).first().click();
  78. waitForReconnectDialogWithText("Server connection lost.");
  79. compareScreen("gaveupdialog");
  80. }
  81. private void waitForReconnectDialogWithText(final String text) {
  82. waitUntil(new ExpectedCondition<Boolean>() {
  83. @Override
  84. public Boolean apply(WebDriver input) {
  85. try {
  86. final WebElement reconnectDialog = findElement(
  87. ReconnectDialogThemeTest.reconnectDialogBy);
  88. return reconnectDialog.findElement(By.className("text"))
  89. .getText().equals(text);
  90. } catch (Exception e) {
  91. return false;
  92. }
  93. }
  94. }, 10);
  95. }
  96. private void assertHasManyColors(String message,
  97. BufferedImage spinnerImage) {
  98. int backgroundColor = spinnerImage.getRGB(0, 0);
  99. for (int x = 0; x < spinnerImage.getWidth(); x++) {
  100. for (int y = 0; y < spinnerImage.getHeight(); y++) {
  101. if (Math.abs(
  102. spinnerImage.getRGB(x, y) - backgroundColor) > 50) {
  103. return;
  104. }
  105. }
  106. }
  107. fail(message);
  108. }
  109. @Override
  110. protected Class<?> getUIClass() {
  111. return ReconnectDialogUI.class;
  112. }
  113. }