Search in sources :

Example 1 with I18N

use of ru.sbtqa.tag.qautils.i18n.I18N in project page-factory-2 by sbtqa.

the class JunitReporter method getStepNameI18n.

private static String getStepNameI18n(ProceedingJoinPoint joinPoint, String method) {
    Locale locale = Locale.forLanguageTag(PROPERTIES.getJunitLang());
    Class clazz = joinPoint.getSignature().getDeclaringType();
    I18N i18n = I18N.getI18n(clazz, locale);
    return i18n.get(method);
}
Also used : Locale(java.util.Locale) I18N(ru.sbtqa.tag.qautils.i18n.I18N)

Example 2 with I18N

use of ru.sbtqa.tag.qautils.i18n.I18N in project page-factory-2 by sbtqa.

the class JunitReporter method handleStep.

public static Object handleStep(ProceedingJoinPoint joinPoint) throws Throwable {
    // FIXME: need to get another way to filter junit only steps cuz getStackTrace is very hard
    boolean isFromCucumber = Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(stackTraceElement -> stackTraceElement.getClassName().matches("ru\\.sbtqa\\.tag\\.stepdefs\\.[en|ru]\\..*"));
    if (isFromCucumber) {
        return joinPoint.proceed();
    } else {
        boolean isTestCaseStarted = Allure.getLifecycle().getCurrentTestCase().isPresent();
        if (!isTestCaseStarted) {
            String testCaseId = MD5.hash(joinPoint.getSignature().toShortString());
            String testResultUid = MD5.hash(joinPoint.toLongString());
            Allure.getLifecycle().scheduleTestCase(new TestResult().setTestCaseId(testCaseId).setUuid(testResultUid));
            Allure.getLifecycle().startTestCase(testResultUid);
        }
        Object[] args = normalizeArgs(joinPoint.getArgs());
        String methodName = joinPoint.getSignature().getName();
        // I18n contains template for steps as <methodName><dot><argsCount>. For example: fill.2
        String methodNameWithArgsCount = methodName + "." + args.length;
        String stepUid = createUid(joinPoint);
        String stepNameI18n = getStepNameI18n(joinPoint, methodNameWithArgsCount);
        // if step has i18n template - substitute args to it
        String stepName = String.format((stepNameI18n.equals(methodNameWithArgsCount) ? methodName : stepNameI18n), args);
        Allure.getLifecycle().startStep(stepUid, new StepResult().setName(stepName));
        System.out.println("\t * " + stepName);
        try {
            Object r = joinPoint.proceed();
            Allure.getLifecycle().updateStep(stepUid, stepResult -> stepResult.setStatus(Status.PASSED));
            return r;
        } catch (Throwable t) {
            Allure.getLifecycle().updateStep(stepUid, stepResult -> stepResult.setStatus(Status.FAILED).setStatusDetails(new StatusDetails().setTrace(ExceptionUtils.getStackTrace(t)).setMessage(t.getMessage())));
            throw t;
        } finally {
            attachParameters(methodName, args, createUid(joinPoint), stepName);
            Allure.getLifecycle().stopStep(stepUid);
        }
    }
}
Also used : Status(io.qameta.allure.model.Status) MD5(ru.sbtqa.tag.pagefactory.utils.MD5) Arrays(java.util.Arrays) I18N(ru.sbtqa.tag.qautils.i18n.I18N) TestResult(io.qameta.allure.model.TestResult) PageEntry(ru.sbtqa.tag.pagefactory.annotations.PageEntry) Page(ru.sbtqa.tag.pagefactory.Page) Endpoint(ru.sbtqa.tag.pagefactory.annotations.rest.Endpoint) StatusDetails(io.qameta.allure.model.StatusDetails) Allure(io.qameta.allure.Allure) Locale(java.util.Locale) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ApiEndpoint(ru.sbtqa.tag.pagefactory.ApiEndpoint) StepResult(io.qameta.allure.model.StepResult) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Configuration(ru.sbtqa.tag.pagefactory.properties.Configuration) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) StatusDetails(io.qameta.allure.model.StatusDetails) TestResult(io.qameta.allure.model.TestResult) StepResult(io.qameta.allure.model.StepResult)

Example 3 with I18N

use of ru.sbtqa.tag.qautils.i18n.I18N in project page-factory-2 by sbtqa.

the class PageFactoryUtils method isRequiredAction.

