本文整理匯總了Java中org.openqa.selenium.support.FindBy類的典型用法代碼示例。如果您正苦於以下問題:Java FindBy類的具體用法?Java FindBy怎麽用?Java FindBy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FindBy類屬於org.openqa.selenium.support包,在下文中一共展示了FindBy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFindByAnno
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
private By getFindByAnno(FindBy anno){
log.info(anno);
switch (anno.how()) {
case CLASS_NAME:
return new By.ByClassName(anno.using());
case CSS:
return new By.ByCssSelector(anno.using());
case ID:
return new By.ById(anno.using());
case LINK_TEXT:
return new By.ByLinkText(anno.using());
case NAME:
return new By.ByName(anno.using());
case PARTIAL_LINK_TEXT:
return new By.ByPartialLinkText(anno.using());
case XPATH:
return new By.ByXPath(anno.using());
default :
throw new IllegalArgumentException("Locator not Found : " + anno.how() + " : " + anno.using());
}
}
示例2: isDecoratable
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private boolean isDecoratable(Field field) {
if (!hasAnnotation(field, com.qmetry.qaf.automation.ui.annotations.FindBy.class, FindBy.class,
FindBys.class)) {
return false;
}
if (WebElement.class.isAssignableFrom(field.getType())) {
return true;
}
if (!(List.class.isAssignableFrom(field.getType()))) {
return false;
}
Type genericType = field.getGenericType();
if (!(genericType instanceof ParameterizedType)) {
return false;
}
Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];
return WebElement.class.isAssignableFrom((Class<?>) listType);
}
示例3: findByToBy
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
public static By findByToBy(FindBy locator) {
if (locator == null) return null;
if (!locator.id().isEmpty())
return By.id(locator.id());
if (!locator.className().isEmpty())
return By.className(locator.className());
if (!locator.xpath().isEmpty())
return By.xpath(locator.xpath());
if (!locator.css().isEmpty())
return By.cssSelector(locator.css());
if (!locator.linkText().isEmpty())
return By.linkText(locator.linkText());
if (!locator.name().isEmpty())
return By.name(locator.name());
if (!locator.partialLinkText().isEmpty())
return By.partialLinkText(locator.partialLinkText());
if (!locator.tagName().isEmpty())
return By.tagName(locator.tagName());
return null;
}
示例4: findByToBy
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
public static By findByToBy(FindBy locator) {
if (locator == null) return null;
if (!"".equals(locator.id()))
return By.id(locator.id());
if (!"".equals(locator.className()))
return By.className(locator.className());
if (!"".equals(locator.xpath()))
return By.xpath(locator.xpath());
if (!"".equals(locator.css()))
return By.cssSelector(locator.css());
if (!"".equals(locator.linkText()))
return By.linkText(locator.linkText());
if (!"".equals(locator.name()))
return By.name(locator.name());
if (!"".equals(locator.partialLinkText()))
return By.partialLinkText(locator.partialLinkText());
if (!"".equals(locator.tagName()))
return By.tagName(locator.tagName());
return null;
}
示例5: getFindByLocator
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
public static By getFindByLocator(FindBy locator) {
if (locator == null) return null;
if (!"".equals(locator.id()))
return By.id(locator.id());
if (!"".equals(locator.className()))
return By.className(locator.className());
if (!"".equals(locator.xpath()))
return By.xpath(locator.xpath());
if (!"".equals(locator.css()))
return By.cssSelector(locator.css());
if (!"".equals(locator.linkText()))
return By.linkText(locator.linkText());
if (!"".equals(locator.name()))
return By.name(locator.name());
if (!"".equals(locator.partialLinkText()))
return By.partialLinkText(locator.partialLinkText());
if (!"".equals(locator.tagName()))
return By.tagName(locator.tagName());
return null;
}
示例6: getNewLocator
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
private static By getNewLocator(Field field) {
try {
By byLocator = null;
String locatorGroup = applicationVersion;
if (locatorGroup != null) {
JFindBy jFindBy = field.getAnnotation(JFindBy.class);
if (jFindBy != null && locatorGroup.equals(jFindBy.group()))
byLocator = getFindByLocator(jFindBy);
}
return (byLocator != null)
? byLocator
: getFindByLocator(field.getAnnotation(FindBy.class));
} catch (Exception | AssertionError ex) {
throw exception(format("Error in get locator for type '%s'", field.getType().getName()) +
LineBreak + ex.getMessage());
}
}
示例7: getNewLocator
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
private static By getNewLocator(Field field) {
try {
By byLocator = null;
String locatorGroup = APP_VERSION;
if (locatorGroup != null) {
JFindBy jFindBy = field.getAnnotation(JFindBy.class);
if (jFindBy != null && locatorGroup.equals(jFindBy.group()))
byLocator = WebAnnotationsUtil.getFindByLocator(jFindBy);
}
return (byLocator != null)
? byLocator
: WebAnnotationsUtil.getFindByLocator(field.getAnnotation(FindBy.class));
} catch (Exception ex) {
throw exception("Error in get locator for type '%s'", field.getType().getName() +
LINE_BREAK + ex.getMessage());
}
}
示例8: ExtendedElementLocator
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
/**
* Creates a new element locator.
*
* @param searchContext
* The context to use when finding the element
* @param field
* The field on the Page Object that will hold the located value
*/
public ExtendedElementLocator(SearchContext searchContext, Field field)
{
this.searchContext = searchContext;
if (field.isAnnotationPresent(FindBy.class))
{
LocalizedAnnotations annotations = new LocalizedAnnotations(field);
this.shouldCache = annotations.isLookupCached();
this.by = annotations.buildBy();
}
// Elements to be recognized by Alice
if (field.isAnnotationPresent(FindByAI.class))
{
this.aiCaption = field.getAnnotation(FindByAI.class).caption();
this.aiLabel = field.getAnnotation(FindByAI.class).label();
}
this.isPredicate = false;
if (field.isAnnotationPresent(Predicate.class))
{
this.isPredicate = field.getAnnotation(Predicate.class).enabled();
}
}
示例9: isDecoratableList
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
private boolean isDecoratableList(Field field, Class<?> type) {
if (!List.class.isAssignableFrom(field.getType())) {
return false;
}
Class<?> listType = getListGenericType(field);
return listType != null && type.isAssignableFrom(listType)
&& (field.getAnnotation(FindBy.class) != null || field.getAnnotation(FindBys.class) != null);
}
示例10: processLoadableContextForClass
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
private void processLoadableContextForClass(Class clazz, ConditionHierarchyNode parent,
Object injectee) {
List<Field> declaredFields = Arrays.asList(clazz.getDeclaredFields());
List<Field> applicableFields = declaredFields.stream()
.filter(f -> (f.isAnnotationPresent(Inject.class))
|| (f.isAnnotationPresent(FindBy.class) && !f.getType().equals(WebElement.class)))
.filter(f -> f.getType().isAnnotationPresent(PageObject.class))
.collect(Collectors.toList());
applicableFields.forEach(field -> {
field.setAccessible(true);
Object subjectInstance = null;
try {
subjectInstance = field.get(injectee);
} catch (IllegalArgumentException | IllegalAccessException ex) {
LOG.error(ex.getMessage(), ex);
}
ConditionHierarchyNode node = addChild(parent, new ClassFieldContext(subjectInstance,
LoadableComponentsUtil.getConditionsFormField(field)));
String className = node.getLoadableFieldContext().getSubjectClass().getCanonicalName();
if (node.equals(findFirstOccurrence(node))) {
LOG.debug("Building loadable components hierarchy tree for {}", className);
processLoadableContextForClass(field.getType(), node, subjectInstance);
} else {
LOG.debug("Loadable components hierarchy tree for {} has already been built, skipping.",
className);
}
});
}
示例11: assertValidAnnotations
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
@Override protected void assertValidAnnotations() {
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
AndroidFindBy androidBy = annotatedElement.getAnnotation(AndroidFindBy.class);
AndroidFindBys androidBys = annotatedElement.getAnnotation(AndroidFindBys.class);
checkDisallowedAnnotationPairs(androidBy, androidBys);
AndroidFindAll androidFindAll = annotatedElement.getAnnotation(AndroidFindAll.class);
checkDisallowedAnnotationPairs(androidBy, androidFindAll);
checkDisallowedAnnotationPairs(androidBys, androidFindAll);
SelendroidFindBy selendroidBy = annotatedElement.getAnnotation(SelendroidFindBy.class);
SelendroidFindBys selendroidBys = annotatedElement.getAnnotation(SelendroidFindBys.class);
checkDisallowedAnnotationPairs(selendroidBy, selendroidBys);
SelendroidFindAll selendroidFindAll =
annotatedElement.getAnnotation(SelendroidFindAll.class);
checkDisallowedAnnotationPairs(selendroidBy, selendroidFindAll);
checkDisallowedAnnotationPairs(selendroidBys, selendroidFindAll);
iOSFindBy iOSBy = annotatedElement.getAnnotation(iOSFindBy.class);
iOSFindBys iOSBys = annotatedElement.getAnnotation(iOSFindBys.class);
checkDisallowedAnnotationPairs(iOSBy, iOSBys);
iOSFindAll iOSFindAll = annotatedElement.getAnnotation(iOSFindAll.class);
checkDisallowedAnnotationPairs(iOSBy, iOSFindAll);
checkDisallowedAnnotationPairs(iOSBys, iOSFindAll);
FindBy findBy = annotatedElement.getAnnotation(FindBy.class);
FindBys findBys = annotatedElement.getAnnotation(FindBys.class);
checkDisallowedAnnotationPairs(findBy, findBys);
FindAll findAll = annotatedElement.getAnnotation(FindAll.class);
checkDisallowedAnnotationPairs(findBy, findAll);
checkDisallowedAnnotationPairs(findBys, findAll);
}
示例12: buildDefaultBy
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
@Override protected By buildDefaultBy() {
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
By defaultBy = null;
FindBy findBy = annotatedElement.getAnnotation(FindBy.class);
if (findBy != null) {
defaultBy = super.buildByFromFindBy(findBy);
}
if (defaultBy == null) {
FindBys findBys = annotatedElement.getAnnotation(FindBys.class);
if (findBys != null) {
defaultBy = super.buildByFromFindBys(findBys);
}
}
if (defaultBy == null) {
FindAll findAll = annotatedElement.getAnnotation(FindAll.class);
if (findAll != null) {
defaultBy = super.buildBysFromFindByOneOf(findAll);
}
}
return defaultBy;
}
示例13: getElemetLocator
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
protected By getElemetLocator(Object obj,String element) throws SecurityException,NoSuchFieldException {
Class childClass = obj.getClass();
By locator = null;
try {
locator = getFindByAnno(childClass.
getDeclaredField(element).
getAnnotation(FindBy.class));
} catch (SecurityException | NoSuchFieldException e) {
log.equals(e);
throw e;
}
log.debug(locator);
return locator;
}
示例14: findByToBy
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
private By findByToBy(FindBy locator) {
if (locator == null)
return null;
if (!"".equals(locator.className()))
return By.className(locator.className());
if (!"".equals(locator.name()))
return By.name(locator.name());
if (!"".equals(locator.id()))
return By.id(locator.id());
if (!"".equals(locator.xpath()))
return By.xpath(locator.xpath());
return null;
}
示例15: getNewLocatorFromField
import org.openqa.selenium.support.FindBy; //導入依賴的package包/類
protected By getNewLocatorFromField(Field field) {
By byLocator = null;
if (group == null)
return findByToBy(field.getAnnotation(FindBy.class));
JFindBy jFindBy = field.getAnnotation(JFindBy.class);
if (jFindBy != null && group.equals(jFindBy.group()))
byLocator = AppiumAnnotationsUtil.getFindByLocator(jFindBy);
return byLocator != null
? byLocator
: findByToBy(field.getAnnotation(FindBy.class));
}