Search in sources :

Example 1 with ISelectList

use of com.seleniumtests.uipage.htmlelements.select.ISelectList in project seleniumRobot by bhecquet.

the class SelectList method searchRelevantImplementation.

private static List<Class<? extends ISelectList>> searchRelevantImplementation() {
    List<Class<? extends ISelectList>> selectImplementations = new ArrayList<>();
    // load via SPI other Select implementations
    ServiceLoader<ISelectList> selectLoader = ServiceLoader.load(ISelectList.class);
    Iterator<ISelectList> selectsIterator = selectLoader.iterator();
    while (selectsIterator.hasNext()) {
        ISelectList selectClass = selectsIterator.next();
        selectImplementations.add(selectClass.getClass());
    }
    if (selectImplementations.isEmpty()) {
        throw new CustomSeleniumTestsException("Could not get list of Select classes");
    }
    return selectImplementations;
}
Also used : ISelectList(com.seleniumtests.uipage.htmlelements.select.ISelectList) CustomSeleniumTestsException(com.seleniumtests.customexception.CustomSeleniumTestsException) ArrayList(java.util.ArrayList)

Example 2 with ISelectList

use of com.seleniumtests.uipage.htmlelements.select.ISelectList in project seleniumRobot by bhecquet.

the class SelectList method findElement.

@Override
protected void findElement() {
    // set a default type so that use of selectImplementation can be done
    selectImplementation = new StubSelect();
    super.findElement(true);
    // if we have a prefered implementation, use it
    // search the right select list handler
    implementationList = orderImplementations(getPreferedUiLibraries());
    for (Class<? extends ISelectList> selectClass : implementationList) {
        try {
            ISelectList selectInstance = selectClass.getConstructor(WebElement.class, FrameElement.class).newInstance(getRealElementNoSearch(), frameElement);
            if (selectInstance.isApplicable()) {
                selectImplementation = selectInstance;
                selectInstance.setDriver(getDriver());
                break;
            }
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
            logger.error(String.format("Cannot use Select implementation %s: %s", selectClass.getName(), e.getMessage()));
        }
    }
    if (selectImplementation instanceof StubSelect) {
        throw new ScenarioException("Cannot find type of select " + getRealElementNoSearch().getTagName());
    }
    options = selectImplementation.getOptions();
    multiple = selectImplementation.isMultipleWithoutFind();
}
Also used : StubSelect(com.seleniumtests.uipage.htmlelements.select.StubSelect) WebElement(org.openqa.selenium.WebElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISelectList(com.seleniumtests.uipage.htmlelements.select.ISelectList) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Aggregations

ISelectList (com.seleniumtests.uipage.htmlelements.select.ISelectList)2 CustomSeleniumTestsException (com.seleniumtests.customexception.CustomSeleniumTestsException)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 StubSelect (com.seleniumtests.uipage.htmlelements.select.StubSelect)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 WebElement (org.openqa.selenium.WebElement)1