/**
 * Check whether given method has {@link ActionTitle} or
 * {@link ActionTitles} annotation with required title
 *
 * @param method method to check
 * @param title required title
 * @return true|false
 */
public static Boolean isRequiredAction(Method method, final String title) {
    ActionTitle actionTitle = method.getAnnotation(ActionTitle.class);
    ActionTitles actionTitles = method.getAnnotation(ActionTitles.class);
    List<ActionTitle> actionList = new ArrayList<>();
    if (actionTitles != null) {
        actionList.addAll(Arrays.asList(actionTitles.value()));
    }
    if (actionTitle != null) {
        actionList.add(actionTitle);
    }
    for (ActionTitle action : actionList) {
        String actionValue = action.value();
        try {
            I18N i18n = I18N.getI18n(method.getDeclaringClass(), TagCucumber.getFeature().getI18n().getLocale());
            actionValue = i18n.get(action.value());
        } catch (I18NRuntimeException e) {
            LOG.debug("There is no bundle for translation class. Leave it as is", e);
        }
        if (actionValue.equals(title)) {
            return true;
        }
    }
    return false;
}
Also used : I18NRuntimeException(ru.sbtqa.tag.qautils.i18n.I18NRuntimeException) ActionTitles(ru.sbtqa.tag.pagefactory.annotations.ActionTitles) ArrayList(java.util.ArrayList) ActionTitle(ru.sbtqa.tag.pagefactory.annotations.ActionTitle) I18N(ru.sbtqa.tag.qautils.i18n.I18N)

Example 4 with I18N

use of ru.sbtqa.tag.qautils.i18n.I18N in project page-factory-2 by sbtqa.

the class HTMLStepDefs method findElementInBlock.

/**
 * Find element inside given block. Element name itself is a parameter, and
 * defines type of the element to search for User|he keywords are optional
 *
 * @param block path or name of the block
 * @param elementType type of the searched element. Could be one of Yandex
 * element types types
 * @param elementTitle title of the element to search
 * @throws PageException if current page is not initialized, or element
 * wasn't found
 */
public void findElementInBlock(String block, String elementType, String elementTitle) throws PageException {
    String[] packages = this.getClass().getCanonicalName().split("\\.");
    String currentLanguage = packages[packages.length - 2];
    I18N i18n = I18N.getI18n(this.getClass(), new Locale(currentLanguage));
    String key = i18n.getKey(elementType);
    Class<? extends WebElement> clazz;
    switch(key) {
        case "ru.sbtqa.tag.pagefactory.type.element":
            clazz = WebElement.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.textinput":
            clazz = TextInput.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.checkbox":
            clazz = CheckBox.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.radiobutton":
            clazz = Radio.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.table":
            clazz = Table.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.header":
            clazz = TextBlock.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.button":
            clazz = Button.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.link":
            clazz = Link.class;
            break;
        case "ru.sbtqa.tag.pagefactory.type.image":
            clazz = Image.class;
            break;
        default:
            clazz = WebElement.class;
    }
    PageReflectUtil.findElementInBlockByTitle(PageContext.getCurrentPage(), block, elementTitle, clazz);
}
Also used : Locale(java.util.Locale) I18N(ru.sbtqa.tag.qautils.i18n.I18N)

Aggregations

I18N (ru.sbtqa.tag.qautils.i18n.I18N)4 Locale (java.util.Locale)3 Allure (io.qameta.allure.Allure)1 Status (io.qameta.allure.model.Status)1 StatusDetails (io.qameta.allure.model.StatusDetails)1 StepResult (io.qameta.allure.model.StepResult)1 TestResult (io.qameta.allure.model.TestResult)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 ApiEndpoint (ru.sbtqa.tag.pagefactory.ApiEndpoint)1 Page (ru.sbtqa.tag.pagefactory.Page)1 ActionTitle (ru.sbtqa.tag.pagefactory.annotations.ActionTitle)1 ActionTitles (ru.sbtqa.tag.pagefactory.annotations.ActionTitles)1 PageEntry (ru.sbtqa.tag.pagefactory.annotations.PageEntry)1 Endpoint (ru.sbtqa.tag.pagefactory.annotations.rest.Endpoint)1 Configuration (ru.sbtqa.tag.pagefactory.properties.Configuration)1 MD5 (ru.sbtqa.tag.pagefactory.utils.MD5)1