Intellij IDEA Run configurations for Cucumber runner class - intellij-idea

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!

Related

Converting current project into Cucumber

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 {
}

IntelliJ Error: Could not find or load main class cucumber.api.cli.Main [duplicate]

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!

Running TestNG Test in IntelliJ

After running Rebuild Project successfully in IntelliJ 13.1.3 Ultimate IDE, I opened my Test NG test file.
When right-clicking on the file, I don't see any option to run the test.
How can I run an TestNG test in IntelliJ 13.1.3?
This question is similar, but it's from 2012 with an unaccepted answer.
Yes you can!
Сheck the folder that contains the test classes whether marked as Test Source Root. In another case see whether installed TestNG-J plugin.
Update:
There are 3 possibilities in the new Intellij 2017.2 to run a testNG test.
You can click on the module (project) name >>Run>>All Tests(TNG). Be careful as there are 2 'All Tests' options. The second option is the one you need. It carries a testNG logo. This way you can run all your testNG classes in parallel
The second possibility is to run a single TestNG class. Righ click the class name in the package explorer and choose 'Run Test' If your class is a testNG class, by default, the test will run as a TestNG test.
This option is my favourite as it gives me a lot of control over my tests. Install this 'Create TestNG XML' plugin. Once installed. if you right click on your module name, you will see a new option called 'Create TESTNG XML' and you will be able to directly use that option to run your TestNG tests, giving you a lot of flexibility.
It could be that a plugin that you need is disabled.
Make sure the testNg plugin is enabled.
I noticed this plugin wasn't enabled,
and as soon as I turned it on, everything started working.

IntelliJ with cucumber (java) and step definition location

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?
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.
You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.
(IntelliJ 12.1.4)
Go File->Settings--> plugins
Install Cucumber for Java plugin
Then you can manage cucumber plugin as shown below
This should redirect you to step definition when you click your test.
Hope this helps
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.
And after creating the Step Definition, navigation is easily possible
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
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$")

How can I tell which specific version of JUnit IntelliJ is using?

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