Java 类org.openqa.selenium.support.pagefactory.ElementLocatorFactory 实例源码

项目:bobcat    文件:SelectorPageObjectProvider.java   
/**
 * This method produces value for the field. It constructs the context for the creation out of
 * paren't context and the field's own frame info.
 */
@Override
public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) {
  By selector = PageObjectProviderHelper.getSelectorFromPageObject(field);
  ElementLocatorFactory elementLocatorFactory =
      new NestedSelectorScopedLocatorFactory(webDriver, selector,
          context.getElementLocatorFactory(), AnnotationsHelper.isGlobal(field));
  final FramePath framePath = frameMap.get(pageObject);
  contextStack.push(new PageObjectContext(elementLocatorFactory, framePath));
  Object scopedPageObject = null;
  try {
    scopedPageObject = injector.getInstance(field.getType());
  } catch (Exception e) {
    if (e instanceof ConfigurationException) {
      ConfigurationException ce = (ConfigurationException) e;
      throw new BobcatRuntimeException(
          "Configuration exception: " + ce.getErrorMessages().toString(), e);
    }
    throw new BobcatRuntimeException(e.getMessage(), e);
  } finally {
    contextStack.pop();
  }
  return Optional.ofNullable(scopedPageObject);
}
项目:bobcat    文件:ScopedPageObjectProvider.java   
/**
 * This method produces value for the field. It constructs the context for the creation out of
 * parent's context and the field's own frame info.
 */
@Override
public Optional<Object> provideValue(Object pageObject, Field field, PageObjectContext context) {
  final ElementLocatorFactory elementLocatorFactory = new ScopedElementLocatorFactory(webDriver,
      context.getElementLocatorFactory(), field);
  final FramePath framePath = frameMap.get(pageObject);
  contextStack.push(new PageObjectContext(elementLocatorFactory, framePath));
  Object scopedPageObject = null;
  try {
    scopedPageObject = injector.getInstance(field.getType());
  } catch (Exception e) {
    if (e instanceof ConfigurationException) {
      ConfigurationException ce = (ConfigurationException) e;
      throw new BobcatRuntimeException(
          "Configuration exception: " + ce.getErrorMessages().toString(), e);
    }
    throw new BobcatRuntimeException(e.getMessage(), e);
  } finally {
    contextStack.pop();
  }
  return Optional.ofNullable(scopedPageObject);
}
项目:bobcat    文件:PageObjectInjector.java   
/**
 * This method creates the object of type clazz within context defined by the top web element and the
 * frame path provided as the parameter.
 *
 * @param clazz     PageObject class.
 * @param framePath instance of FramePath.
 * @param <T>       type of PageObject class that will be returned.
 * @return instance of Injector.
 */
public <T> T inject(Class<T> clazz, FramePath framePath) {
  final ElementLocatorFactory elementLocatorFactory = new DefaultElementLocatorFactory(webDriver);
  stack.push(new PageObjectContext(elementLocatorFactory, framePath));
  try {
    return injector.getInstance(clazz);
  } finally {
    stack.pop();
  }
}
项目:bobcat    文件:PageObjectInjector.java   
/**
 * This method creates the object of type clazz within context defined by the "scope" WebElement parameter
 * and frame path provided as the parameter.
 *
 * @param clazz     PageObject class.
 * @param scope     WebElement for scope definition.
 * @param framePath instance of FramePath.
 * @param <T>       type of PageObject class that will be returned.
 * @return instance of Injector.
 */
public <T> T inject(Class<T> clazz, WebElement scope, FramePath framePath) {
  final ElementLocatorFactory elementLocatorFactory =
      new WebElementScopedLocatorFactory(webDriver, scope);
  stack.push(new PageObjectContext(elementLocatorFactory, framePath));
  try {
    return injector.getInstance(clazz);
  } finally {
    stack.pop();
  }
}
项目:bobcat    文件:CurrentScopeListProvider.java   
@SuppressWarnings("unchecked")
private List<WebElement> retrieveListFromFactory(ElementLocatorFactory factory) {
  InvocationHandler handler = new LocatingElementListHandler(
      ((ScopedElementLocatorFactory) factory).getCurrentScope());
  return (List<WebElement>) Proxy
      .newProxyInstance(WebElement.class.getClassLoader(), new Class[] {List.class}, handler);
}
项目:bobcat    文件:NestedSelectorScopedLocatorFactory.java   
/**
 * Creates a selector-scoped locator factory with scope within parent scope.
 *
 * @param searchContext Initial search context
 * @param selector Scope of the created locator
 * @param parentFactory Factory that represents scope for elements
 */
