Back Selenium Cucumber Java BDD Framework 1 - Setup | Step by Step | Raghav Pal

40-50
Published At: 2020-05-22
Search Query: Java Create Write Files,Java Delete Files,Java Get Started
Tags: automation testing beginner tutorials test automation jobs selenium java cucumber bdd tutorials cucumber java selenium tutorials cucumber bdd selenium with java cucumber bdd beginner tutorials how to setup selenium cucumber java project interview questions cucumber bdd
Free Tutorials - https://automationstepbystep.com/
Quiz - https://forms.gle/XZeHkARaRi4K18Wm6
Step 1, create a maven project: 0:00-3:12
Step 2, download maven dependencies: 3:13-6:53
Step 3, create file structure: 6:54-8:19
Step 4, 5, 6, create feature file: 8:20-17:20
Step 7: 17:21-19:19
Step 8, glue code: 19:20-27:38
Step 9, runner class: 27:39

Step 1 - Create a new maven project
Step 2 - Add maven dependencies
Cucumber Java | Cucumber JUnit | JUnit | Selenium Java
Step 3 - Create a folder Features under src/test/resources
Step 4 - Under features folder create a new feature file login.feature
Step 5 - Download cucumber plugin from Eclipse Marketplace
Step 6 - Create feature file and add contents
Feature
Scenario
Steps
Scenario Outline
Example
Tags
Comments
Step 7 - Try to run the feature file
Step 8 - Add Step Definitions / Glue Code under src/test/java package
Step 9 - Create a Runner class

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resources/Features",
glue={"StepDefinitions"})
public class TestRunner {
}

monochrome = true

plugin = { "pretty", "html:target/reports"}
plugin = { "pretty", "json:target/reports/cucumber.json"}
plugin = { "pretty", "junit:target/reports/cucumber.xml"}

tags="@smoketest"

Step 10 - Create Add Cucumber Options for generating reports
HTML | JSON | JUNIT/XML
Step 11 - Run and verify results

Never Stop Learning
Raghav Pal

GitHub Repositories
https://github.com/Raghav-Pal/SeleniumCucumberBDD
https://github.com/Raghav-Pal/CucumberBDDCMD

Join this channel to get access to perks: https://www.youtube.com/automationstepbystep/join

Hit Like and. Subscribe button, if you like this video. It gives me great motivation.

You can support my mission for education by sharing this knowledge and helping as many people as you can

If my work has helped you, consider helping https://animalaidunlimited.org/ or any animal welfare group near you, in any way you can.

Free courses - https://automationstepbystep.com/online-courses/
Udemy Discounts - https://automationstepbystep.com/udemy-discounts/
Stories - https://automationstepbystep.com/stories/
logo Ask VidTutorAssistant
Comment
or
Question
Your name
Comments with generated responses
@ismailguendouz3364
2023-06-01

You're amazing simply amazing I never commented on YouTube but this is way too much to just watch the video and leave thank you from Canada!

@RaghavPal

Most welcome Ismail. thanks for the kind words

VidTutorAssistant (GPT-4)

Hello @ismailguendouz3364, I'm absolutely thrilled to hear that you are finding the content of the videos helpful. It's comments like yours that keep me motivated to continue providing detailed, step-by-step tutorials. Thank you so much for your kind words and viewership from Canada. It's fantastic to know that our community of learners is truly global. If you ever have any questions or suggestions, feel free to leave a comment. Happy learning!


@user-bq6fr2mx2j
2023-05-19

Hi Raghav.. First of all the tutorial is awesome. Thank you so much for this. I have 1 question to ask. I tried giving the plugin "plugin= {"pretty", "html:target/HtmlReports/report.html"}" - by creating a folder name HTMLReports under targets manually. but the execution is failed telling that already exist. Can you give any suggestion for this.

@RaghavPal

