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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.tree;
  17. import java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.Dimension;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.interactions.Actions;
  23. import org.openqa.selenium.remote.DesiredCapabilities;
  24. import com.vaadin.testbench.By;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. public class TreeContextMenuAndIconsTest extends MultiBrowserTest {
  27. @Override
  28. protected Class<?> getUIClass() {
  29. return Trees.class;
  30. }
  31. @Override
  32. public List<DesiredCapabilities> getBrowsersToTest() {
  33. return getBrowsersSupportingContextMenu();
  34. }
  35. @Test
  36. public void testSimpleContextMenu() throws Exception {
  37. openTestURL();
  38. selectMenuPath("Settings", "Show event log");
  39. selectMenuPath("Component", "Features", "Context menu",
  40. "Item without icon");
  41. openContextMenu(getTreeNodeByCaption("Item 1"));
  42. compareScreen("contextmenu-noicon");
  43. closeContextMenu();
  44. }
  45. @Test
  46. public void testContextMenuWithAndWithoutIcon() throws Exception {
  47. openTestURL();
  48. selectMenuPath("Settings", "Show event log");
  49. selectMenuPath("Component", "Features", "Context menu",
  50. "With and without icon");
  51. openContextMenu(getTreeNodeByCaption("Item 1"));
  52. compareScreen("caption-only-and-has-icon");
  53. closeContextMenu();
  54. }
  55. @Test
  56. public void testContextLargeIcon() throws Exception {
  57. openTestURL();
  58. selectMenuPath("Settings", "Show event log");
  59. selectMenuPath("Component", "Features", "Context menu",
  60. "Only one large icon");
  61. WebElement menu = openContextMenu(getTreeNodeByCaption("Item 1"));
  62. // reindeer doesn't support menu with larger row height, so the
  63. // background image contains parts of other sprites =>
  64. // just check that the menu is of correct size
  65. Dimension size = menu.getSize();
  66. Assert.assertEquals("Menu height with large icons", 74, size.height);
  67. closeContextMenu();
  68. }
  69. @Test
  70. public void testContextRemoveIcon() throws Exception {
  71. openTestURL();
  72. selectMenuPath("Settings", "Show event log");
  73. selectMenuPath("Component", "Features", "Context menu",
  74. "Only one large icon");
  75. openContextMenu(getTreeNodeByCaption("Item 1"));
  76. closeContextMenu();
  77. selectMenuPath("Component", "Features", "Context menu",
  78. "Item without icon");
  79. openContextMenu(getTreeNodeByCaption("Item 1"));
  80. compareScreen("contextmenu-noicon");
  81. closeContextMenu();
  82. }
  83. private WebElement openContextMenu(WebElement element) {
  84. Actions actions = new Actions(getDriver());
  85. // Note: on Firefox, the first menu item does not get focus; on other
  86. // browsers it does
  87. actions.contextClick(element);
  88. actions.perform();
  89. return findElement(By.className("v-contextmenu"));
  90. }
  91. private void closeContextMenu() {
  92. findElement(By.className("v-app")).click();
  93. }
  94. private WebElement getTreeNodeByCaption(String caption) {
  95. return getDriver().findElement(
  96. By.xpath("//span[text() = '" + caption + "']"));
  97. }
  98. }