View Javadoc

1   package com.atlassian.webdriver.jira.component;
2   
3   import com.atlassian.pageobjects.PageBinder;
4   import com.atlassian.pageobjects.Page;
5   import com.atlassian.webdriver.AtlassianWebDriver;
6   import org.openqa.selenium.By;
7   import org.openqa.selenium.ElementNotVisibleException;
8   import org.openqa.selenium.SearchContext;
9   
10  import javax.inject.Inject;
11  
12  /**
13   *
14   */
15  public class WebDriverLink<P extends Page>
16  {
17      @Inject
18      private AtlassianWebDriver webDriver;
19  
20      @Inject
21      private PageBinder pageBinder;
22  
23      private final By locator;
24      private final Class<P> pageObjectClass;
25  
26      public WebDriverLink(By locator, Class<P> pageObjectClass)
27      {
28          this.locator = locator;
29          this.pageObjectClass = pageObjectClass;
30      }
31  
32      public P activate()
33      {
34          return activate(webDriver);
35      }
36  
37      public P activate(SearchContext context)
38      {
39          if (webDriver.elementExistsAt(locator, context))
40          {
41              context.findElement(locator).click();
42  
43              return pageBinder.bind(pageObjectClass);
44          }
45  
46          throw new ElementNotVisibleException("The link could not be activated By(" + locator + ") failed to find element");
47      }
48  }