2626import com .intuit .karate .core .StepResult ;
2727import io .qameta .allure .Allure ;
2828import io .qameta .allure .AllureLifecycle ;
29- import io .qameta .allure .model .Attachment ;
3029import io .qameta .allure .model .Label ;
3130import io .qameta .allure .model .Link ;
3231import io .qameta .allure .model .Parameter ;
5049import java .util .Optional ;
5150import java .util .Set ;
5251import java .util .UUID ;
53- import java .util .concurrent .locks .ReadWriteLock ;
54- import java .util .concurrent .locks .ReentrantReadWriteLock ;
5552import java .util .stream .Collectors ;
5653
5754import static io .qameta .allure .util .ResultsUtils .createLabel ;
@@ -71,11 +68,6 @@ public class AllureKarate implements RuntimeHook {
7168
7269 private final AllureLifecycle lifecycle ;
7370
74- private final ReadWriteLock lock = new ReentrantReadWriteLock ();
75-
76- private final Map <String , String > stepsAndTcUuids = new HashMap <>();
77- private final Map <String , Step > stepAndUuids = new HashMap <>();
78-
7971 private final List <String > tcUuids = new ArrayList <>();
8072
8173 public AllureKarate () {
@@ -221,14 +213,6 @@ public void afterStep(final StepResult result,
221213 });
222214 lifecycle .stopStep (uuid );
223215
224- if (stepResult .isFailed ()
225- && sr .engine .getConfig ().getDriverOptions () != null
226- && (Boolean ) sr .engine .getConfig ().getDriverOptions ().get ("screenshotOnFailure" )
227- ) {
228- addToStepsAndTcUuids (uuid , lifecycle .getCurrentTestCase ().get ());
229- addToStepAndUuids (uuid , step );
230- }
231-
232216 if (Objects .nonNull (result .getEmbeds ())) {
233217 result .getEmbeds ().forEach (embed -> {
234218 try (InputStream is = new BufferedInputStream (Files .newInputStream (embed .getFile ().toPath ()))) {
@@ -248,30 +232,6 @@ public void afterStep(final StepResult result,
248232
249233 @ Override
250234 public void afterFeature (final FeatureRuntime fr ) {
251-
252- if (!stepsAndTcUuids .isEmpty ()) {
253- fr .result .getScenarioResults ()
254- .forEach (sc -> {
255- if (Objects .nonNull (sc .getFailedStep ())) {
256- getKeySetFromStepAndUuids ().forEach (uuid -> {
257- if (getValueFromStepAndUuids (uuid ) == sc .getFailedStep ().getStep ()) {
258- final List <Attachment > attachments = new ArrayList <>();
259- sc .getFailedStep ().getEmbeds ().forEach (e -> attachments .add (
260- new Attachment ()
261- .setSource (e .getFile ().getPath ())
262- .setType (e .getResourceType ().contentType )
263- .setName (e .getFile ().getName ())
264- )
265- );
266- lifecycle .updateTestCase (getValueFromStepsAndTcUuids (uuid ), result ->
267- result .setAttachments (attachments )
268- );
269- }
270- });
271- }
272- });
273- }
274-
275235 tcUuids .forEach (lifecycle ::writeTestCase );
276236 }
277237
@@ -321,49 +281,4 @@ private List<Link> getLinks(final List<String> labels) {
321281 }
322282 return allureLinks ;
323283 }
324-
325- private void addToStepsAndTcUuids (final String stepUuid , final String tcUuid ) {
326- lock .writeLock ().lock ();
327- try {
328- stepsAndTcUuids .put (stepUuid , tcUuid );
329- } finally {
330- lock .writeLock ().unlock ();
331- }
332- }
333-
334- private void addToStepAndUuids (final String stepUuid , final Step step ) {
335- lock .writeLock ().lock ();
336- try {
337- stepAndUuids .put (stepUuid , step );
338- } finally {
339- lock .writeLock ().unlock ();
340- }
341- }
342-
343- private String getValueFromStepsAndTcUuids (final String stepUuid ) {
344- lock .readLock ().lock ();
345- try {
346- return stepsAndTcUuids .get (stepUuid );
347- } finally {
348- lock .readLock ().unlock ();
349- }
350- }
351-
352- private Step getValueFromStepAndUuids (final String stepUuid ) {
353- lock .readLock ().lock ();
354- try {
355- return stepAndUuids .get (stepUuid );
356- } finally {
357- lock .readLock ().unlock ();
358- }
359- }
360-
361- private Set <String > getKeySetFromStepAndUuids () {
362- lock .readLock ().lock ();
363- try {
364- return stepAndUuids .keySet ();
365- } finally {
366- lock .readLock ().unlock ();
367- }
368- }
369284}
0 commit comments