IntelliJ with cucumber (java) and step definition

2019-03-13 20:00发布

Ok, so I'm working on a project using IntelliJ and trying to take advantage of its cucumber functionality. I've not worked with the java flavour of cucumber, but IntelliJ seems to want the step definition files in a specific location, relative to the feature files.

I found this: how to define step definitions location for cucumber in intelliJ 12 and other sources that pointed me to been able to add the "glue" property of my run configurations which tells cuke which package to find the step file. So I am at a point where I can run my tests via IDEA. BUT I need to set this every time I run a new test, as Ctrl+Alt+F10 or right click+run test will not start the test with this flag. Also, the ide support is screwed as IDEA doesn't know where the steps are, it doesn't auto complte or Ctrl+Click navigate to steps.

Is there a way to the the IDEA project to always look for steps in a given package both when running the tests and for its auto complete?

6条回答
地球回转人心会变
2楼-- · 2019-03-13 20:13

It is really nonsense :) but in in my case when IDEA refused to add steps definition automatically due to some plugins installed, e.g. Cucumber for Scala and suggested deleting them that i cant since i need them in other project. So, long story short, to add (Create step definition) you need to create Class in 'glue' dir and some fake Cucumber implementation, build one more time and it resolved my issue.

 Background:
 When I use IDEA 2018.2
 And Java 8
 And Cucumber info.cukes:cucumber-java:1.2.4

 @When("^I created a Class and put there fake step implementation$")
 @And("^I run gradle build one more time :)$")
 @Then("^This Class will be able for me from the feature file by ALT+ENTER as usual$")
 @And("^It resolved my issue when I was not able to automatically generate step definition$")
查看更多
Luminary・发光体
3楼-- · 2019-03-13 20:14

Creating self answer for others who might have this problem. My project did not have the steps marked as test source root, and although I DID do this, it was not until I closed and reopened my project that they were picked up. So a simple restart was my answer.

查看更多
对你真心纯属浪费
4楼-- · 2019-03-13 20:15

I go in EditConfiguration, Glue section and i put the path from the package above and the package where is your class for steps, ex: CucumberFramework.stepsDefinitions

查看更多
够拽才男人
5楼-- · 2019-03-13 20:17

You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.

(IntelliJ 12.1.4)

查看更多
迷人小祖宗
6楼-- · 2019-03-13 20:22

Go File->Settings--> plugins Then you can manage cucumber plugin as shown below This should redirect you to step definition when you click your test.

enter image description here

Hope this helps

查看更多
手持菜刀,她持情操
7楼-- · 2019-03-13 20:35

IntelliJ supports a plugin for Cucumber-Java/Groovy. Installing this plugin will enable the navigation from Steps mentioned in the feature file to the Step Definitions.

enter image description here

And after creating the Step Definition, navigation is easily possible

enter image description here

查看更多
登录 后发表回答