All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.aoreshin.junit5.extensions.allure.AllureEncodeStepParametersExtension Maven / Gradle / Ivy

There is a newer version: 83
Show newest version
package com.github.aoreshin.junit5.extensions.allure;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toUnmodifiableList;

import io.qameta.allure.Allure;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.StepResult;
import java.util.List;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

/**
 * Extension that is used to erase all sensitive parameters (passwords, tokens, etc) from Allure's
 * test step parameters
 *
 * 

Can be used in two flavours: * *

    *
  • @ExtendWith(AllureEncodeStepParametersExtension.class) then you must specify * allureEncodeStepParameters property in order to make it work properly *
  • Use com.github.aoreshin.junit5.extensions.TestTemplateInvocationContextBuilder addExtension * method and pass parameter names through constructor. *
*/ public class AllureEncodeStepParametersExtension implements AfterEachCallback { private final List parameterNames; public AllureEncodeStepParametersExtension() { this.parameterNames = List.of(System.getProperty("allureEncodeStepParameters").split(",")); } public AllureEncodeStepParametersExtension(String... parameterNames) { this.parameterNames = List.of(parameterNames); } @Override public void afterEach(ExtensionContext context) { Allure.getLifecycle() .updateTestCase( update -> { List processed = processStepResult(update.getSteps()); update.setSteps(processed); }); } private List processStepResult(List stepResults) { if (stepResults.size() != 0) { return stepResults.stream() .peek( stepResult -> { List parameters = stepResult.getParameters().stream() .filter(parameter -> parameterNames.contains(parameter.getName())) .peek(parameter -> parameter.setValue("*****")) .collect(toUnmodifiableList()); stepResult.setParameters(parameters); stepResult.setSteps(processStepResult(stepResult.getSteps())); }) .collect(toList()); } return List.of(); } /** Only for testing */ List getParameterNames() { return parameterNames; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy