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.

FooterClickTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.vaadin.tests.components.table;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import static org.junit.Assert.assertEquals;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6. import org.junit.Test;
  7. import com.vaadin.testbench.TestBenchElement;
  8. import com.vaadin.testbench.elements.TableElement;
  9. import com.vaadin.testbench.elements.CheckBoxElement;
  10. import com.vaadin.testbench.elements.TextFieldElement;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. /**
  13. * Tests Table Footer ClickListener
  14. *
  15. * @author Vaadin Ltd
  16. */
  17. public class FooterClickTest extends MultiBrowserTest {
  18. @Test
  19. public void testFooter() throws IOException {
  20. openTestURL();
  21. TableElement table = $(TableElement.class).first();
  22. TestBenchElement footer0 = table.getFooterCell(0);
  23. footer0.click();
  24. TextFieldElement tf = $(TextFieldElement.class).id("ClickedColumn");
  25. assertEquals("col1", tf.getValue());
  26. assertAnyLogText("1. Clicked on footer: col1");
  27. table = $(TableElement.class).first();
  28. TestBenchElement footer1 = table.getFooterCell(1);
  29. footer1.click();
  30. tf = $(TextFieldElement.class).id("ClickedColumn");
  31. assertEquals("col2", tf.getValue());
  32. assertAnyLogText("2. Clicked on footer: col2");
  33. table = $(TableElement.class).first();
  34. TestBenchElement footer2 = table.getFooterCell(2);
  35. footer2.click();
  36. tf = $(TextFieldElement.class).id("ClickedColumn");
  37. assertEquals("col3", tf.getValue());
  38. assertAnyLogText("3. Clicked on footer: col3");
  39. CheckBoxElement cb = $(CheckBoxElement.class).first();
  40. cb.click();
  41. table = $(TableElement.class).first();
  42. footer0 = table.getFooterCell(0);
  43. footer0.click();
  44. tf = $(TextFieldElement.class).id("ClickedColumn");
  45. assertEquals("col1", tf.getValue());
  46. assertAnyLogText("4. Clicked on footer: col1");
  47. table = $(TableElement.class).first();
  48. footer1 = table.getFooterCell(1);
  49. footer1.click();
  50. tf = $(TextFieldElement.class).id("ClickedColumn");
  51. assertEquals("col2", tf.getValue());
  52. assertAnyLogText("5. Clicked on footer: col2");
  53. table = $(TableElement.class).first();
  54. footer2 = table.getFooterCell(2);
  55. footer2.click();
  56. tf = $(TextFieldElement.class).id("ClickedColumn");
  57. assertEquals("col3", tf.getValue());
  58. assertAnyLogText("6. Clicked on footer: col3");
  59. }
  60. private void assertAnyLogText(String... texts) {
  61. assertThat(String.format(
  62. "Correct log text was not found, expected any of %s",
  63. Arrays.asList(texts)), logContainsAnyText(texts));
  64. }
  65. private boolean logContainsAnyText(String... texts) {
  66. for (String text : texts) {
  67. if (logContainsText(text)) {
  68. return true;
  69. }
  70. }
  71. return false;
  72. }
  73. }