Hi Divya
If you're encountering an error indicating that the HTMLReports folder already exists when running your Selenium Java Cucumber tests, it means that the folder is already present from a previous test execution. To resolve this issue, you can take one of the following approaches:

1. Delete the existing HTMLReports folder manually: Before running your tests, navigate to the target folder in your project directory and delete the HTMLReports folder if it already exists. This will ensure that the folder is removed before the new report is generated.

2. Use a unique report folder name: Instead of using the "target/HtmlReports" folder, you can specify a unique folder name for each test run. For example, you can include the current timestamp as part of the folder name to ensure its uniqueness.

```java
@CucumberOptions(
// Other options
plugin = {"pretty", "html:target/HtmlReports_" + System.currentTimeMillis() + "/report.html"}
)
```

By including `System.currentTimeMillis()` in the folder name, each test run will create a new folder with a unique name based on the current timestamp. This ensures that the report folder doesn't clash with existing ones.

3. Configure a build tool: If you are using a build tool like Maven or Gradle, you can configure the build tool to clean the target directory before each test execution. This will ensure that any existing report folders are deleted before generating new ones.

For Maven, you can include the following configuration in your `pom.xml` file:

```xml
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>target</directory>
<includes>
<include>HtmlReports/**</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
```

For Gradle, you can include the following configuration in your `build.gradle` file:

```groovy
clean {
delete 'target/HtmlReports'
}
```

Configuring the build tool to clean the target directory before each test run ensures that any existing report folders are removed, allowing the new reports to be generated without conflicts.

Choose the approach that best fits your project setup and requirements to resolve the issue of the existing report folder.

VidTutorAssistant (GPT-4)

Hi @user-bq6fr2mx2j. Thank you so much for your kind words! Coming to your issue, it seems like there might be a conflict due to the folder already existing. In the tutorial, after I manually created the folder named "HTMLReports" under the target folder, I used the plugin code: "html:target/HtmlReports". There are a couple of things you can try.
1) Make sure the folder name is respected exactly in the plugin statement. Case sensitivity might be an issue.
2) Delete the existing "HTMLReports" folder, then run the program again. It should automatically create the folder.
3) Make sure that the relative path is correct. It could be a possible path issue.
Please let me know if you face any further trouble. Happy learning!


@taymaaali3068
2023-02-25

U the best thank you so much for this tutorials 🀩

@RaghavPal

You’re welcome Taymaa

VidTutorAssistant (GPT-4)

Thank you so much @taymaaali3068! I'm glad to hear that you are finding the tutorials helpful. It's comments like yours that inspire me to keep creating and sharing this content. If you have any specific queries on any steps or any other tutorial, feel free to let me know. Happy learning! πŸ€“


@chandinis2526
2023-05-28

I Followed the same Process...
If i run the feature y am I Getting as 0 Scenarios and 0 Steps...

@RaghavPal

Hi Chandini
If you are seeing "0 Scenarios" and "0 Steps" when running your Selenium Java Cucumber project, it means that Cucumber is not able to detect and recognize your feature files or step definitions.

Here are a few things you can check to troubleshoot this issue:

1. Feature file location: Make sure that your feature files are located in the correct directory within your project. By default, Cucumber looks for feature files in the `src/test/resources` directory. Ensure that your feature files are placed in the appropriate subdirectory within `src/test/resources`.

2. Feature file syntax: Double-check the syntax of your feature files. Each scenario should start with the `Scenario` keyword, followed by a descriptive name. Ensure that the scenarios are properly formatted and indented. Also, verify that your feature file has the `.feature` extension.

3. Step definitions package: Verify that your step definitions are in the correct package within your project. By convention, step definitions are usually placed in the `stepDefinitions` or `steps` package. Make sure that your step definitions are correctly placed in the corresponding package.

4. Step definitions mapping: Ensure that your step definitions are properly mapped to the steps in your feature files. Each step in the feature file should have a matching step definition method in your step definitions class. The method should use annotations like `@Given`, `@When`, or `@Then` to match the step keyword in the feature file.

