I am using JUnit test configuration to run my test and feature file properly recognized its relevant step definitions. After a recent IntelliJ update (to Ultimate 2020), my feature file shows all the Gherkin statements as undefined. Even when I try to create a dummy one using the 'Create Step Definition' link by hovering over, it complained 'Incorrect step definition directory path' for File Location. These are things that I followed:
Visited these existing Stackoverflow links
IntelliJ with cucumber (java) and step definition location
Undefined step definitions in IntelliJ
Did a 'Invalidate caches and restart' of my IntelliJ.
My project structure is src/main/java/xxxx/stepDefinitions (for my .java step definitions) and src/main/resources/features (for my .feature files). Already marked my 'resources' as 'Test Resources Root' and the 'java' as 'Sources Root'. Ensured that they are still the same after update.
Disabled the plugins (Cucumber for Java, Cucumber for Groovy, Gherkin), did a restart and then enabled them back.
Edit configurations' JUnit runner was not disturbed after the update. I have no glue settings here and having them in my JUnit Runner class. Here is a short snippet. Also, deleted all existing configurations and kept only JUnit.
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"classpath:features"}
,glue = "xxxx/stepDefinitions"
,tags = {"#xxx","#yyyy"}
,plugin ={"com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:target/report/report.html"}
)
Can someone please help out with any missing steps and resolve my problem?
Related
We already have a working project in test NG and now we are trying to add cucumber framework to it.
Sofar, I could goto eclipse marketplace and download the cucumber plugin, also added cucumber dependencies into my gradle file.
Then I have created a feature file - login.feature and its corresponding step definition for it. In the same feature file I have right clicked -> run as -> (selected) cucumber feature, now the issue is eclipse is unable to recognize the step definition for its corresponding feature file and the executed console in the attached screenshots.
Output:
0 Scenarios
0 Steps
0m0.567s
Please see the attached screenshots for more information.
If you just need to see whether feature file is running, first you need to make sure that Cucumber Eclipse Plugin is properly installed, Eclipse needs to be restarted after installation. If you are using TestNG then Cucumber-TestNG and Cucumber-Java dependencies of same version should be used. I could see Cucumber-TestNG dependency missing. You need to exclude JUnit also.
Then in order to run feature file, you first need to configure it, by selecting Run Configuration->click Cucumber feature(left panel)->select project->provide Feature file location->Apply and Run
You can also create a Test Runner which will link Feature file with Step definition and run the test as TestNG test from Runner.
Eg. Test Runner
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(features = "src/test/resources/featureFiles", glue = "stepDefinitions")
public class RunTestNGTest extends AbstractTestNGCucumberTests {
}
I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!
I encountered the following issue. I have four Cucumber feature files in IntelliJ. I added the Cucumber support via the IntelliJ plugin. After creating my features I edited my configuration like followed so i can execute the feature files.
Glue should be the name of the package the step definitions reside in. In my case the package is called stepdefinitions.
The following image shows what my project structure looks like. The feature files reside in /src/test/resource/features while the stepdefinitions are stored in /src/test/java/stepdefinitions.
Sadly when I try to run the cucumber features with the step definitions I get prompted "You can implement missing steps with the snippets below:" But I already did this. I already copied those snippets to the step definition files. When I hover a scenario IntelliJ tells me *Unimplemented Substep Definition".
Those two things lead me to the conclusion that IntelliJ does not find my step definitions. Maybe one of you knows what I am doing wrong.
I finally found the solution to my question. The error was caused by a plugin called Substep IntelliJ Plugin. You need to search for it in the IntelliJ Plugin Section and disable or deinstall it.
Try 'Invalidate cache and restart'. It worked for me - something the plugin gets stuck.
Disable the Cucumber plugin to avoid collisions over feature file association, install the Substeps plugin. See http://substeps.github.io/ for more docs on how to use the Substeps BDD framework alongside downloading a sample starter project from here: https://github.com/Substeps/substeps-example/archive/1.1.zip
I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!
I've started working on a large project where the IntelliJ environment has already been set up. The environment includes JUnit, and I can successfully run unit tests. I've seen screens where I can specify the usage of JUnit 3 or JUnit 4, but how can I determine which specific JUnit is being used to run my tests, e.g., JUnit 4.11?
I have already tried "Open Module Settings". When I look at the "Dependencies" tab, I don't see anything relating to JUnit, although I can run JUnit tests.
Which jar is used?
When you run JUnit from IntelliJ, the very first line of the console output displays your classpath. You can use Ctrl+F to find any "junit" references.
junit-rt.jar is a helper library that JetBrains might have written. By opening the jar as an archive with 7-zip, you will find that the only package inside it is under com.intellij
According to Java: Which of multiple resources on classpath JVM takes? the first reference to junit.jar is the one you will use.
What version is that jar?
Once you know which jar is being used, there are a number of ways to find the version. One is to use this code taken from https://stackoverflow.com/a/16729507/1405720
import junit.runner.Version;
System.out.println("JUnit version is: " + Version.id());
Another method might be to open up the jar as an archive and see if you can figure it out from there.
If you are looking for the JUnit libraries that are shipped with IntelliJ have a look at the corresponding jars in the lib/ directory of your Intellij IDEA installation.
For more information on this have a look at the online documention:
http://www.jetbrains.com/idea/webhelp/configuring-testing-libraries.html
http://www.jetbrains.com/idea/webhelp/testing.html