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