Search in sources :

Example 21 with SelectList

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

the class PageObject method assertSelectedOption.

@GenericStep
public <T extends PageObject> T assertSelectedOption(String fieldName, String value) {
    Element element = getElement(fieldName);
    if (element instanceof SelectList) {
        try {
            WebElement selectedOption = ((SelectList) element).getFirstSelectedOption();
            Assert.assertNotNull(selectedOption, "No selected option found");
            Assert.assertEquals(selectedOption.getText(), value, "Selected option is not the expected one");
        } catch (WebDriverException e) {
            Assert.assertTrue(false, String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        }
    } else {
        throw new ScenarioException(String.format("Element %s is not an SelectList subclass", fieldName));
    }
    return (T) this;
}
Also used : SelectList(com.seleniumtests.uipage.htmlelements.SelectList) WebElement(org.openqa.selenium.WebElement) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) GenericPictureElement(com.seleniumtests.uipage.htmlelements.GenericPictureElement) RadioButtonElement(com.seleniumtests.uipage.htmlelements.RadioButtonElement) Element(com.seleniumtests.uipage.htmlelements.Element) CheckBoxElement(com.seleniumtests.uipage.htmlelements.CheckBoxElement) LinkElement(com.seleniumtests.uipage.htmlelements.LinkElement) WebElement(org.openqa.selenium.WebElement) ScenarioException(com.seleniumtests.customexception.ScenarioException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 22 with SelectList

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

the class TestFrameElement method testSelectListInsideFrame.

@Test(groups = { "ut" })
public void testSelectListInsideFrame() throws Exception {
    when(element.getTagName()).thenReturn("select");
    FrameElement frame = new FrameElement("", By.id("frameId"));
    SelectList el = new SelectList("", By.id("el"), frame);
    el.getSelectedText();
    verify(locator).frame(any(WebElement.class));
    verify(locator, times(1)).defaultContent();
}
Also used : SelectList(com.seleniumtests.uipage.htmlelements.SelectList) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 23 with SelectList

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

the class TestSelectList method testSelectByValues.

@Test(groups = { "ut" })
public void testSelectByValues() throws IOException {
    when(option1.isSelected()).thenReturn(false);
    when(option2.isSelected()).thenReturn(false);
    when(element.getAttribute("multiple")).thenReturn("true");
    SelectList select = new SelectList("", By.id("select"));
    select.selectByValue("opti1", "opti2");
    verify(option1).click();
    verify(option2).click();
}
Also used : SelectList(com.seleniumtests.uipage.htmlelements.SelectList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 24 with SelectList

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

Example 25 with SelectList

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

the class TestSelectList method testIsMultipleNoAttribute.

@Test(groups = { "ut" })
public void testIsMultipleNoAttribute() throws IOException {
    when(option1.isSelected()).thenReturn(true);
    when(option2.isSelected()).thenReturn(false);
    SelectList select = new SelectList("", By.id("select"));
    Assert.assertFalse(select.isMultiple());
}
Also used : SelectList(com.seleniumtests.uipage.htmlelements.SelectList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

SelectList (com.seleniumtests.uipage.htmlelements.SelectList)35 MockitoTest (com.seleniumtests.MockitoTest)34 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)34 Test (org.testng.annotations.Test)34 WebElement (org.openqa.selenium.WebElement)9 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)1 Element (com.seleniumtests.uipage.htmlelements.Element)1 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)1 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)1 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)1 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)1 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)1 NativeSelect (com.seleniumtests.uipage.htmlelements.select.NativeSelect)1 StubSelect (com.seleniumtests.uipage.htmlelements.select.StubSelect)1 NoSuchElementException (org.openqa.selenium.NoSuchElementException)1 WebDriverException (org.openqa.selenium.WebDriverException)1