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.

ItemClickEventsTestWithShiftOrCtrl.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package com.vaadin.tests.components.table;
  2. import java.util.List;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import org.openqa.selenium.Keys;
  6. import org.openqa.selenium.remote.DesiredCapabilities;
  7. import com.vaadin.testbench.TestBenchElement;
  8. import com.vaadin.testbench.elements.CheckBoxElement;
  9. import com.vaadin.testbench.elements.LabelElement;
  10. import com.vaadin.testbench.elements.TableElement;
  11. import com.vaadin.testbench.parallel.Browser;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. import static org.junit.Assert.assertNotNull;
  14. import static org.junit.Assert.assertTrue;
  15. public class ItemClickEventsTestWithShiftOrCtrl extends MultiBrowserTest {
  16. @Override
  17. protected Class<?> getUIClass() {
  18. return ItemClickEvents.class;
  19. }
  20. @Override
  21. public List<DesiredCapabilities> getBrowsersToTest() {
  22. // Apparently only Chrome supports ctrl-click..?
  23. return getBrowserCapabilities(Browser.CHROME);
  24. }
  25. private void clickElement(TestBenchElement e) {
  26. assertNotNull(e);
  27. e.click();
  28. }
  29. private void shiftClickElement(TestBenchElement e) {
  30. assertNotNull(e);
  31. e.click(5, 5, Keys.SHIFT);
  32. }
  33. private void ctrlClickElement(TestBenchElement e) {
  34. assertNotNull(e);
  35. e.click(5, 5, Keys.CONTROL);
  36. }
  37. private void assertSelected(TestBenchElement e) {
  38. assertNotNull(e);
  39. assertTrue(hasCssClass(e, "v-selected"));
  40. }
  41. private void assertNotSelected(TestBenchElement e) {
  42. assertNotNull(e);
  43. assertTrue(!hasCssClass(e, "v-selected"));
  44. }
  45. private void assertLog(String compare) {
  46. LabelElement logRow = $(LabelElement.class).id("Log_row_0");
  47. assertNotNull(logRow);
  48. assertTrue(logRow.getText().contains(compare));
  49. }
  50. @Before
  51. public void init() {
  52. openTestURL("restartApplication");
  53. }
  54. @Test
  55. public void testMultiSelectNotSelectable() throws Exception {
  56. // Activate table multi-selection mode
  57. clickElement($(CheckBoxElement.class).caption("multi").get(1));
  58. // Remove the 'selectable' mode from Table
  59. $(CheckBoxElement.class).caption("selectable").get(1).click();
  60. // Get table element
  61. TableElement table = $(TableElement.class).id("table");
  62. // Click some items and check that clicks go through
  63. clickElement(table.getCell(4, 0));
  64. assertLog("left click on table/Item 4");
  65. clickElement(table.getCell(2, 0));
  66. assertLog("left click on table/Item 2");
  67. ctrlClickElement(table.getCell(5, 0));
  68. assertLog("left click on table/Item 5 (ctrl)");
  69. shiftClickElement(table.getCell(3, 0));
  70. assertLog("left click on table/Item 3 (shift)");
  71. }
  72. @Test
  73. public void testSingleNonImmediateNonSelectable() throws Exception {
  74. // Disable table immediate mode
  75. clickElement($(CheckBoxElement.class).caption("immediate").get(1));
  76. // Disable the 'selectable' mode from Table
  77. $(CheckBoxElement.class).caption("selectable").get(1).click();
  78. // Get table element
  79. TableElement table = $(TableElement.class).id("table");
  80. // Click items and verify that click event went through
  81. clickElement(table.getCell(0, 0));
  82. assertLog("left click on table/Item 0");
  83. clickElement(table.getCell(1, 0));
  84. assertLog("left click on table/Item 1");
  85. ctrlClickElement(table.getCell(2, 0));
  86. assertLog("left click on table/Item 2 (ctrl)");
  87. shiftClickElement(table.getCell(3, 0));
  88. assertLog("left click on table/Item 3 (shift)");
  89. }
  90. @Test
  91. public void testMultiSelectNotNull() throws Exception {
  92. // Activate table multi-selection mode
  93. clickElement($(CheckBoxElement.class).caption("multi").get(1));
  94. // Get table element
  95. TableElement table = $(TableElement.class).id("table");
  96. // Click item 10, verify log output
  97. clickElement(table.getCell(9, 0));
  98. assertLog("left click on table/Item 9");
  99. sleep(100);
  100. // Click it again, should not deselect
  101. ctrlClickElement(table.getCell(9, 0));
  102. assertLog("left click on table/Item 9 (ctrl)");
  103. // Click item 4 to select it
  104. ctrlClickElement(table.getCell(3, 0));
  105. assertLog("left click on table/Item 3 (ctrl)");
  106. // Unselect item 10
  107. ctrlClickElement(table.getCell(9, 0));
  108. assertLog("left click on table/Item 9 (ctrl)");
  109. // Try to click item 4, should not deselect
  110. ctrlClickElement(table.getCell(3, 0));
  111. assertLog("left click on table/Item 3 (ctrl)");
  112. // Check that row 4 remains selected
  113. assertSelected(table.getRow(3));
  114. }
  115. @Test
  116. public void testMultiSelectNull() throws Exception {
  117. // Activate table multi-selection mode
  118. clickElement($(CheckBoxElement.class).caption("multi").get(1));
  119. // Activate table null selection mode
  120. clickElement($(CheckBoxElement.class).caption("nullsel").get(1));
  121. // Get table element
  122. TableElement table = $(TableElement.class).id("table");
  123. // Select first item
  124. clickElement(table.getCell(0, 0));
  125. assertLog("left click on table/Item 0");
  126. // Shift-click to select range between first and fifth element
  127. shiftClickElement(table.getCell(4, 0));
  128. assertLog("left click on table/Item 4 (shift)");
  129. // Pick element 7
  130. ctrlClickElement(table.getCell(6, 0));
  131. assertLog("left click on table/Item 6 (ctrl)");
  132. // Un-pick element 3
  133. ctrlClickElement(table.getCell(2, 0));
  134. assertLog("left click on table/Item 2 (ctrl)");
  135. // Check selection
  136. assertSelected(table.getRow(0));
  137. assertSelected(table.getRow(1));
  138. assertNotSelected(table.getRow(2));
  139. assertSelected(table.getRow(3));
  140. assertSelected(table.getRow(4));
  141. assertSelected(table.getRow(6));
  142. }
  143. }