public NestedSelectorScopedLocatorFactory(SearchContext searchContext, By selector,
    ElementLocatorFactory parentFactory, boolean globalCurrenScope) {
  this.searchContext = searchContext;
  this.selector = selector;
  this.parentFactory = parentFactory;
  this.globalCurrenScope = globalCurrenScope;
}
项目:bobcat    文件:PageObjectSelectorListProxyProvider.java   
private SearchContext getSearchContext(PageObjectContext context, Field field) {
  SearchContext searchContext = webDriver;
  ElementLocatorFactory elementLocatorFactory = context.getElementLocatorFactory();
  if (elementLocatorFactory instanceof ParentElementLocatorProvider
    && !AnnotationsHelper.isGlobal(field)) {
    searchContext = acquireSearchContext(elementLocatorFactory);
  }
  return searchContext;
}
项目:bobcat    文件:PageObjectSelectorListProxyProvider.java   
private SearchContext acquireSearchContext(ElementLocatorFactory elementLocatorFactory) {
  SearchContext searchContext;
  ElementLocator parentElementLocator = ((ParentElementLocatorProvider) elementLocatorFactory).
    getCurrentScope();
  if (parentElementLocator instanceof SearchContextAwareLocator) {
    searchContext = ((SearchContextAwareLocator) parentElementLocator).getSearchContext();
  } else {
    searchContext = parentElementLocator.findElement();
  }
  return searchContext;
}
项目:bobcat    文件:CurrentScopeListProviderTest.java   
@Test
public void shouldReturnEmptyListWhenFactoryInStackIsNotScoped() {
  //given
  ElementLocatorFactory elementLocatorFactory = mock(ElementLocatorFactory.class);
  when(contextStack.peek()).thenReturn(pageObjectContext);
  when(contextStack.peek().getElementLocatorFactory()).thenReturn(elementLocatorFactory);

  //when
  List<WebElement> actual = testedObject.get();

  //then
  assertThat(actual).isEmpty();
}
项目:bobcat    文件:AemDialogFieldResolver.java   
/**
 * Searches for the field of a given type, identified by the selector class.
 *
 * @param selector        Locator by which to locate the dialog field.
 * @param dialogFieldType Class that represents dialog field.
 * @param <T> dialog field class
 * @return A dialogFieldType's instance that represents dialog field.
 */
public <T> T getFieldBySelector(By selector, Class<T> dialogFieldType) {
  ElementLocatorFactory fieldScope = new SelectorScopedLocatorFactory(webDriver, selector);
  elementLocatorStack.push(new PageObjectContext(fieldScope, FramePath.parsePath("$cq")));
  try {
    return injector.getInstance(dialogFieldType);
  } finally {
    elementLocatorStack.pop();
  }
}
项目:wiselenium    文件:WiseDecorator.java   
/**
 * Constructor.
 * 
 * @param factory The factory of the elements locator.
 */
public WiseDecorator(ElementLocatorFactory factory) {
    ElementDecoratorChain wiseComponentDecorator = new WiseComponentDecorator(factory);
    ElementDecoratorChain wiseFrameDecorator = new WiseFrameDecorator(factory);
    ElementDecoratorChain webElementDecorator = new WebElementDecorator(factory);
    ElementDecoratorChain nullDecorator = new NullDecorator(factory);

    wiseComponentDecorator.setNext(wiseFrameDecorator);
    wiseFrameDecorator.setNext(webElementDecorator);
    webElementDecorator.setNext(nullDecorator);

    this.elementDecorator = wiseComponentDecorator;
}
项目:wiselenium    文件:WiseElementListProxy.java   
@SuppressWarnings("unchecked")
public static <E> List<E> getInstance(Class<E> clazz, List<WebElement> webElements,
        ElementLocatorFactory factory) {
    Enhancer e = new Enhancer();
    e.setInterfaces(new Class[] { List.class });
    e.setCallback(new WiseElementListProxy<E>(clazz, webElements, factory));
    return (List<E>) e.create();
}
项目:bobcat    文件:PageObjectContext.java   
/**
 * @return Element locator factory that is stored in the context.
 */
