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.

FooterTest.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.table;
  17. import static org.junit.Assert.assertEquals;
  18. import java.io.IOException;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebDriver;
  22. import org.openqa.selenium.support.ui.ExpectedCondition;
  23. import com.vaadin.testbench.TestBenchElement;
  24. import com.vaadin.testbench.elements.ButtonElement;
  25. import com.vaadin.testbench.elements.CheckBoxElement;
  26. import com.vaadin.testbench.elements.TableElement;
  27. import com.vaadin.testbench.elements.TextFieldElement;
  28. import com.vaadin.testbench.parallel.BrowserUtil;
  29. import com.vaadin.tests.tb3.MultiBrowserTest;
  30. /**
  31. * Tests Table Footer
  32. *
  33. * @since
  34. * @author Vaadin Ltd
  35. */
  36. public class FooterTest extends MultiBrowserTest {
  37. @Test
  38. public void testFooter() throws IOException {
  39. openTestURL();
  40. waitForElementPresent(By.className("v-table"));
  41. compareScreen("initial");
  42. TableElement table = $(TableElement.class).first();
  43. TestBenchElement footer0 = table.getFooterCell(0);
  44. TestBenchElement footer1 = table.getFooterCell(1);
  45. TestBenchElement footer2 = table.getFooterCell(2);
  46. assertEquals("Footer1", footer0.getText());
  47. assertEquals("Footer2", footer1.getText());
  48. assertEquals("Footer3", footer2.getText());
  49. CheckBoxElement checkBox = $(CheckBoxElement.class).first();
  50. checkBox.click();
  51. if (!BrowserUtil.isIE8(getDesiredCapabilities())) {
  52. // excluded IE8 since its screenshots varies from run-to-run
  53. compareScreen("no-footer");
  54. }
  55. checkBox.click();
  56. if (!BrowserUtil.isIE8(getDesiredCapabilities())) {
  57. // excluded IE8 since its screenshots varies from run-to-run
  58. compareScreen("footer-col1-col2-col3-a");
  59. }
  60. table = $(TableElement.class).first();
  61. footer0 = table.getFooterCell(0);
  62. footer1 = table.getFooterCell(1);
  63. footer2 = table.getFooterCell(2);
  64. assertEquals("Footer1", footer0.getText());
  65. assertEquals("Footer2", footer1.getText());
  66. assertEquals("Footer3", footer2.getText());
  67. // open table column selector menu
  68. table.findElement(By.className("v-table-column-selector")).click();
  69. // hide col2
  70. findElements(By.className("gwt-MenuItem")).get(1).click();
  71. if (!BrowserUtil.isIE8(getDesiredCapabilities())) {
  72. // excluded IE8 since its screenshots varies from run-to-run
  73. compareScreen("footer-col1-col3");
  74. }
  75. // open table column selector menu
  76. table.findElement(By.className("v-table-column-selector")).click();
  77. // show col2
  78. findElements(By.className("gwt-MenuItem")).get(1).click();
  79. if (!BrowserUtil.isIE8(getDesiredCapabilities())) {
  80. // excluded IE8 since its screenshots varies from run-to-run
  81. compareScreen("footer-col1-col2-col3-b");
  82. }
  83. TextFieldElement tf = $(TextFieldElement.class).first();
  84. tf.clear();
  85. tf.sendKeys("fuu");
  86. ButtonElement button = $(ButtonElement.class).first();
  87. button.click();
  88. table = $(TableElement.class).first();
  89. footer0 = table.getFooterCell(0);
  90. assertEquals("fuu", footer0.getText());
  91. tf = $(TextFieldElement.class).get(1);
  92. tf.clear();
  93. tf.sendKeys("bar");
  94. button = $(ButtonElement.class).get(1);
  95. button.click();
  96. table = $(TableElement.class).first();
  97. footer1 = table.getFooterCell(1);
  98. assertEquals("bar", footer1.getText());
  99. tf = $(TextFieldElement.class).get(2);
  100. tf.clear();
  101. tf.sendKeys("");
  102. button = $(ButtonElement.class).get(2);
  103. button.click();
  104. table = $(TableElement.class).first();
  105. footer2 = table.getFooterCell(2);
  106. assertEquals("", footer2.getText().trim());
  107. TextFieldElement tf1 = $(TextFieldElement.class).first();
  108. tf1.clear();
  109. tf1.sendKeys("Footer1");
  110. TextFieldElement tf2 = $(TextFieldElement.class).get(1);
  111. tf2.clear();
  112. tf2.sendKeys("Footer2");
  113. TextFieldElement tf3 = $(TextFieldElement.class).get(2);
  114. tf3.clear();
  115. tf3.sendKeys("Footer3");
  116. waitUntiltextFieldIsChangedTo(tf1, "Footer1");
  117. waitUntiltextFieldIsChangedTo(tf2, "Footer2");
  118. waitUntiltextFieldIsChangedTo(tf3, "Footer3");
  119. button = $(ButtonElement.class).first();
  120. button.click();
  121. button = $(ButtonElement.class).get(1);
  122. button.click();
  123. button = $(ButtonElement.class).get(2);
  124. button.click();
  125. waitUntilFooterCellIsChangedTo(0, "Footer1");
  126. waitUntilFooterCellIsChangedTo(1, "Footer2");
  127. waitUntilFooterCellIsChangedTo(2, "Footer3");
  128. table = $(TableElement.class).first();
  129. footer0 = table.getFooterCell(0);
  130. assertEquals("Footer1", footer0.getText());
  131. if (!BrowserUtil.isIE8(getDesiredCapabilities())) {
  132. // excluded IE8 since its screenshots varies from run-to-run
  133. compareScreen("footer-col1-col2-col3-c");
  134. }
  135. }
  136. private void waitUntiltextFieldIsChangedTo(final TextFieldElement tf,
  137. final String text) {
  138. waitUntil(new ExpectedCondition<Boolean>() {
  139. @Override
  140. public Boolean apply(WebDriver input) {
  141. return text.equals(tf.getValue());
  142. }
  143. @Override
  144. public String toString() {
  145. // Timed out after 10 seconds waiting for ...
  146. return String.format("textfields value was '%s'",
  147. "" + tf.getText());
  148. }
  149. });
  150. }
  151. private void waitUntilFooterCellIsChangedTo(final int cell,
  152. final String footer) {
  153. final TestBenchElement footerCell = $(TableElement.class).first()
  154. .getFooterCell(cell);
  155. waitUntil(new ExpectedCondition<Boolean>() {
  156. @Override
  157. public Boolean apply(WebDriver input) {
  158. return footer.equals(footerCell.getText());
  159. }
  160. @Override
  161. public String toString() {
  162. // Timed out after 10 seconds waiting for ...
  163. return String.format("footer cell %s's text was'%s'",
  164. "" + cell, footerCell.getText());
  165. }
  166. });
  167. }
  168. }