Search in sources :

Example 6 with AutotestError

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");
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) MalformedURLException(java.net.MalformedURLException) PageEntry(ru.sbtqa.tag.pagefactory.annotations.PageEntry) Annotation(java.lang.annotation.Annotation) URL(java.net.URL)

Example 7 with AutotestError

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();
    }
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) TestCaseFinished(cucumber.api.event.TestCaseFinished) Result(cucumber.api.Result) TestResult(io.qameta.allure.model.TestResult) Around(org.aspectj.lang.annotation.Around)

Example 8 with AutotestError

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;
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) CheckBox(ru.yandex.qatools.htmlelements.element.CheckBox) WebElement(org.openqa.selenium.WebElement) HtmlElementUtils.getWebElement(ru.sbtqa.tag.pagefactory.utils.HtmlElementUtils.getWebElement) TextInput(ru.yandex.qatools.htmlelements.element.TextInput) SelectValue(ru.sbtqa.tag.pagefactory.elements.select.SelectValue)

Example 9 with AutotestError

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();
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) BaseElement(ru.sbtqa.tag.pagefactory.elements.BaseElement)

Example 10 with AutotestError

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));
    }
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) ElementNotFoundException(ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException) WebElement(org.openqa.selenium.WebElement) HtmlFindUtils(ru.sbtqa.tag.pagefactory.find.HtmlFindUtils) BaseElement(ru.sbtqa.tag.pagefactory.elements.BaseElement) Field(java.lang.reflect.Field) ElementDescriptionException(ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException) ElementTitle(ru.sbtqa.tag.pagefactory.annotations.ElementTitle) FindBy(org.openqa.selenium.support.FindBy)

Aggregations

AutotestError (ru.sbtqa.tag.qautils.errors.AutotestError)13 Field (java.lang.reflect.Field)4 WebElement (org.openqa.selenium.WebElement)3 BaseElement (ru.sbtqa.tag.pagefactory.elements.BaseElement)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ElementDescriptionException (ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException)2 ElementNotFoundException (ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException)2 TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ToNumberPolicy (com.google.gson.ToNumberPolicy)1 Result (cucumber.api.Result)1 TestCaseFinished (cucumber.api.event.TestCaseFinished)1 TestResult (io.qameta.allure.model.TestResult)1 String.format (java.lang.String.format)1 Annotation (java.lang.annotation.Annotation)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1