All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hemanthsridhar.builder.CustomAnnotations Maven / Gradle / Ivy

There is a newer version: 3.3.2
Show newest version
package com.github.hemanthsridhar.builder;

import com.github.hemanthsridhar.pagefactory.AbstractCustomFindByBuilder;
import com.github.hemanthsridhar.support.SearchAll;
import com.github.hemanthsridhar.support.SearchBy;
import com.github.hemanthsridhar.support.SearchBys;
import org.openqa.selenium.By;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.pagefactory.AbstractAnnotations;
import org.openqa.selenium.support.pagefactory.Annotations;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * Created by hemanthsridhar on 1/6/19.
 */
public class CustomAnnotations extends AbstractAnnotations {
    private final Field field;

    public CustomAnnotations(Field field) {
        this.field = field;
    }

    @Override
    public By buildBy() {

        SearchBy searchBy = field.getAnnotation(SearchBy.class);
        SearchAll searchAll = field.getAnnotation(SearchAll.class);
        SearchBys searchBys = field.getAnnotation(SearchBys.class);

        if (searchBy != null || searchAll != null || searchBys != null) {
            for (Annotation annotation : field.getDeclaredAnnotations()) {
                AbstractCustomFindByBuilder builder = null;
                try {
                    builder = annotation.annotationType()
                            .getAnnotation(CustomPageFactoryFinder.class).value()
                            .newInstance();
                } catch (InstantiationException | IllegalAccessException e) {
                    e.printStackTrace();
                }
                if (builder != null) {
                    return builder.buildIt(annotation, field);
                }
            }
            return new Annotations(field).buildBy();
        } else {
            return new Annotations(field).buildBy();
        }
    }

    @Override
    public boolean isLookupCached() {
        return (field.getAnnotation(CacheLookup.class) != null);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy