View Javadoc

1   package com.atlassian.webdriver.jira.component.menu;
2   
3   import com.atlassian.pageobjects.PageBinder;
4   import com.atlassian.pageobjects.binder.Init;
5   import com.atlassian.webdriver.AtlassianWebDriver;
6   import com.atlassian.webdriver.utils.Check;
7   import com.google.common.base.Function;
8   import org.openqa.selenium.By;
9   import org.openqa.selenium.WebDriver;
10  import org.openqa.selenium.WebElement;
11  
12  import javax.inject.Inject;
13  
14  /**
15   * Represents an AUI dropdown menu
16   */
17  public class AuiDropdownMenu
18  {
19      @Inject
20      protected AtlassianWebDriver driver;
21  
22      @Inject
23      protected PageBinder pageBinder;
24  
25      private final By rootElementLocator;
26      private WebElement rootElement;
27  
28      /**
29       * Default constructor
30       * @param rootElementLocator The locator to the root element of the menu.
31       */
32      public AuiDropdownMenu(By rootElementLocator)
33      {
34          this.rootElementLocator = rootElementLocator;
35      }
36  
37      @Init
38      public void initialize()
39      {
40          rootElement = driver.findElement(rootElementLocator);
41      }
42  
43      public AuiDropdownMenu open()
44      {
45          if(!isOpen())
46          {
47              rootElement.findElement(By.cssSelector("a.drop")).click();
48              waitUntilOpen();
49          }
50          return this;
51      }
52  
53      public boolean isOpen()
54      {
55          return Check.hasClass("active", rootElement)
56                  && !Check.elementExists(By.className("loading"), rootElement)
57                  && Check.elementExists(By.tagName("li"), rootElement);
58      }
59  
60      public AuiDropdownMenu close()
61      {
62          if(isOpen())
63          {
64              rootElement.findElement(By.cssSelector("a.drop")).click();
65              waitUntilClose();
66          }
67          return this;
68      }
69  
70      public void waitUntilOpen()
71      {
72          driver.waitUntil(new Function<WebDriver,Boolean>(){
73              public Boolean apply( WebDriver webDriver) {
74                  return isOpen();
75              }
76          });
77      }
78  
79      public void waitUntilClose()
80      {
81          driver.waitUntil(new Function<WebDriver,Boolean>(){
82              public Boolean apply( WebDriver webDriver) {
83                  return !isOpen();
84              }
85          });
86      }
87  }