use of com.seleniumtests.customexception.ScenarioException 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;
}
use of com.seleniumtests.customexception.ScenarioException 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()));
}
}
use of com.seleniumtests.customexception.ScenarioException 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;
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class PageObject method assertForNonEmptyValue.
@GenericStep
public <T extends PageObject> T assertForNonEmptyValue(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).getValue().isEmpty(), String.format("Element %s is empty", fieldName));
} else {
throw new ScenarioException(String.format(ELEMENT_S_IS_NOT_AN_HTML_ELEMENT_SUBCLASS, fieldName));
}
return (T) this;
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class PageObject method assertForEmptyValue.
@GenericStep
public <T extends PageObject> T assertForEmptyValue(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).getValue().isEmpty(), String.format("Value or Element %s is not empty", fieldName));
} else {
throw new ScenarioException(String.format(ELEMENT_S_IS_NOT_AN_HTML_ELEMENT_SUBCLASS, fieldName));
}
return (T) this;
}
Aggregations