Search in sources :

Example 21 with HtmlElement

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

the class TestHtmlElement method testElementNotFoundWithIndex.

/**
 * issue #325: check NoSuchElementException exception is raised with index 0
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testElementNotFoundWithIndex() throws Exception {
    HtmlElement elNotPresent3 = new HtmlElement("element", By.id("notPresent"), 1, 3);
    when(driver.findElement(By.id("notPresent"))).thenThrow(new NoSuchElementException("Unable to locate element with ID: 'notPresent'"));
    when(driver.findElements(By.id("notPresent"))).thenThrow(new NoSuchElementException("Unable to locate element with ID: 'notPresent'"));
    try {
        elNotPresent3.getValue();
        throw new Exception("we should not be there");
    } catch (NoSuchElementException e) {
    // we expect not to have an IndexOutOfBoundsException
    }
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) ScenarioException(com.seleniumtests.customexception.ScenarioException) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with HtmlElement

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

the class PageObject method assertForMatchingValue.

@GenericStep
public <T extends PageObject> T assertForMatchingValue(String fieldName, String regex) {
    Element element = getElement(fieldName);
    if (element instanceof HtmlElement) {
        Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        Assert.assertTrue(Pattern.compile(regex).matcher(((HtmlElement) element).getText()).find() || Pattern.compile(regex).matcher(((HtmlElement) element).getValue()).find(), String.format("Value of Element %s does not match %s ", fieldName, regex));
    } else {
        throw new ScenarioException(String.format(ELEMENT_S_IS_NOT_AN_HTML_ELEMENT_SUBCLASS, fieldName));
    }
    return (T) this;
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) 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) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 23 with HtmlElement

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

the class PageObject method assertNotChecked.

@GenericStep
public <T extends PageObject> T assertNotChecked(String fieldName) {
    Element element = getElement(fieldName);
    if (element instanceof CheckBoxElement || element instanceof RadioButtonElement) {
        Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        Assert.assertFalse(((HtmlElement) element).isSelected(), String.format("Element %s is checked", fieldName));
    } else {
        throw new ScenarioException(String.format("Element %s is not an CheckBoxElement/RadioButtonElement", fieldName));
    }
    return (T) this;
}
Also used : 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) RadioButtonElement(com.seleniumtests.uipage.htmlelements.RadioButtonElement) CheckBoxElement(com.seleniumtests.uipage.htmlelements.CheckBoxElement) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 24 with HtmlElement

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

the class PageObject method assertForVisible.

@GenericStep
public <T extends PageObject> T assertForVisible(String fieldName) {
    Element element = getElement(fieldName);
    if (element instanceof HtmlElement) {
        Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        Assert.assertTrue(((HtmlElement) element).isDisplayed(), String.format("Element %s is not visible", fieldName));
    } else {
        Assert.assertTrue(((GenericPictureElement) element).isElementPresent(), String.format("Element %s is not visible", fieldName));
    }
    return (T) this;
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) 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)

Example 25 with HtmlElement

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

the class PageObject method assertChecked.

@GenericStep
public <T extends PageObject> T assertChecked(String fieldName) {
    Element element = getElement(fieldName);
    if (element instanceof CheckBoxElement || element instanceof RadioButtonElement) {
        Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        Assert.assertTrue(((HtmlElement) element).isSelected(), String.format("Element %s is unchecked", fieldName));
    } else {
        throw new ScenarioException(String.format("Element %s is not an CheckBoxElement/RadioButtonElement", fieldName));
    }
    return (T) this;
}
Also used : 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) RadioButtonElement(com.seleniumtests.uipage.htmlelements.RadioButtonElement) CheckBoxElement(com.seleniumtests.uipage.htmlelements.CheckBoxElement) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Aggregations

HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)50 WebElement (org.openqa.selenium.WebElement)24 Test (org.testng.annotations.Test)23 MockitoTest (com.seleniumtests.MockitoTest)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)12 ScenarioException (com.seleniumtests.customexception.ScenarioException)10 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)10 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)9 Element (com.seleniumtests.uipage.htmlelements.Element)9 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)9 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)9 TimeoutException (org.openqa.selenium.TimeoutException)9 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)8 LocalDateTime (java.time.LocalDateTime)8 NoSuchElementException (org.openqa.selenium.NoSuchElementException)8 Date (java.util.Date)5 WebDriverException (org.openqa.selenium.WebDriverException)5 Field (java.lang.reflect.Field)4 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)3