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