use of com.seleniumtests.core.Step.RootCause in project seleniumRobot by bhecquet.
the class LogAction method buildRootStep.
/**
* Returns step with name depending on step type
* In case of cucumber step, get the annotation value.
* /!\ THIS WORKS ONLY IF
* parameters of the annotated method are the Object version ones. Use 'Integer' instead of 'int' for example, when declaring
* a cucumber method which uses an integer as parameter. Else method discovery won't find it and step name will fall back to method name
*
* Else, get method name
* @param joinPoint
* @param returnArgs if true, returns method arguments
* @return
*/
private TestStep buildRootStep(JoinPoint joinPoint, String stepNamePrefix, boolean returnArgs) {
String stepName;
List<String> pwdToReplace = new ArrayList<>();
Map<String, String> arguments = new HashMap<>();
String argumentString = buildArgString(joinPoint, pwdToReplace, arguments);
if (returnArgs) {
stepName = String.format("%s %s", joinPoint.getSignature().getName(), argumentString);
} else {
stepName = joinPoint.getSignature().getName();
}
// Get the method called by this joinPoint
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
RootCause errorCause = RootCause.NONE;
String errorCauseDetails = null;
boolean disableBugtracker = false;
for (Annotation annotation : method.getAnnotations()) {
if ((annotation.annotationType().getCanonicalName().contains("cucumber.api.java.en") || annotation.annotationType().getCanonicalName().contains("cucumber.api.java.fr") || annotation.annotationType().getCanonicalName().contains("io.cucumber.java.en") || annotation.annotationType().getCanonicalName().contains("io.cucumber.java.fr")) && SeleniumRobotTestPlan.isCucumberTest()) {
stepName = getAnnotationValue(annotation) + " " + argumentString;
break;
} else if (annotation instanceof StepName) {
stepName = ((StepName) annotation).value();
// replaces argument placeholders with values
for (Entry<String, String> entry : arguments.entrySet()) {
stepName = stepName.replaceAll(String.format("\\$\\{%s\\}", entry.getKey()), entry.getValue().replace("$", "\\$"));
}
break;
} else if (annotation instanceof Step) {
stepName = ((Step) annotation).name();
errorCause = ((Step) annotation).errorCause();
errorCauseDetails = ((Step) annotation).errorCauseDetails();
disableBugtracker = ((Step) annotation).disableBugTracker();
// replaces argument placeholders with values
for (Entry<String, String> entry : arguments.entrySet()) {
stepName = stepName.replaceAll(String.format("\\$\\{%s\\}", entry.getKey()), entry.getValue().replace("$", "\\$"));
}
break;
}
}
return new TestStep(stepNamePrefix + stepName, Reporter.getCurrentTestResult(), pwdToReplace, SeleniumTestsContextManager.getThreadContext().getMaskedPassword(), errorCause, errorCauseDetails, disableBugtracker);
}
Aggregations