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 {
}
Related
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?
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 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!
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.
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