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.

TreeContextMenuAndIconsTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.vaadin.v7.tests.components.tree;
  2. import static org.junit.Assert.assertEquals;
  3. import org.junit.Test;
  4. import org.openqa.selenium.Dimension;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.interactions.Actions;
  7. import com.vaadin.testbench.By;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. public class TreeContextMenuAndIconsTest extends MultiBrowserTest {
  10. @Override
  11. protected Class<?> getUIClass() {
  12. return Trees.class;
  13. }
  14. @Test
  15. public void testSimpleContextMenu() throws Exception {
  16. openTestURL();
  17. selectMenuPath("Settings", "Show event log");
  18. selectMenuPath("Component", "Features", "Context menu",
  19. "Item without icon");
  20. openContextMenu(getTreeNodeByCaption("Item 1"));
  21. compareScreen("contextmenu-noicon");
  22. closeContextMenu();
  23. }
  24. @Test
  25. public void testContextMenuWithAndWithoutIcon() throws Exception {
  26. openTestURL();
  27. selectMenuPath("Settings", "Show event log");
  28. selectMenuPath("Component", "Features", "Context menu",
  29. "With and without icon");
  30. openContextMenu(getTreeNodeByCaption("Item 1"));
  31. compareScreen("caption-only-and-has-icon");
  32. closeContextMenu();
  33. }
  34. @Test
  35. public void testContextLargeIcon() throws Exception {
  36. openTestURL();
  37. selectMenuPath("Settings", "Show event log");
  38. selectMenuPath("Component", "Features", "Context menu",
  39. "Only one large icon");
  40. WebElement menu = openContextMenu(getTreeNodeByCaption("Item 1"));
  41. // reindeer doesn't support menu with larger row height, so the
  42. // background image contains parts of other sprites =>
  43. // just check that the menu is of correct size
  44. Dimension size = menu.getSize();
  45. assertEquals("Menu height with large icons", 74, size.height);
  46. closeContextMenu();
  47. }
  48. @Test
  49. public void testContextRemoveIcon() throws Exception {
  50. openTestURL();
  51. selectMenuPath("Settings", "Show event log");
  52. selectMenuPath("Component", "Features", "Context menu",
  53. "Only one large icon");
  54. openContextMenu(getTreeNodeByCaption("Item 1"));
  55. closeContextMenu();
  56. selectMenuPath("Component", "Features", "Context menu",
  57. "Item without icon");
  58. openContextMenu(getTreeNodeByCaption("Item 1"));
  59. compareScreen("contextmenu-noicon");
  60. closeContextMenu();
  61. }
  62. private WebElement openContextMenu(WebElement element) {
  63. Actions actions = new Actions(getDriver());
  64. // Note: on Firefox, the first menu item does not get focus; on other
  65. // browsers it does
  66. actions.contextClick(element);
  67. actions.perform();
  68. return findElement(By.className("v-contextmenu"));
  69. }
  70. private void closeContextMenu() {
  71. findElement(By.className("v-app")).click();
  72. }
  73. private WebElement getTreeNodeByCaption(String caption) {
  74. return getDriver()
  75. .findElement(By.xpath("//span[text() = '" + caption + "']"));
  76. }
  77. }