Discussion:
[Cucumber] Expressions in Java
Tim Walker
2018-06-18 18:22:50 UTC
Permalink
Hello,



I’m using cucumber expressions snd am struggling getting the basics
working. I am not sure if I am doing it right as there was a little
confusion around just providing the expression class like regular glue code
(and it seems so simple!). Perhaps some can shed some light.



With this Gherkin:

Given a customer has a savings account

Given a customer has a checking account



And this step:

@Given("a customer has a {account_type} account")

public void a_customer_has_a_account(AccountType account_type) {

System.out.println("Has an account type: " + account_type);

}



And this entry in config\cucumber.yml:

typeRegistry.defineParameterType(new ParameterType<>(

"account_type", // name

"savings|checking", // regexp

AccountType.class, // type

AccountType::new // transformer function

))



With this inner-class in the steps file:

public class AccountType {

String accountType;

AccountType(String accountType) {

this.accountType = accountType;

}

}



I get this:

Exception in thread "main" cucumber.runtime.CucumberException: Could not
create a cucumber expression for 'a customer has a {account_type} account'.

It appears you did not register parameter type. The details are in the
stacktrace below.

You can find the documentation here: https://docs.cucumber.io/
cucumber/cucumber-

expressions/

at io.cucumber.stepexpression.StepExpressionFactory.
registerTypeInConfiguration(StepExpressionFactory.java:87)

at io.cucumber.stepexpression.StepExpressionFactory.
createExpression(StepExpressionFactory.java:65)

at io.cucumber.stepexpression.StepExpressionFactory.
createExpression(StepExpressionFactory.java:54)



*--*
Tim
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Björn Rasmusson
2018-06-18 19:19:13 UTC
Permalink
Post by Tim Walker
Hello,
I’m using cucumber expressions snd am struggling getting the basics
working. I am not sure if I am doing it right as there was a little
confusion around just providing the expression class like regular glue code
(and it seems so simple!). Perhaps some can shed some light.
Given a customer has a savings account
Given a customer has a checking account
@Given("a customer has a {account_type} account")
public void a_customer_has_a_account(AccountType account_type) {
System.out.println("Has an account type: " + account_type);
}
Cucumber-JVM does not use cucumber.yml. The java-calculator example uses
ParameterTypes.java
<https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/ParameterTypes.java>
to define parameter types.

/Björn
Post by Tim Walker
typeRegistry.defineParameterType(new ParameterType<>(
"account_type", // name
"savings|checking", // regexp
AccountType.class, // type
AccountType::new // transformer function
))
public class AccountType {
String accountType;
AccountType(String accountType) {
this.accountType = accountType;
}
}
Exception in thread "main" cucumber.runtime.CucumberException: Could not
create a cucumber expression for 'a customer has a {account_type} account'.
It appears you did not register parameter type. The details are in the
stacktrace below.
https://docs.cucumber.io/cucumber/cucumber-
expressions/
at
io.cucumber.stepexpression.StepExpressionFactory.registerTypeInConfiguration(StepExpressionFactory.java:87)
at
io.cucumber.stepexpression.StepExpressionFactory.createExpression(StepExpressionFactory.java:65)
at
io.cucumber.stepexpression.StepExpressionFactory.createExpression(StepExpressionFactory.java:54)
*--*
Tim
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Walker
2018-06-18 20:00:00 UTC
Permalink
Björn thank you. [tim] below inline...
Post by Björn Rasmusson
Post by Tim Walker
Hello,
I’m using cucumber expressions snd am struggling getting the basics
working. I am not sure if I am doing it right as there was a little
confusion around just providing the expression class like regular glue code
(and it seems so simple!). Perhaps some can shed some light.
Given a customer has a savings account
Given a customer has a checking account
@Given("a customer has a {account_type} account")
public void a_customer_has_a_account(AccountType account_type) {
System.out.println("Has an account type: " + account_type);
}
Cucumber-JVM does not use cucumber.yml. The java-calculator example uses
ParameterTypes.java
<https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/ParameterTypes.java>
to define parameter types.
[Tim] Thank you very much. This is not at all obvious as the stack trace
"Register Type In Configuration" - sure looks like it wants to give it a go
from the YML! So, to be clear, don;t register parameter types using
profiles or configurations but, rather, leave an "extended
ParameterType.java" in the path to do the deed? Thanks again. Tim
Post by Björn Rasmusson
/Björn
Post by Tim Walker
typeRegistry.defineParameterType(new ParameterType<>(
"account_type", // name
"savings|checking", // regexp
AccountType.class, // type
AccountType::new // transformer function
))
public class AccountType {
String accountType;
AccountType(String accountType) {
this.accountType = accountType;
}
}
Exception in thread "main" cucumber.runtime.CucumberException: Could not
create a cucumber expression for 'a customer has a {account_type} account'.
It appears you did not register parameter type. The details are in the
stacktrace below.
You can find the documentation here: https://docs.cucumber.
io/cucumber/cucumber-
expressions/
at io.cucumber.stepexpression.StepExpressionFactory.
registerTypeInConfiguration(StepExpressionFactory.java:87)
at io.cucumber.stepexpression.StepExpressionFactory.
createExpression(StepExpressionFactory.java:65)
at io.cucumber.stepexpression.StepExpressionFactory.
createExpression(StepExpressionFactory.java:54)
*--*
Tim
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...