use of com.seleniumtests.uipage.htmlelements.Element 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.uipage.htmlelements.Element 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;
}
use of com.seleniumtests.uipage.htmlelements.Element in project seleniumRobot by bhecquet.
the class PageObject method sendRandomKeysToField.
@GenericStep
public <T extends PageObject> T sendRandomKeysToField(Integer charNumber, String fieldName) {
Element element = getElement(fieldName);
element.sendKeys(RandomStringUtils.random(charNumber, true, false));
return (T) this;
}
use of com.seleniumtests.uipage.htmlelements.Element in project seleniumRobot by bhecquet.
the class PageObject method clickAndChangeToPage.
/**
* Click on element and creates a new PageObject of the type of following page
* @param fieldName
* @param nextPage Class of the next page
* @return
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
*/
@GenericStep
public <T extends PageObject> T clickAndChangeToPage(String fieldName, Class<T> nextPage) {
Element element = getElement(fieldName);
element.click();
try {
return nextPage.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new ScenarioException(String.format("Cannot switch to next page %s, maybe default constructor does not exist", nextPage.getSimpleName()), e);
}
}
use of com.seleniumtests.uipage.htmlelements.Element 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;
}
Aggregations