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.

TableMoveFocusWithSelectionTest.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.vaadin.tests.components.table;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import org.openqa.selenium.WebElement;
  5. import com.vaadin.testbench.By;
  6. import com.vaadin.tests.tb3.MultiBrowserTest;
  7. /**
  8. * Tests if table focus is moved correctly to the selected item
  9. *
  10. * @author Vaadin Ltd
  11. */
  12. public class TableMoveFocusWithSelectionTest extends MultiBrowserTest {
  13. @Test
  14. public void selectUnfocusedTableAndAssumeSelectionGetsFocus() {
  15. openTestURL();
  16. // Click on row 5
  17. getDriver().findElement(By.id("row-5")).click();
  18. // Ensure row 5 gets focused
  19. WebElement row5TableRow = getDriver()
  20. .findElement(By.xpath("//div[@id='row-5']/../../.."));
  21. String row5StyleName = row5TableRow.getAttribute("class");
  22. assertTrue(row5StyleName.contains("v-table-focus"));
  23. }
  24. @Test
  25. public void focusShouldStayOnUserSelectedRowIfSelectionChangesServerSide() {
  26. openTestURL();
  27. // Select multiselect
  28. getDriver().findElement(By.id("toggle-mode")).click();
  29. // Click on row 7
  30. getDriver().findElement(By.id("row-7")).click();
  31. // Clicking a row should get the row focus
  32. WebElement row7TableRow = getDriver()
  33. .findElement(By.xpath("//div[@id='row-7']/../../.."));
  34. String row7StyleName = row7TableRow.getAttribute("class");
  35. assertTrue(row7StyleName.contains("v-table-focus"));
  36. // Select row 5-10 server side
  37. getDriver().findElement(By.id("select-510")).click();
  38. /*
  39. * Focus the table again (some browsers steal focus when performing
  40. * button click, other don't)
  41. */
  42. getDriver().findElement(By.id("test-table")).click();
  43. // Ensure row 7 is still focused
  44. row7TableRow = getDriver()
  45. .findElement(By.xpath("//div[@id='row-7']/../../.."));
  46. row7StyleName = row7TableRow.getAttribute("class");
  47. assertTrue(row7StyleName.contains("v-table-focus"));
  48. }
  49. }