karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.29k stars 1.95k forks source link

@parallel=false is Applied to Scenario After the Tag #1921

Closed adrian-85 closed 2 years ago

adrian-85 commented 2 years ago

When applying the @parallel=false tag at the scenario level, it's running for the scenario after the one that's tagged. Version under test is 1.2.0RC2:

@HelloWorld
Feature: TEMP

    Background:
        * def sleep = function(millis){ java.lang.Thread.sleep(millis) }

    Scenario: One
        * karate.log('Running test one...')
        * sleep(2500)
        * karate.log('Finishing test one...')

    Scenario: Two
        * karate.log('Running test two...')
        * sleep(2500)
        * karate.log('Finishing test two...')

    Scenario: Three
        * karate.log('Running test three...')
        * sleep(2500)
        * karate.log('Finishing test three...')

    @parallel=false
    Scenario: Four
        * karate.log('Running test four...')
        * sleep(2500)
        * karate.log('Finishing test four...')

    Scenario: Five
        * karate.log('Running test five...')
        * sleep(2500)
        * karate.log('Finishing test five...')
12:55:59.690 [pool-1-thread-3] INFO  com.intuit.karate - Running test three... 
12:55:59.690 [pool-1-thread-4] INFO  com.intuit.karate - Running test four... 
12:55:59.690 [pool-1-thread-1] INFO  com.intuit.karate - Running test one... 
12:55:59.690 [pool-1-thread-2] INFO  com.intuit.karate - Running test two... 
12:56:02.213 [pool-1-thread-1] INFO  com.intuit.karate - Finishing test one... 
12:56:02.213 [pool-1-thread-4] INFO  com.intuit.karate - Finishing test four... 
12:56:02.213 [pool-1-thread-2] INFO  com.intuit.karate - Finishing test two... 
12:56:02.213 [pool-1-thread-3] INFO  com.intuit.karate - Finishing test three... 
12:56:02.233 [pool-1-thread-5] INFO  com.intuit.karate - Running test five... 
12:56:04.740 [pool-1-thread-5] INFO  com.intuit.karate - Finishing test five... 

Runner File:

package coding;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class CodingParallelRunner {

    @Test
    public void testParallel() {
        final Results results = Runner.path("classpath:coding")
            .outputCucumberJson(true)
            .outputJunitXml(true)
            .tags("~@ignore", "~@debug", "~@performance")
            .parallel(5);
        generateReport(results.getReportDir(), getClass().getSimpleName());
        assertTrue(results.getFailCount() == 0, results.getErrorMessages());
    }

    public static void generateReport(String karateOutputPath, String className) {
        final Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] { "json" }, true);
        final List<String> jsonPaths = new ArrayList<String>(jsonFiles.size());
        jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
        final Configuration config = new Configuration(new File("target"), className);
        final ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
        reportBuilder.generateReports();
    }

}
ptrthomas commented 2 years ago

@adrian-85 please note that you have to use the Runner API and not the JUnit one. is that the case ?

adrian-85 commented 2 years ago

I believe I am. Included the runner file contents.

ptrthomas commented 2 years ago

tagging as help wanted as I need time to create a sample project. anyone reading this please feel free to contribute code + fixes

J-Harms commented 2 years ago

Sample project: https://github.com/J-Harms/karate-parallel-scenario-issue-example/tree/master

While setting this up, I noted this exact problem does not exist in version 1.0.1 in case that is useful at all.

ptrthomas commented 2 years ago

@J-Harms so it must be this change: https://github.com/karatelabs/karate/issues/1608

without digging more - there may be some people who prefer the current behavior. all the info needed for anyone to see which parts of the code need to be tweaked are in the above ticket with commit history. for now, I'd like a second opinion, and ideally a PR.

ptrthomas commented 2 years ago

closing because of inactivity and no one else reporting this. to re-open, please submit a PR