1 package com.atlassian.pageobjects.components.aui;
2
3 import com.atlassian.pageobjects.PageBinder;
4 import com.atlassian.pageobjects.binder.Init;
5 import com.atlassian.pageobjects.binder.InvalidPageStateException;
6 import com.atlassian.pageobjects.components.TabbedComponent;
7 import com.atlassian.pageobjects.elements.PageElement;
8 import com.atlassian.pageobjects.elements.PageElementFinder;
9 import com.atlassian.pageobjects.elements.query.Poller;
10 import org.openqa.selenium.By;
11
12 import javax.inject.Inject;
13 import java.util.List;
14
15
16
17
18
19
20 public class AuiTabs implements TabbedComponent
21 {
22 @Inject
23 protected PageBinder pageBinder;
24
25 @Inject
26 protected PageElementFinder elementFinder;
27
28 private final By rootLocator;
29
30 private PageElement rootElement;
31
32 public AuiTabs(By locator)
33 {
34 this.rootLocator = locator;
35 }
36
37 @Init
38 public void initialize()
39 {
40 this.rootElement = elementFinder.find(rootLocator);
41 }
42
43 public PageElement selectedTab()
44 {
45 List<PageElement> items = rootElement.find(By.className("tabs-menu")).findAll(By.tagName("li"));
46
47 for(int i = 0; i < items.size(); i++)
48 {
49 PageElement tab = items.get(i);
50 if(tab.hasClass("active-tab"))
51 {
52 return tab;
53 }
54 }
55
56 throw new InvalidPageStateException("A tab must be active.", this);
57 }
58
59 public PageElement selectedView()
60 {
61 List<PageElement> panes = rootElement.findAll(By.className("tabs-pane"));
62 for(int i = 0; i < panes.size(); i++)
63 {
64 PageElement pane = panes.get(i);
65 if(pane.hasClass("active-pane"))
66 {
67 return pane;
68 }
69 }
70
71 throw new InvalidPageStateException("A pane must be active", this);
72 }
73
74 public List<PageElement> tabs()
75 {
76 return rootElement.find(By.className("tabs-menu")).findAll(By.tagName("li"));
77 }
78
79 public PageElement openTab(String tabText)
80 {
81 List<PageElement> tabs = rootElement.find(By.className("tabs-menu")).findAll(By.tagName("a"));
82
83 for(int i = 0; i < tabs.size(); i++)
84 {
85 if(tabs.get(i).getText().equals(tabText))
86 {
87 PageElement listItem = tabs.get(i);
88 listItem.click();
89
90
91 String tabViewClassName = listItem.getAttribute("href").substring(1);
92 PageElement pane = rootElement.find(By.id(tabViewClassName));
93 Poller.waitUntilTrue(pane.timed().hasClass("active-pane"));
94
95 return pane;
96 }
97 }
98
99 throw new InvalidPageStateException("Tab not found", this);
100 }
101
102 public PageElement openTab(PageElement tab)
103 {
104 String tabIdentifier = tab.getText();
105 return openTab(tabIdentifier);
106 }
107 }