Search in sources :

Example 1 with StubSelect

use of com.seleniumtests.uipage.htmlelements.select.StubSelect 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)

Example 2 with StubSelect

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

the class TestSelectList method testFindElementWrongType.

@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testFindElementWrongType() throws IOException {
    when(element.getTagName()).thenReturn("something");
    SelectList select = new SelectList("", By.id("select"));
    List<WebElement> options = select.getOptions();
    Assert.assertTrue(select.getSelectImplementation() instanceof StubSelect);
}
Also used : SelectList(com.seleniumtests.uipage.htmlelements.SelectList) StubSelect(com.seleniumtests.uipage.htmlelements.select.StubSelect) WebElement(org.openqa.selenium.WebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

StubSelect (com.seleniumtests.uipage.htmlelements.select.StubSelect)2 WebElement (org.openqa.selenium.WebElement)2 MockitoTest (com.seleniumtests.MockitoTest)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 SelectList (com.seleniumtests.uipage.htmlelements.SelectList)1 ISelectList (com.seleniumtests.uipage.htmlelements.select.ISelectList)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1