public ElementLocatorFactory getElementLocatorFactory() {
  return elementLocatorFactory;
}
项目:bobcat    文件:CurrentScopeListProvider.java   
private List<WebElement> getScopedList() {
  ElementLocatorFactory factory = stack.peek().getElementLocatorFactory();
  return factory instanceof ScopedElementLocatorFactory ?
      retrieveListFromFactory(factory) :
      Collections.emptyList();
}
项目:bobcat    文件:CurrentWebElementProvider.java   
private WebElement getScopedWebElement() {
  ElementLocatorFactory factory = stack.peek().getElementLocatorFactory();
  return (factory instanceof ParentElementLocatorProvider) ?
      getWebElementFromFactory(factory) :
      getTopElement();
}
项目:bobcat    文件:CurrentWebElementProvider.java   
private WebElement getWebElementFromFactory(ElementLocatorFactory factory) {
  InvocationHandler handler = new LocatingElementHandler(
      ((ParentElementLocatorProvider) factory).getCurrentScope());
  return (WebElement) Proxy.newProxyInstance(WebElement.class.getClassLoader(),
      new Class[] {WebElement.class, WrapsElement.class, Locatable.class}, handler);
}
项目:bobcat    文件:ContextStack.java   
private PageObjectContext getDefaultPageObjectContext(WebDriver webDriver) {
  ElementLocatorFactory elementLocatorFactory = new DefaultElementLocatorFactory(webDriver);
  FramePath framePath = new FramePath();
  return new PageObjectContext(elementLocatorFactory, framePath);
}
项目:jpagefactory    文件:JPageFactoryFieldDecorator.java   
public JPageFactoryFieldDecorator(ElementLocatorFactory factory) {
    super(factory);
}
项目:wiselenium    文件:NullDecorator.java   
public NullDecorator(ElementLocatorFactory factory) {
    super(factory);
}
项目:wiselenium    文件:WiseFrameDecorator.java   
public WiseFrameDecorator(ElementLocatorFactory factory) {
    super(factory);
}
项目:wiselenium    文件:WiseElementListProxy.java   
private WiseElementListProxy(Class<E> clazz, List<WebElement> webElements,
        ElementLocatorFactory factory) {
    this.clazz = clazz;
    this.webElements = webElements;
    this.locatorFactory = factory;
}
项目:wiselenium    文件:ElementDecoratorChainTemplate.java   
public ElementDecoratorChainTemplate(ElementLocatorFactory factory) {
    super(factory);
}
项目:wiselenium    文件:WiseComponentDecorator.java   
public WiseComponentDecorator(ElementLocatorFactory factory) {
    super(factory);
}
项目:wiselenium    文件:WebElementDecorator.java   
public WebElementDecorator(ElementLocatorFactory factory) {
    super(factory);
}
项目:carina    文件:ExtendedFieldDecorator.java   
public ExtendedFieldDecorator(ElementLocatorFactory factory, WebDriver webDriver)
{
    this.factory = factory;
    this.webDriver = webDriver;
}
项目:bobcat    文件:NestedSelectorScopedElementLocator.java   
/**
 * Constructs NestedSelectorScopedElementLocator.
 *
 * @param searchContext instance of SearchContext
 * @param scopeFactory instance of ElementLocatorFactory
 * @param selector selector
 * @param globalCurrentScope indicates if field is in global scope
 */
public NestedSelectorScopedElementLocator(SearchContext searchContext,
    ElementLocatorFactory scopeFactory, By selector, boolean globalCurrentScope) {
  this.scopeFactory = scopeFactory;
  this.selector = selector;
  this.searchContext = searchContext;
  this.globalCurrentScope = globalCurrentScope;
}
项目:bobcat    文件:ScopedElementLocator.java   
/**
 * Constructs ScopedElementLocator.
 *
 * @param scopeFactory instance of ElementLocatorFactory
 * @param scopeField field for scope definition
 * @param searchField class field
 */
public ScopedElementLocator(ElementLocatorFactory scopeFactory,
    Field scopeField, Field searchField) {
  this.scopeFactory = scopeFactory;
  this.scopeField = scopeField;
  this.searchField = searchField;
}
项目:bobcat    文件:ScopedElementLocatorFactory.java   
/**
 * Creates an element-scoped locator factory.
 *
 * @param webDriver     WebDriver instance that will serve as a global scope
 *                      for Global-annotated fields
 * @param parentFactory Factory that represents scope for elements without Global annotation
 * @param parentField   Field that contains current field,
 *                      reducing the scope indicated by parentFactory
 */
public ScopedElementLocatorFactory(WebDriver webDriver,
    ElementLocatorFactory parentFactory, Field parentField) {
  this.parentFactory = parentFactory;
  this.parentField = parentField;
  this.webDriver = webDriver;
}
项目:bobcat    文件:PageObjectContext.java   
/**
 * Constructs PageObjectContext. Initializes its fields.
 *
 * @param elementLocatorFactory ElementLocatorFactory instance.
 * @param framePath             FramePath instance.
 */
public PageObjectContext(ElementLocatorFactory elementLocatorFactory, FramePath framePath) {
  this.elementLocatorFactory = elementLocatorFactory;
  this.framePath = framePath;
}
项目:bobcat    文件:GuiceAwareFieldDecorator.java   
/**
 * Constructor. Initializes decorator with the element locator factory that will be used for
 * producing
 * values for decorated fields.
 *
 * @param factory                 represents ElementLocatorFactory
 * @param bobcatWebElementFactory instance of BobcatWebElementFactory
 */
public GuiceAwareFieldDecorator(ElementLocatorFactory factory,
    BobcatWebElementFactory bobcatWebElementFactory) {
  super(factory);
  this.bobcatWebElementFactory = bobcatWebElementFactory;
}