use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class PageManager method changeUrlByTitle.
/**
* Redirect to WebElementsPage by WebElementsPage Entry url value
*
* @param packageName a {@link java.lang.String} object.
* @param title a {@link java.lang.String} object.
* @return a WebElementsPage object.
* @throws ru.sbtqa.tag.pagefactory.exceptions.PageInitializationException
* TODO
*/
public static Page changeUrlByTitle(String packageName, String title) throws PageInitializationException {
Class<?> pageClass = getPageClass(packageName, title);
if (pageClass == null) {
return null;
}
Annotation annotation = pageClass.getAnnotation(PageEntry.class);
if (annotation != null && !((PageEntry) annotation).url().isEmpty()) {
if (PageFactory.getWebDriver().getCurrentUrl() == null) {
throw new AutotestError("Current URL is null");
} else {
try {
URL currentUrl = new URL(PageFactory.getWebDriver().getCurrentUrl());
String finalUrl = new URL(currentUrl.getProtocol(), currentUrl.getHost(), currentUrl.getPort(), ((PageEntry) annotation).url()).toString();
PageFactory.getWebDriver().navigate().to(finalUrl);
} catch (MalformedURLException ex) {
LOG.error("Failed to get current url", ex);
}
}
return bootstrapPage(pageClass);
}
throw new AutotestError("WebElementsPage " + title + " doesn't have fast URL in PageEntry");
}
use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class CriticalStepCheckAspect method sendCaseFinished.
@Around("sendCaseFinished(event)")
public void sendCaseFinished(ProceedingJoinPoint joinPoint, TestCaseFinished event) throws Throwable {
boolean hasFailedNonCriticalStep = hasFailedNonCriticalStep(event.testCase);
if (hasFailedNonCriticalStep) {
final Result result = new Result(Result.Type.PASSED, event.result.getDuration(), new AutotestError(NON_CRITICAL_CATEGORY_MESSAGE));
event = new TestCaseFinished(event.getTimeStamp(), event.getTimeStampMillis(), event.testCase, result);
Allure.getLifecycle().updateTestCase(getCurrentTestCaseUid(event.testCase), testResult -> testResult.setStatus(Status.PASSED));
joinPoint.proceed(new Object[] { event });
} else {
joinPoint.proceed();
}
}
use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class HtmlStepsImpl method setFormElementValue.
public T setFormElementValue(String key, String value) {
WebElement element = getElement(key);
if (element instanceof TextInput) {
element.clear();
element.sendKeys(value);
} else {
if (element instanceof SelectValue) {
((SelectValue) element).selectByValue(value);
} else {
if (element instanceof CheckBox) {
((CheckBox) element).set(Boolean.valueOf(value));
} else {
throw new AutotestError("Incorrect element type: " + key);
}
}
}
return (T) this;
}
use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class SelectAbstract method selectByIndex.
/**
* Select an option by index
*
* @param i option index
*/
public void selectByIndex(int i) {
open();
BaseElement option = ElementUtils.getElementByIndex(getOptions(), i);
if (!option.isEnabled()) {
throw new AutotestError(String.format(ERROR_DISABLED_TEMPLATE, option.getText()));
}
option.click();
}
use of ru.sbtqa.tag.qautils.errors.AutotestError in project page-factory-2 by sbtqa.
the class TableAbstract method selectRowByElement.
/**
* Selects a row in a table by element value in a column. Checks all the fields with
* the specified element name in order, until the search text is found in one of them.
* If several elements are found with the search text, the element with the specified number will be selected.
* If an element with the specified text and number is not found, an exception will be thrown.
*
* @param columnName column name
* @param elementName element name
* @param elementValue search text
* @param serialNumber sequence number for selection of matches found (1, 2, 3 ...)
* @param doubleClick {@code true}, if you need to make a double-click selection,
* and {@code false} if single
*/
public void selectRowByElement(String columnName, String elementName, String elementValue, int serialNumber, boolean doubleClick) {
int columnIndex = getColumnIndexByName(columnName);
HtmlFindUtils findUtils = Environment.getFindUtils();
try {
List<BaseElement> cells = findUtils.findList(this, columnName);
if (!cells.isEmpty()) {
Class<?> cellType = cells.get(0).getClass();
List<Field> fields = FieldUtils.getFieldsListWithAnnotation(cellType, ElementTitle.class);
String elementXpath = fields.stream().filter(field -> field.getAnnotation(ElementTitle.class).value().equals(elementName)).findFirst().orElseThrow(() -> new AutotestError("No cell element with name found: " + elementName)).getAnnotation(FindBy.class).xpath();
// to glue it under special conditions, excluding these symbols
if (elementXpath.startsWith(".") || elementXpath.startsWith("(")) {
elementXpath = elementXpath.replaceFirst("\\.?\\(?\\.?", "").replaceFirst("\\) ?\\[", "[");
}
String elementWithTextXpath = getColumnXpath(columnIndex) + elementXpath + format(TEXT_PART_XPATH_TEMPLATE, elementValue);
List<WebElement> elements = this.findElements(By.xpath(elementWithTextXpath));
click(ElementUtils.getElementByIndex(elements, serialNumber - 1), doubleClick);
} else {
throw new AutotestError("No column in the table was found: " + columnName);
}
} catch (ElementDescriptionException ex) {
throw new AutotestError("Error finding element in table");
} catch (ElementNotFoundException e) {
throw new AutotestError(format("No cell element found with value: %s. Number: %s", elementValue, serialNumber));
}
}
Aggregations