View Javadoc

1   package com.atlassian.webdriver.confluence.page;
2   
3   import com.atlassian.pageobjects.binder.Init;
4   import com.atlassian.webdriver.confluence.component.macro.UserMacro;
5   import com.atlassian.webdriver.utils.by.ByJquery;
6   import org.openqa.selenium.By;
7   import org.openqa.selenium.WebElement;
8   import org.openqa.selenium.support.FindBy;
9   
10  import java.util.HashMap;
11  import java.util.Map;
12  import java.util.Set;
13  
14  /**
15   * 
16   */
17  public class PeopleDirectoryPage extends ConfluenceAbstractPage
18  {
19      private static final String URI = "/browsepeople.action";
20  
21      @FindBy (linkText = "All People")
22      private WebElement allPeopleLink;
23  
24      @FindBy (linkText = "People with Personal Spaces")
25      private WebElement peopleWithPersonalSpacesLink;
26  
27      private Map<String, UserMacro> users = new HashMap<String, UserMacro>();
28  
29  
30      public String getUrl()
31      {
32          return URI;
33      }
34  
35      @Init
36      public void parseUsers()
37      {
38          for (WebElement profile : driver.findElements(By.className("profile-macro")))
39          {
40              UserMacro userMacro = pageBinder.bind(UserMacro.class, By.className("vcard"), profile);
41              users.put(userMacro.getUsername(), userMacro);
42          }
43      }
44  
45      /**
46       * @return a set which contains all the usernames on the page.
47       */
48      public Set<String> getAllUsernames()
49      {
50          return users.keySet();
51      }
52  
53      public PeopleDirectoryPage showAllPeople()
54      {
55          if (!isShowingAllPeople())
56          {
57              allPeopleLink.click();
58          }
59  
60          return pageBinder.bind(PeopleDirectoryPage.class);
61      }
62  
63      public PeopleDirectoryPage showAllPeopleWithPersonalSpaces()
64      {
65  
66          if (!isShowingPeopleWithPersonalSpaces())
67          {
68              peopleWithPersonalSpacesLink.click();
69          }
70  
71          return pageBinder.bind(PeopleDirectoryPage.class);
72  
73      }
74  
75      public boolean hasUser(String username)
76      {
77          return users.containsKey(username);
78      }
79  
80      public UserMacro getUserMacro(String username)
81      {
82          return hasUser(username) ? users.get(username) : null;
83      }
84  
85      public boolean isShowingAllPeople()
86      {
87          return driver.elementExists(ByJquery.$("div.greybox p strong:contains(All People)"));
88      }
89  
90      public boolean isShowingPeopleWithPersonalSpaces()
91      {
92          return driver.elementExists(ByJquery.$("div.greybox p strong:contains(People with Personal Spaces)"));
93      }
94  }