If cucumber feature file contains {} in scenario Then, When and etc. such as {guid}, it is very common in REST API scenarios.
Scenario: User REST API Business Scenarios
Then Test the user was created GET /parcel_rewards/v1/user/{guid}
Then Java method can not be translated correctly. Test case failed as error below.
cucumber.runtime.CucumberException: java.util.regex.PatternSyntaxException: Illegal repetition near index 58
In addition, feature file is crashed when open it with Cucumber plugin in the Eclipse.
Expected Behavior
Java method can be translated correctly.
Current Behavior
Java method can be translated correctly. Test cases failures
Feature file is crashed when open it with Cucumber plugin in the Eclipse.
Possible Solution
If add escape character for {guid}, like \{guid\} in translated JAVA method, the issue can be fixed
@Then("^Test the user was created GET /parcel_rewards/v(\\d+)/user/\\{guid\\}$")
public void test_the_user_was_created_GET_parcel_rewards_v_user_guid(int arg1) throws Exception {
}
Steps to Reproduce (for bugs)
Added REST API scenario which contains { }, such as {guid}, eg
Scenario: User REST API Business Scenarios
Then Test the user was created GET /parcel_rewards/v1/user/{guid}
Translated to java code:
@Then("^Test the user was created GET /parcel_rewards/v(\d+)/user/{guid}$")
public void test_the_user_was_created_GET_parcel_rewards_v_user_guid(int arg1) throws Exception {
}
When execute test cases, there is error log below that illegal repetition near {guid}
cucumber.runtime.CucumberException: java.util.regex.PatternSyntaxException: Illegal repetition near index 58
^Test the user was created GET /parcel_rewards/v(\d+)/user/{guid}$
^
at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:149)
at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:63)
at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:79)
at cucumber.runner.Runner.(Runner.java:45)
at cucumber.runtime.Runtime.(Runtime.java:65)
at cucumber.runtime.Runtime.(Runtime.java:45)
at cucumber.runtime.Runtime.(Runtime.java:41)
at net.serenitybdd.cucumber.CucumberWithSerenityRuntime.createSerenityEnabledRuntime(CucumberWithSerenityRuntime.java:38)
at net.serenitybdd.cucumber.CucumberWithSerenityRuntime.using(CucumberWithSerenityRuntime.java:28)
at net.serenitybdd.cucumber.CucumberWithSerenity.createRuntime(CucumberWithSerenity.java:58)
at cucumber.api.junit.Cucumber.(Cucumber.java:63)
at net.serenitybdd.cucumber.CucumberWithSerenity.(CucumberWithSerenity.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 58
^Test the user was created GET /parcel_rewards/v(\d+)/user/{guid}$
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.closure(Pattern.java:3157)
at java.util.regex.Pattern.sequence(Pattern.java:2134)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at cucumber.runtime.java.JavaBackend.pattern(JavaBackend.java:185)
at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:144)
... 29 more
4 Close feature file in Eclipse, then open it with Cucumber Editor, the feature file is crashed.
Context & Motivation
As we all known, REST API testing is more important in software industry. REST API in cucumber is common, specially contains {} in scenarios.
Summary
If cucumber feature file contains {} in scenario Then, When and etc. such as {guid}, it is very common in REST API scenarios.
Scenario: User REST API Business Scenarios Then Test the user was created GET /parcel_rewards/v1/user/{guid}
Then Java method can not be translated correctly. Test case failed as error below.
cucumber.runtime.CucumberException: java.util.regex.PatternSyntaxException: Illegal repetition near index 58
In addition, feature file is crashed when open it with Cucumber plugin in the Eclipse.
Expected Behavior
Java method can be translated correctly.
Current Behavior
Possible Solution
If add escape character for {guid}, like \{guid\} in translated JAVA method, the issue can be fixed
Steps to Reproduce (for bugs)
Added REST API scenario which contains { }, such as {guid}, eg Scenario: User REST API Business Scenarios Then Test the user was created GET /parcel_rewards/v1/user/{guid}
Translated to java code: @Then("^Test the user was created GET /parcel_rewards/v(\d+)/user/{guid}$") public void test_the_user_was_created_GET_parcel_rewards_v_user_guid(int arg1) throws Exception { }
When execute test cases, there is error log below that illegal repetition near {guid}
cucumber.runtime.CucumberException: java.util.regex.PatternSyntaxException: Illegal repetition near index 58 ^Test the user was created GET /parcel_rewards/v(\d+)/user/{guid}$ ^ at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:149) at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:63) at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40) at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:79) at cucumber.runner.Runner.(Runner.java:45)
at cucumber.runtime.Runtime.(Runtime.java:65)
at cucumber.runtime.Runtime.(Runtime.java:45)
at cucumber.runtime.Runtime.(Runtime.java:41)
at net.serenitybdd.cucumber.CucumberWithSerenityRuntime.createSerenityEnabledRuntime(CucumberWithSerenityRuntime.java:38)
at net.serenitybdd.cucumber.CucumberWithSerenityRuntime.using(CucumberWithSerenityRuntime.java:28)
at net.serenitybdd.cucumber.CucumberWithSerenity.createRuntime(CucumberWithSerenity.java:58)
at cucumber.api.junit.Cucumber.(Cucumber.java:63)
at net.serenitybdd.cucumber.CucumberWithSerenity.(CucumberWithSerenity.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 58
^Test the user was created GET /parcel_rewards/v(\d+)/user/{guid}$
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.closure(Pattern.java:3157)
at java.util.regex.Pattern.sequence(Pattern.java:2134)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at cucumber.runtime.java.JavaBackend.pattern(JavaBackend.java:185)
at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:144)
... 29 more
4 Close feature file in Eclipse, then open it with Cucumber Editor, the feature file is crashed.
Context & Motivation
As we all known, REST API testing is more important in software industry. REST API in cucumber is common, specially contains {} in scenarios.
Your Environment