com.atlassian.pageobjects.binder
Class InjectPageBinder

java.lang.Object
  extended by com.atlassian.pageobjects.binder.InjectPageBinder
All Implemented Interfaces:
ConfigurableInjectionContext, InjectionContext, PageBinder

@NotThreadSafe
@Internal
public final class InjectPageBinder
extends Object
implements PageBinder, ConfigurableInjectionContext

Page navigator that builds page objects from classes, then injects them with dependencies and calls lifecycle methods.

The construction process is as follows:

  1. Determine the actual class by checking for an override
  2. Instantiate the class using a constructor that matches the passed arguments
  3. Changes the tester to the corrent URL (if navigateToAndBind(Class, Object...))
  4. Inject all fields annotated with Inject, including private
  5. Execute the supplied PostInjectionProcessor
  6. Call all methods annotated with WaitUntil
  7. Call all methods annotated with ValidateState
  8. Call all methods annotated with Init

When going to a page via the navigateToAndBind(Class, Object...) method, the page's URL is retrieved and navigated to via Tester.gotoUrl(String) after construction and initializing but before WaitUntil methods are called.

This class also implements a mutable variant of ConfigurableInjectionContext, where injection configuration changes are applied in-place, by creating a new Guice injector.


Constructor Summary
InjectPageBinder(ProductInstance productInstance, Tester tester, com.google.inject.Module... modules)
           
 
Method Summary
<P> P
bind(Class<P> pageClass, Object... args)
          Builds and binds the page object to the page.
 InjectionConfiguration configure()
          Get an injection configuration object that may be used to add/override objects in this injection context.
<P> DelayedBinder<P>
delayedBind(Class<P> pageClass, Object... args)
          Creates a delayed binder that gives the caller full control over the lifecycle of the page object.
<T> T
getInstance(Class<T> type)
          Get an instance of given type from context.
 void injectMembers(Object targetInstance)
          Execute injection of fields on given targetInstance
 com.google.inject.Injector injector()
          Deprecated. take advantage of InjectionContext API instead. Scheduled for removal in 3.0
 void injectStatic(Class<?> targetClass)
          Execute injection of static fields on given targetClass.
<P extends Page>
P
navigateToAndBind(Class<P> pageClass, Object... args)
          Constructs the page object, changes the browser URL to the desired page URL, then binds the object to the page.
<P> void
override(Class<P> oldClass, Class<? extends P> newClass)
          Overrides a page object
protected  void visitUrl(Page p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InjectPageBinder

public InjectPageBinder(ProductInstance productInstance,
                        Tester tester,
                        com.google.inject.Module... modules)
Method Detail

injector

public com.google.inject.Injector injector()
Deprecated. take advantage of InjectionContext API instead. Scheduled for removal in 3.0

Injector used by this binder.

Returns:
injector used by this binder.

navigateToAndBind

public <P extends Page> P navigateToAndBind(Class<P> pageClass,
                                            Object... args)
Description copied from interface: PageBinder
Constructs the page object, changes the browser URL to the desired page URL, then binds the object to the page.

Specified by:
navigateToAndBind in interface PageBinder
Type Parameters:
P - The page type
Parameters:
pageClass - The page class
args - Arguments to pass to the page object constructor.
Returns:
The constructed and fully loaded page with the browser set accordingly

bind

public <P> P bind(Class<P> pageClass,
                  Object... args)
Description copied from interface: PageBinder
Builds and binds the page object to the page.

Specified by:
bind in interface PageBinder
Type Parameters:
P - The page type
Parameters:
pageClass - The page object class
args - Arguments to pass to the page object constructor.
Returns:
The constructed and loaded page object with the browser set accordingly

delayedBind

public <P> DelayedBinder<P> delayedBind(Class<P> pageClass,
                                        Object... args)
Description copied from interface: PageBinder
Creates a delayed binder that gives the caller full control over the lifecycle of the page object. The page object will not even be instantiated until the DelayedBinder methods are called.

Specified by:
delayedBind in interface PageBinder
Type Parameters:
P - The page type
Parameters:
pageClass - The page object class
args - The arguments to pass to the page object constructor
Returns:
A delayed binder instance

visitUrl

protected void visitUrl(Page p)

override

public <P> void override(Class<P> oldClass,
                         Class<? extends P> newClass)
Description copied from interface: PageBinder
Overrides a page object

Specified by:
override in interface PageBinder
Type Parameters:
P - The old class type
Parameters:
oldClass - The old class that would have normally been constructed
newClass - An subclass of the old class to be substituted

getInstance

@Nonnull
public <T> T getInstance(@Nonnull
                                 Class<T> type)
Description copied from interface: InjectionContext
Get an instance of given type from context.

Specified by:
getInstance in interface InjectionContext
Type Parameters:
T - type param
Parameters:
type - type of the requested instance
Returns:
an instance of requested type. An exception may be raised if the context is unable to instantiate given type.

injectStatic

public void injectStatic(@Nonnull
                         Class<?> targetClass)
Description copied from interface: InjectionContext
Execute injection of static fields on given targetClass.

Specified by:
injectStatic in interface InjectionContext
Parameters:
targetClass - class to inject into

injectMembers

public void injectMembers(@Nonnull
                          Object targetInstance)
Description copied from interface: InjectionContext
Execute injection of fields on given targetInstance

Specified by:
injectMembers in interface InjectionContext
Parameters:
targetInstance - instance to inject into

configure

@Nonnull
public InjectionConfiguration configure()
Description copied from interface: ConfigurableInjectionContext
Get an injection configuration object that may be used to add/override objects in this injection context.

Specified by:
configure in interface ConfigurableInjectionContext
Returns:
injection configuration associated with this context
See Also:
InjectionConfiguration


Copyright © 2014 Atlassian. All rights reserved.