View Javadoc

1   package com.atlassian.webdriver.jira.component.dashboard;
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.atlassian.webdriver.utils.MouseEvents;
8   import org.openqa.selenium.By;
9   import org.openqa.selenium.WebElement;
10  
11  import javax.inject.Inject;
12  
13  /**
14   * Implements a object for interacting with a JIRA Dashboard Gadget.
15   */
16  public class Gadget
17  {
18      @Inject
19      AtlassianWebDriver driver;
20  
21      @Inject
22      PageBinder pageBinder;
23  
24      private final String id;
25      private String titleId;
26      private String frameId;
27      private WebElement chrome;
28  
29      public Gadget(String id)
30      {
31          this.id = id;
32      }
33  
34      @Init
35      public void init()
36      {
37          this.frameId = "gadget-" + id;
38          this.titleId = frameId + "-title";
39          final String chromeId = frameId + "-chrome";
40  
41          // This should only get invoked when the gadget doesn't exist. If there are unexpected timing
42          // issues, could change to a wait until.
43          if (!Check.elementExists(By.id(titleId), driver))
44          {
45              throw new IllegalStateException("Gadget with id: " + id + " not found on page.");
46          }
47  
48          driver.waitUntilElementIsLocated(By.id(frameId));
49          this.chrome = driver.findElement(By.id(chromeId));
50      }
51  
52      /**
53       * Switches to the gadget iframe and returns a GadgetView which is the html page for the gadget.
54       * @return
55       */
56      public GadgetView view()
57      {
58          driver.switchTo().frame(frameId);
59          driver.waitUntilElementIsLocated(By.className("view"));
60  
61          return pageBinder.bind(GadgetView.class, driver.findElement(By.className("view")));
62      }
63  
64      public void minimize()
65      {
66  
67          WebElement dropdown = openDropdown();
68          if (Check.elementExists(By.className("minimization"), dropdown))
69          {
70              dropdown.findElement(By.className("minimization")).click();
71          }
72          else
73          {
74              closeDropdown();
75          }
76  
77      }
78  
79      public void maximize()
80      {
81  
82          WebElement dropdown = openDropdown();
83          if (Check.elementExists(By.className("maximization"), dropdown))
84          {
85              dropdown.findElement(By.className("maximization")).click();
86          }
87          else
88          {
89              closeDropdown();
90          }
91  
92      }
93  
94      public void refresh()
95      {
96  
97          WebElement dropdown = openDropdown();
98          if (Check.elementExists(By.className("reload"), dropdown))
99          {
100             dropdown.findElement(By.cssSelector(".reload .no_target")).click();
101         }
102         else
103         {
104             closeDropdown();
105         }
106 
107     }
108 
109     public String getGadgetTitle()
110     {
111         return driver.findElement(By.id(titleId)).getText();
112     }
113 
114     private WebElement openDropdown()
115     {
116         WebElement dropdown = getDropdown();
117 
118         if (Check.hasClass("hidden", dropdown))
119         {
120             MouseEvents.hover(chrome, driver)
121                     .findElement(By.className(("aui-dd-trigger")))
122                     .click();
123         }
124 
125         return dropdown;
126     }
127 
128     private void closeDropdown()
129     {
130         WebElement dropdown = getDropdown();
131 
132         if (!Check.hasClass("hidden", dropdown))
133         {
134             chrome.findElement(By.className("aui-dd-trigger")).click();
135         }
136 
137     }
138 
139     private WebElement getDropdown()
140     {
141         return chrome.findElement(By.className("aui-dropdown"));
142     }
143 
144 }