Can I run/use 3 feature files with a single step definition file in cucumber Java - cucumber-jvm

Can I run/use 3 feature files with a single step definition file in cucumber Java? Does cucumber java supports this?
I have the following feature files:
login.feature
registration.feature
search.feature
I need to implement only 1 step-definition.java file
for the 3 feature files.

You can use as many or as few files as you want to. But I would recommend splitting your step definitions into classes that correspond with the steps. Here are two suggestions as to how you could do it.
login.feature
registration.feature
search.feature
LoginStepDefs.java
RegistrationStepDefs.java
SearchStepDefs.java
or per page
login.feature
registration.feature
search.feature
LoginPageStepDefs.java
RegistrationPageStepDefs.java
SearchPageStepDefs.java
SearchResultPageStepDefs.java
Whatever you choose, make sure your CucumberRunner is configured to pick up the glue code (step definitions).

You can create a step for one feature and if the step makes sense and the logic is the same you can use it on other feature files without creating another step.

Related

Reading datatable value of one feature from another feature in specflow

i have a feature called as create experiment in feature1, i am passing the data that is needed to create experiment as Background section of feature file 1.
i want to access the data i am passing from feature file1 into feature file 2 as precondition. before executing featurefile2 i want to make sure the experiment is present with the data given in feature file1.
i am using a common class to collect all the data used in feature file 1 instead of storing them in stepdefination .
following the example given in this link to achieve this. https://docs.specflow.org/projects/specflow/en/latest/Bindings/Context-Injection.html
The problem here is, when i run feature file2 alone it does not get the data, since to data is filled during execution of feature file 1.
How to read the data of featurefile1 without executing featurefile1.
how to solve this .
Depending on the state of another test is generally not the idea on how to do BDD tests, or any unit/integration tests in general, since they are supposed to be self-contained. Understandably there won't be any support in SpecFlow on how to do this.
The easiest solution I can think of is to either copy the step definitions to your second feature file, which then calls the same code again. You don't have to copy the test implementation, because all steps are global in SpecFlow by default.
Another solution would be to add a background to the second feature file where you simply call the methods of the first feature file.

How to link Feature File to multiple step defintion files in Python BDD

I am developing a framework for automation using pytest-bdd based framework. Based on functionality I have multiple feature files and multiple step defintion files. Some scenarios take steps from other step definition files.
For example I have a Login Module , User Details Module. Now for validation of a step in User Module I do have to start with steps from the Login Module.
However in python bdd, I could see a one to one mapping of feature and step definition file.
Please let me know if this a limitation of pytest bdd framework .
Yes as far as i have worked with pytest bdd, you can only map one step definition to a single feature file, but there are work arounds to these.
1.Use conftest to keep all your common steps that you want to call across multiple feature files.
2.Use methods to be called into other step definitions by importing those methods into other step definitions.
I have a similar experience and i realized that if i don't use 1:1 mapping of feature to step definition file then it results in step_def not found errors
e.g.pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found:
So, I stick with the safe approach of 1:1 mapping
Would like to hear more thoughts feedback on this

Refactor the name of a Cucumber step definition in multiple .feature files in IntelliJ

Suppose a Cucumber step definition for which I would like to change the name on multiple .feature files.
#Then("^the step which I need to rename in multiple .feature files:$")
I was wondering if there was some IntelliJ plugin support to allow such refactoring.
If you right-click on the step in .feature file there is an option for that: Refactor -> Rename.... But it doesn't work as expected =)
Here is an issue for this: https://youtrack.jetbrains.com/issue/IDEA-152772
Best thing you can do so far is to upvote it...

Folder specific cucumber-reporting without parallel run?

Was wondering if I could get setup cucumber-reporting for specific folders?
For example in the https://github.com/intuit/karate#naming-conventions, in CatsRunner.java i set up the third party cucumber reporting? without parallel execution. please advise or direct me on how to set it up.
Rationale. its easier to read and helps me in debugging
You are always recommended to use the 3rd party Cucumber Reporting when you want HTML reports. And you can create as many Java classes similar to the DemoTestParallel in different packages. The first argument to CucumberRunner.parallel() needs to be a Java class - and by default, the same package and sub-folders will be scanned for *.feature files.
BUT I think your question is simply how to easily debug a single feature in dev-mode. Easy, just use the #RunWith(Karate.class) JUnit runner: video | documentation

Testing with Cucumber and Selenium:How can i break the sequence of feature file and run in random sequence

I have tried many option but any of them not work as i need. I have created some feature file as i required time by time. so i have a disorder feature file.
I want to run the feature file as i wanted. like.
fil1.feature
fil2.feature
fil3.feature
fil4.feature
so i want to run in this sequence : file3.feature->fil4.feature->fil1.feature.
I have tried #tag, #feature in junit test runner option but its maintain the sequence its run only 3,4 but can't run 1.
So can you tell me how to run feature file randomly???
Cucumber picks up the feature files in alphabetic order from the folder given in the features parameter of the CucumberOptions. So one options would be to rename your feature files alphabetically in the order you want.
After the feature files in the initial folder are read, then the sub folders in the location are picked up alphabetically and the feature files inside them are read. So you can place the file you want to be used later into a sub-folder.
Saying all this, it is not a very good idea to have any dependency between tests which requires a sequence to be maintained.
I got the same stop. Have you solved this problem?
I did some test, use --tags #XXX to controll the sequence is useless, it's just action on different scenarios in a feature file.
so far, I have to do it like this cucumber features/c.feature features/a.feature features/b.feature I think this is a little bit better than rename feature files.
But you may say that: "If there is a lot of feature files......" In my project(ROR), I assigned the statement to ./config/cucumber.yml
In cucumber.yml I define a profile, test_dev: features/c.feature features/a.feature features/b.feature after that, I just to use cucumber -p test_dev and the feature files execute in order.
If you have a butter way, please share with us.