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.

ReconnectDialogThemeTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 java.awt.image.BufferedImage;
  18. import java.io.ByteArrayInputStream;
  19. import java.io.IOException;
  20. import javax.imageio.ImageIO;
  21. import org.junit.Assert;
  22. import org.junit.Test;
  23. import org.openqa.selenium.By;
  24. import org.openqa.selenium.OutputType;
  25. import org.openqa.selenium.TakesScreenshot;
  26. import org.openqa.selenium.WebDriver;
  27. import org.openqa.selenium.WebElement;
  28. import org.openqa.selenium.support.ui.ExpectedCondition;
  29. import com.vaadin.testbench.elements.ButtonElement;
  30. import com.vaadin.testbench.parallel.BrowserUtil;
  31. import com.vaadin.testbench.parallel.TestCategory;
  32. import com.vaadin.tests.tb3.CustomTestBenchCommandExecutor;
  33. import com.vaadin.tests.tb3.MultiBrowserThemeTestWithProxy;
  34. @TestCategory("")
  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. Assert.assertEquals("1. Hello from the server", getLogRow(0));
  44. disconnectProxy();
  45. helloButton.click();
  46. testBench().disableWaitForVaadin();
  47. waitUntil(new ExpectedCondition<Boolean>() {
  48. @Override
  49. public Boolean apply(WebDriver input) {
  50. boolean present = isElementPresent(reconnectDialogBy);
  51. return present;
  52. }
  53. });
  54. WebElement dialog = findElement(reconnectDialogBy);
  55. WebElement spinner = dialog.findElement(By.className("spinner"));
  56. // Hide spinner to make screenshot stable
  57. executeScript("arguments[0].style.visibility='hidden';", spinner);
  58. compareScreen("onscreen-without-spinner");
  59. // Show spinner and make sure it is shown by comparing to the screenshot
  60. // without a spinner
  61. executeScript("arguments[0].style.visibility='visible';", spinner);
  62. BufferedImage fullScreen = ImageIO.read(new ByteArrayInputStream(
  63. ((TakesScreenshot) getDriver())
  64. .getScreenshotAs(OutputType.BYTES)));
  65. BufferedImage spinnerImage = CustomTestBenchCommandExecutor
  66. .cropToElement(spinner, fullScreen,
  67. BrowserUtil.isIE8(getDesiredCapabilities()));
  68. assertHasManyColors("Spinner is not shown", spinnerImage);
  69. }
  70. private void assertHasManyColors(String message, BufferedImage spinnerImage) {
  71. int backgroundColor = spinnerImage.getRGB(0, 0);
  72. for (int x = 0; x < spinnerImage.getWidth(); x++) {
  73. for (int y = 0; y < spinnerImage.getHeight(); y++) {
  74. if (Math.abs(spinnerImage.getRGB(x, y) - backgroundColor) > 50) {
  75. return;
  76. }
  77. }
  78. }
  79. Assert.fail(message);
  80. }
  81. @Override
  82. protected Class<?> getUIClass() {
  83. return ReconnectDialogUI.class;
  84. }
  85. }