Search in sources :

Example 6 with Element

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;
}
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 7 with Element

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;
}
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 8 with Element

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;
}
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 9 with Element

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);
    }
}
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) InvocationTargetException(java.lang.reflect.InvocationTargetException) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 10 with Element

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;
}
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