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.

LabelEmbeddedClickThroughForTableTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.vaadin.tests.components.table;
  2. import static org.junit.Assert.assertEquals;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebElement;
  7. import com.vaadin.testbench.elements.TableElement;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. /**
  10. * Tests clicks on different types of Table contents.
  11. *
  12. * @author Vaadin Ltd
  13. */
  14. public class LabelEmbeddedClickThroughForTableTest extends MultiBrowserTest {
  15. @Test
  16. public void testNotification() {
  17. openTestURL();
  18. TableElement table = $(TableElement.class).first();
  19. // click first cell of first row
  20. clickCell(table, 0, 0);
  21. // click first cell of second row
  22. clickCell(table, 1, 0);
  23. // click the ordinary label component on first row
  24. clickLabel(table, 0, 1);
  25. // click the ordinary label component on second row
  26. clickLabel(table, 1, 1);
  27. // click the html-content label component on first row
  28. clickBoldTag(table, 0, 2);
  29. // click the ordinary label component on second row (some browsers
  30. // navigate away from the page if you try to click the link in the
  31. // html-content label)
  32. clickLabel(table, 1, 1);
  33. // click the embedded image on first row
  34. clickImageTag(table, 0, 3);
  35. // click the embedded image on second row
  36. clickImageTag(table, 1, 3);
  37. }
  38. private void clickImageTag(TableElement table, int row, int column) {
  39. table.getCell(row, column).findElement(By.className("v-embedded"))
  40. .findElement(By.tagName("img")).click();
  41. checkRowSelected(table, row);
  42. }
  43. private void clickBoldTag(TableElement table, int row, int column) {
  44. table.getCell(row, column).findElement(By.className("v-label"))
  45. .findElement(By.tagName("b")).click();
  46. checkRowSelected(table, row);
  47. }
  48. private void clickLabel(TableElement table, int row, int column) {
  49. table.getCell(row, column).findElement(By.className("v-label")).click();
  50. checkRowSelected(table, row);
  51. }
  52. private void clickCell(TableElement table, int row, int column) {
  53. table.getCell(row, column).click();
  54. checkRowSelected(table, row);
  55. }
  56. private void checkRowSelected(TableElement table, int rowIndex) {
  57. List<WebElement> selectedRows = table
  58. .findElement(By.className("v-table-body"))
  59. .findElements(By.className("v-selected"));
  60. assertEquals("unexpected table selection size", 1, selectedRows.size());
  61. assertEquals(
  62. "contents of the selected row don't match contents of the row #"
  63. + rowIndex,
  64. table.getCell(rowIndex, 0).getText(),
  65. selectedRows.get(0)
  66. .findElement(By.className("v-table-cell-wrapper"))
  67. .getText());
  68. }
  69. }