1   package com.atlassian.pageobjects.elements.test.pageobjects;
2   
3   import com.atlassian.pageobjects.Defaults;
4   import com.atlassian.pageobjects.Page;
5   import com.atlassian.pageobjects.PageBinder;
6   import com.atlassian.pageobjects.ProductInstance;
7   import com.atlassian.pageobjects.TestedProduct;
8   import com.atlassian.pageobjects.TestedProductFactory;
9   import com.atlassian.pageobjects.binder.InjectPageBinder;
10  import com.atlassian.pageobjects.binder.StandardModule;
11  import com.atlassian.pageobjects.elements.ElementModule;
12  import com.atlassian.pageobjects.elements.PageElement;
13  import com.atlassian.pageobjects.elements.WebDriverElement;
14  import com.atlassian.pageobjects.elements.timeout.Timeouts;
15  import com.atlassian.pageobjects.elements.timeout.TimeoutsModule;
16  import com.atlassian.webdriver.AtlassianWebDriverModule;
17  import com.atlassian.webdriver.pageobjects.DefaultWebDriverTester;
18  import com.atlassian.webdriver.pageobjects.WebDriverTester;
19  import org.openqa.selenium.By;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  @Defaults(instanceId = "testapp", contextPath = "/", httpPort = 5990)
24  public class SampleTestedProduct  implements TestedProduct<WebDriverTester>
25  {
26      private final PageBinder pageBinder;
27      private final WebDriverTester  webDriverTester;
28      private final ProductInstance productInstance;
29      private final Timeouts timeouts;
30  
31      public SampleTestedProduct(TestedProductFactory.TesterFactory<WebDriverTester> testerFactory, ProductInstance productInstance)
32      {
33          checkNotNull(productInstance);
34          this.productInstance = productInstance;
35          this.webDriverTester =  new DefaultWebDriverTester();
36          TimeoutsModule timeoutsModule =  new TimeoutsModule();
37          this.timeouts = timeoutsModule.timeouts();
38          this.pageBinder = new InjectPageBinder(productInstance, webDriverTester, new StandardModule(this),
39                  new AtlassianWebDriverModule(this), new ElementModule(), new TimeoutsModule());
40      }
41  
42      public Timeouts timeouts()
43      {
44          return timeouts;
45      }
46  
47      public PageElement find(final By by)
48      {
49          return getPageBinder().bind(WebDriverElement.class, by);
50      }
51  
52      public <P extends Page> P visit(Class<P> pageClass, Object... args)
53      {
54          return pageBinder.navigateToAndBind(pageClass, args);
55      }
56  
57      public PageBinder getPageBinder()
58      {
59          return pageBinder;
60      }
61  
62      public ProductInstance getProductInstance()
63      {
64          return productInstance;
65      }
66  
67      public WebDriverTester getTester()
68      {
69          return webDriverTester;
70      }
71  }