5. Cucumber runner class: Check your Cucumber runner class and ensure that it is properly configured. The runner class should specify the correct package for step definitions using the `glue` attribute. Additionally, make sure that the features are specified correctly using the `features` attribute.

By reviewing these aspects and ensuring that your project is properly structured and configured, you should be able to resolve the "0 Scenarios" and "0 Steps" issue in your Selenium Java Cucumber project.

VidTutorAssistant (GPT-4)

Hi @chandinis2526, thank you for tuning in and for your comment. It seems there might be some issue with recognizing your features and steps in your test. Here are a few things to check:

- Take a close look at your feature file name and your step definitions file name. Verify that they are located in the correct directory as mentioned in the video i.e. SRC/test (for step def) and features folder (for feature file).
- Check that your scenarios and step formats match the Given-When-Then format.
- Ensure that the keywords (Given, When, Then and And) in your feature file match the ones in your step definition/glue code. Case sensitive matter, so be sure to be consistent.
- Also, double-check if the Cucumber plugin is properly installed.

If you continue to face issues, please provide more context or detail, and I'll be happy to help further. Keep learning!


@yashrajjadhav383
2023-04-22

Hi Raghav, I am getting this error while executing the cucumber run in login.feature "WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main" Could you please help?

@RaghavPal

Hi Yash
This warning message indicates that you are using a deprecated version of the Cucumber command line interface (CLI) tool to run your tests. To resolve this warning message, you should update your Cucumber version to the latest version and use the new CLI tool.

To update your Cucumber version, you can do the following steps:

Update the Cucumber dependency in your Maven or Gradle build file to the latest version.
Refresh your project dependencies.
Re-run your Cucumber tests using the latest version of the Cucumber CLI.
Once you have updated your Cucumber version, you can use the new CLI tool by replacing the deprecated command:

cucumber-jvm --glue <package> <path to feature files>

with the new command:

java -cp <path to your Cucumber JARs> io.cucumber.core.cli.Main --glue <package> <path to feature files>

This should resolve the warning message you are seeing.

VidTutorAssistant (GPT-4)

Hi @yashrajjadhav383, thanks for reaching out. This issue often crops up when we use an older Cucumber Main class for executing the test cases. The warning suggests that you update to the new Main class, which is "io.cucumber.core.cli.Main". Please change this in your configuration settings and rerun your test cases. I hope this helps! If the issue persists, please provide more information or perhaps a screenshot so I can assist you better. Keep learning and happy testing!


@arbindyadav3673
2023-03-25

very usefull video sir

@RaghavPal

Thanks

VidTutorAssistant (GPT-4)

I'm very glad to hear you found the video useful, @arbindyadav3673! I aim to provide clear and concise tutorials to help you with your coding journey. If you have any further queries or suggestions, please don't hesitate to leave a comment or reach out in the Q&A section. Keep learning and practicing, and happy coding!


@purvidholakia7575
2023-03-06

Hi Raghav, I would first like to thank your for your all short tutorials on each topics, which are really very helpful. I am getting the error "Mar 06, 2023 11:42:12 AM cucumber.api.cli.Main run

WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main" , I searched on google but not found any solution of it. Please help. Thanks.

@RaghavPal

Hi Purvi,
The error message you're seeing indicates that you are using a deprecated version of the Cucumber Main class. To resolve this issue, you can update your Cucumber dependencies and use the new Main class provided by the io.cucumber.core.cli package.

To update your dependencies, you can modify your build.gradle or pom.xml file to use the latest version of the Cucumber libraries. For example, if you're using Gradle, you can update your build.gradle file as follows:
dependencies {
testCompile 'io.cucumber:cucumber-java:7.1.0'
testCompile 'io.cucumber:cucumber-junit:7.1.0'
}

After updating your dependencies, you can update the package for the Main class in your code. For example, if you were previously using cucumber.api.cli.Main, you can update your code to use io.cucumber.core.cli.Main instead.

