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.

WidgetRenderersTest.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.components.grid;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertNotEquals;
  19. import static org.junit.Assert.assertTrue;
  20. import org.junit.Test;
  21. import org.openqa.selenium.WebDriver;
  22. import org.openqa.selenium.WebElement;
  23. import org.openqa.selenium.interactions.Actions;
  24. import org.openqa.selenium.support.ui.ExpectedCondition;
  25. import com.vaadin.testbench.By;
  26. import com.vaadin.testbench.elements.ButtonElement;
  27. import com.vaadin.testbench.elements.GridElement;
  28. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  29. import com.vaadin.testbench.elements.NotificationElement;
  30. import com.vaadin.testbench.parallel.TestCategory;
  31. import com.vaadin.tests.tb3.MultiBrowserTest;
  32. /**
  33. * TB tests for the various builtin widget-based renderers.
  34. *
  35. * @since
  36. * @author Vaadin Ltd
  37. */
  38. @TestCategory("grid")
  39. public class WidgetRenderersTest extends MultiBrowserTest {
  40. @Override
  41. public void setup() throws Exception {
  42. super.setup();
  43. openTestURL();
  44. }
  45. @Test
  46. public void testProgressBarRenderer() {
  47. assertTrue(getGridCell(0, 0).isElementPresent(
  48. By.className("v-progressbar")));
  49. }
  50. @Test
  51. public void testButtonRenderer() {
  52. WebElement button = getGridCell(0, 1).findElement(
  53. By.className("v-nativebutton"));
  54. button.click();
  55. waitUntilTextUpdated(button, "Clicked!");
  56. }
  57. @Test
  58. public void testButtonRendererAfterCellBeingFocused() {
  59. GridCellElement buttonCell = getGridCell(0, 1);
  60. assertFalse("cell should not be focused before focusing",
  61. buttonCell.isFocused());
  62. // avoid clicking on the button
  63. buttonCell.click(buttonCell.getSize().getWidth() - 10, 5);
  64. assertTrue("cell should be focused after focusing",
  65. buttonCell.isFocused());
  66. WebElement button = buttonCell.findElement(By
  67. .className("v-nativebutton"));
  68. assertNotEquals("Button should not be clicked before click",
  69. "Clicked!", button.getText());
  70. new Actions(getDriver()).moveToElement(button).click().perform();
  71. waitUntilTextUpdated(button, "Clicked!");
  72. }
  73. @Test
  74. public void testImageRenderer() {
  75. final WebElement image = getGridCell(0, 2).findElement(
  76. By.className("gwt-Image"));
  77. waitUntilmageSrcEndsWith(image, "window/img/close.png");
  78. image.click();
  79. waitUntilmageSrcEndsWith(image, "window/img/maximize.png");
  80. }
  81. private void waitUntilmageSrcEndsWith(final WebElement image,
  82. final String expectedText) {
  83. waitUntil(new ExpectedCondition<Boolean>() {
  84. @Override
  85. public Boolean apply(WebDriver input) {
  86. return image.getAttribute("src").endsWith(expectedText);
  87. }
  88. @Override
  89. public String toString() {
  90. // Timed out after 10 seconds waiting for ...
  91. return String
  92. .format("image source to update. Supposed to end with '%s' (was: '%s').",
  93. expectedText, image.getAttribute("src"));
  94. }
  95. });
  96. }
  97. @Test
  98. public void testColumnReorder() {
  99. $(ButtonElement.class).caption("Change column order").first().click();
  100. assertFalse("Notification was present",
  101. isElementPresent(NotificationElement.class));
  102. assertTrue(getGridCell(0, 0)
  103. .isElementPresent(By.className("gwt-Image")));
  104. assertTrue(getGridCell(0, 1).isElementPresent(
  105. By.className("v-progressbar")));
  106. assertTrue(getGridCell(0, 2).isElementPresent(
  107. By.className("v-nativebutton")));
  108. }
  109. @Test
  110. public void testPropertyIdInEvent() {
  111. WebElement button = getGridCell(0, 3).findElement(
  112. By.className("v-nativebutton"));
  113. button.click();
  114. waitUntilTextUpdated(button, WidgetRenderers.PROPERTY_ID);
  115. }
  116. GridCellElement getGridCell(int row, int col) {
  117. return $(GridElement.class).first().getCell(row, col);
  118. }
  119. private void waitUntilTextUpdated(final WebElement button,
  120. final String expectedText) {
  121. waitUntil(new ExpectedCondition<Boolean>() {
  122. @Override
  123. public Boolean apply(WebDriver input) {
  124. return button.getText().equals(expectedText);
  125. }
  126. @Override
  127. public String toString() {
  128. // Timed out after 10 seconds waiting for ...
  129. return String.format("button's text to become '%s' (was: '').",
  130. expectedText, button.getText());
  131. }
  132. });
  133. }
  134. }