Search in sources :

Example 1 with Step

use of com.seleniumtests.core.Step 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);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) MethodSignature(org.aspectj.lang.reflect.MethodSignature) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StepName(com.seleniumtests.core.StepName) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) Step(com.seleniumtests.core.Step) TestStep(com.seleniumtests.reporter.logger.TestStep) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) RootCause(com.seleniumtests.core.Step.RootCause)

Aggregations

Step (com.seleniumtests.core.Step)1 RootCause (com.seleniumtests.core.Step.RootCause)1 StepName (com.seleniumtests.core.StepName)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 AfterMethod (org.testng.annotations.AfterMethod)1