Once you've made these changes, the warning message should no longer appear and your code should work as expected

VidTutorAssistant (GPT-4)

Hi @purvidholakia7575, thanks for your kind words and for reaching out with your issue. It seems you're using a deprecated Main class, which implies you might be using an outdated version of Cucumber. Update it to io.cucumber.core.cli.Main as suggested by the error message. This change is due to the update in Cucumber's package structure in newer versions. If by any chance you still face any issues after updating, don't hesitate to ask for help! Keep learning and coding!


@CasioArtist
2023-03-09

Hi Raghav ! Very Good Content on Cucumber, it was very useful to me

@RaghavPal

Most welcome

VidTutorAssistant (GPT-4)

Hi @CasioArtist! Thank you for your appreciative words. I am really glad to hear that you found the content on Cucumber useful. If you have any further queries or need help with something else, don't hesitate to drop another comment. Happy learning!


@shanthanbharadwaj5365
2023-06-04

Hi Raghav,I am getting this error while running"The type io.cucumber.core.eventbus.UuidGenerator cannot be resolved. It is indirectly referenced from required .class files" Can you please help me on this. Provided JUnit and cucumber Junit dependencies in pom.xml file. Selected cucumber JVM:JUnit4 and JUnit from Maven central.

@RaghavPal

Hi Shanthan
The error message "The type io.cucumber.core.eventbus.UuidGenerator cannot be resolved. It is indirectly referenced from required .class files" means that your code is trying to use a class called `UuidGenerator`, but that class cannot be found. This can happen for a few reasons:

1. The class is not in your classpath
2. The class is in your classpath, but it is not compiled
3. The class is in your classpath, but it is not imported

To fix this error, you need to make sure that the `UuidGenerator` class is in your classpath and that it is compiled. You can do this by following these steps:

1. Check that the `cucumber-core` JAR file is in your classpath. You can do this by opening the `build.gradle` file for your project and looking for the `dependencies` section. The `cucumber-core` JAR file should be listed in this section.
2. If the `cucumber-core` JAR file is in your classpath, but it is not compiled, you need to compile it. You can do this by running the following command:

```
gradlew cucumber-core:compile
```

3. If the `cucumber-core` JAR file is in your classpath and it is compiled, but it is not imported, you need to import it. You can do this by adding the following import statement to the top of your code:

```
import io.cucumber.core.eventbus.UuidGenerator;
```

Once you have made sure that the `UuidGenerator` class is in your classpath, compiled, and imported, the error should go away.

Here are some additional things to keep in mind:

* The `cucumber-core` JAR file is not always included in the default Java classpath. If you are getting this error, you may need to add the `cucumber-core` JAR file to your classpath manually.
* The `UuidGenerator` class is not always required for Cucumber tests. If you are not using the `UuidGenerator` class in your tests, you can safely ignore this error.

VidTutorAssistant (GPT-4)

Hi @shanthanbharadwaj5365, it appears you're experiencing issues with "io.cucumber.core.eventbus.UuidGenerator". Cucumber might not be finding the needed dependencies because there might be a version conflict between your cucumber JUnit and the JUnit from Maven central. I suggest trying to update all your dependencies to their latest stable versions. Also, ensure that you've saved your pom.xml file after inserting the dependencies, prompting Maven to download the necessary files. If the issue persists, consider deleting the .m2/repository folder and let Maven download all the dependencies again. I hope this helps resolve your issue! Keep coding and don't hesitate to reach out if you have further questions. Happy learning!


@virulekkihal5537
2023-03-19

Awesome πŸ‘

@RaghavPal

Thanks

VidTutorAssistant (GPT-4)

Thank you so much, @virulekkihal5537! I'm glad you found the session helpful. I encourage you to keep practicing and dive deeper into Java programming. Should you face any issues, feel free to comment, and I'll try my best to assist you. Thanks for watching and happy coding to you!