Search in sources :

Example 1 with Element

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

the class PageObject method assertForValue.

@GenericStep
public <T extends PageObject> T assertForValue(String fieldName, String value) {
    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).getText().equals(value) || ((HtmlElement) element).getValue().equals(value), String.format("Value of element %s is not %s", fieldName, value));
    } 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 2 with Element

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

the class PageObject method sendKeysToField.

@GenericStep
public <T extends PageObject> T sendKeysToField(String fieldName, String value) {
    Element element = getElement(fieldName);
    element.sendKeys(value);
    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)

Example 3 with Element

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

the class PageObject method assertForEnabled.

@GenericStep
public <T extends PageObject> T assertForEnabled(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).isEnabled(), String.format("Element %s is disabled", fieldName));
    } 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 4 with Element

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

the class PageObject method getElement.

/**
 * Returns an Element object based on field name
 * @return
 */
private Element getElement(String fieldName) {
    try {
        Field field = getClass().getDeclaredField(fieldName);
        field.setAccessible(true);
        return (Element) field.get(this);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new ScenarioException(String.format("Field %s does not exist in class %s", fieldName, getClass().getSimpleName()));
    }
}
Also used : Field(java.lang.reflect.Field) 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 5 with Element

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

the class PageObject method assertForDisabled.

@GenericStep
public <T extends PageObject> T assertForDisabled(String fieldName) {
    Element element = getElement(fieldName);
    if (element instanceof HtmlElement) {
        Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
        Assert.assertFalse(((HtmlElement) element).isEnabled(), String.format("Element %s is enabled", fieldName));
    } 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)

Aggregations

CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)15 Element (com.seleniumtests.uipage.htmlelements.Element)15 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)15 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)15 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)15 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)15 WebElement (org.openqa.selenium.WebElement)15 ScenarioException (com.seleniumtests.customexception.ScenarioException)11 SelectList (com.seleniumtests.uipage.htmlelements.SelectList)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 WebDriverException (org.openqa.selenium.WebDriverException)1