temyers / cucumber-jvm-parallel-plugin

Maven plugin to help running Cucumber features in parallel
Apache License 2.0
129 stars 121 forks source link

Unsupported Scheme error with cucumber-jvm:4.2.3 [Solved: update to 4.2.4] #194

Closed techanon closed 5 years ago

techanon commented 5 years ago

PROBLEM:
On WindowsOS, when trying to run cucumber:4.2.3 using the generated classes from this plugin v5.0.0 I am getting an error specifying an "Unsupported Scheme: " error.

DISCOVERY:
I did some investigation into the code and figure out that in the generated files on windows (not sure about linux or mac), the features value is a normal windows path (expected). Then I debugged the cucumber runner and found that it was doing a comparison of the Scheme part of the path it is given.

For example: If the feature file is "C:\Users\user\workspace\app\src\test\resources\features\test.feature"
cucumber will try to get the scheme via the java Path api. This results in the scheme being "C" instead of "file" or "classpath" like it expects and throws an error.

TEMP SOLUTION:
I have created a simple shim that resolves this issue for me for the time being. See below:

<plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.6.0</version>
      <executions>
          <execution>
              <phase>process-test-sources</phase>
              <goals>
                  <goal>java</goal>
              </goals>
          </execution>
      </executions>
      <configuration>
          <mainClass>com.myapp.util.FixCucumberParallelFiles</mainClass>
          <arguments>
              <argument>${project.build.directory}/generated-test-sources/cucumber</argument>
          </arguments>
      </configuration>
</plugin>
package com.myapp.util;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * This class is called from maven using exec-maven-plugin in order to correct the
 * features paths notation in the generated cucumber runner files via cucumber-jvm-parallel-plugin
 * so that the newer version of cucumber-core can correctly understand what type of resource the path is.
 */
public class FixCucumberParallelFiles {
    public static void main(String[] args) throws IOException {
        File[] files = new File(args[0]).listFiles();
        if (files == null) return;
        for (File file : files) {
            Path path = Paths.get(file.toURI());
            String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
            // prefix all paths using the windows path style with the 'file:' scheme
            content = content.replaceAll("\"([A-Z]+):", "\"file:$1:");
            Files.write(path, content.getBytes(StandardCharsets.UTF_8));
        }
    }
}

This code (as the comment says) prefixes all paths that use the window's path style (letter and colon) with the file: scheme so that the Path API interprets the path scheme correctly.

PROPOSED SOLUTION:
The simplest fix I have thought of is to add a maven config option that allows the person to define a custom scheme to prefix the feature file path of the generated runners.

Please let me know if I overlooked something that would nullify this issue, or if you need additional information.

whizkid79 commented 5 years ago

It seems like cucumber core 4.2.4 fixes the issue and makes this fix obsolete: see: https://github.com/cucumber/cucumber-jvm/commit/407627a96cbc2200246f460861489630f68ddde3

Keeping the fix will have scenarios with an outline and a test tabel run n^2 times because it makes cucumber ignore the line number in every runner, thus running all tests every single time. See also: https://github.com/cucumber/cucumber-jvm/commit/346b6e7ee8e064ae991c3d169ca727c6a3ae8a4f

So suggested workaround for the workaround: update core to 4.2.4 (or newer) and remove the fix.

techanon commented 5 years ago

Fantastic! Not sure about the n^2 problem with my shim, but I'm glad this is fixed in 4.2.4