1 package com.atlassian.pageobjects.elements;
2
3 import com.atlassian.pageobjects.PageBinder;
4 import com.atlassian.pageobjects.elements.timeout.TimeoutType;
5 import com.atlassian.webdriver.AtlassianWebDriver;
6 import com.google.common.collect.Lists;
7 import org.openqa.selenium.By;
8 import org.openqa.selenium.WebElement;
9
10 import javax.inject.Inject;
11 import java.util.List;
12
13
14
15
16
17 public class GlobalElementFinder implements PageElementFinder {
18
19 @Inject
20 AtlassianWebDriver driver;
21
22 @Inject
23 PageBinder pageBinder;
24
25 public PageElement find(final By by)
26 {
27 return pageBinder.bind(WebDriverElement.class, by);
28 }
29
30 public PageElement find(final By by, TimeoutType timeoutType)
31 {
32 return pageBinder.bind(WebDriverElement.class, by, timeoutType);
33 }
34
35 public <T extends PageElement> T find(final By by, Class<T> elementClass)
36 {
37 return pageBinder.bind(WebDriverElementMappings.findMapping(elementClass), by);
38 }
39
40 public <T extends PageElement> T find(final By by, Class<T> elementClass, TimeoutType timeoutType)
41 {
42 return pageBinder.bind(WebDriverElementMappings.findMapping(elementClass), by, timeoutType);
43 }
44
45 public List<PageElement> findAll(final By by)
46 {
47 return findAll(by, TimeoutType.DEFAULT);
48 }
49
50 public List<PageElement> findAll(final By by, TimeoutType timeoutType)
51 {
52 return findAll(by, PageElement.class, timeoutType);
53 }
54
55 public <T extends PageElement> List<T> findAll(final By by, Class<T> elementClass)
56 {
57 return findAll(by, elementClass, TimeoutType.DEFAULT);
58 }
59
60 public <T extends PageElement> List<T> findAll(final By by, Class<T> elementClass, TimeoutType timeoutType)
61 {
62 List<T> elements = Lists.newLinkedList();
63 List<WebElement> webElements = driver.findElements(by);
64
65 for(int i = 0; i < webElements.size(); i++)
66 {
67 elements.add(pageBinder.bind(WebDriverElementMappings.findMapping(elementClass),
68 WebDriverLocators.list(webElements.get(i), by, i, WebDriverLocators.root()), timeoutType));
69 }
70
71 return elements;
72 }
73 }