In our previous article, we talked about how to use Cucumber and Selenium to do web application testing in a behavior-driven way. Now, we'll dig deeper into integrating Cucumber with Selenium and the necessary system requirements for setting up a Selenium Maven testing project in Eclipse.
It's important to follow the key steps for configuring the project and running it efficiently to ensure seamless automation testing.
Integrate Cucumber with Selenium
System requirements
Before creating the Selenium Maven testing Project for cucumber testing in Eclipse, we must have the following dependencies in our computer system:
Set up JDK on your system (JDK 1.8 or the latest version)
Download Apache maven in windows
Install the cucumber plugin - from Eclipse marketplace. – Go to Eclipse -> Help -> Install new software and search for Cucumber Eclipse plugin
Steps to set up cucumber – Selenium project.
Step 1: To create a Maven Project in Eclipse, click on New → Project → In the wizard, select Maven Project.
Step 2: On the new Maven Project pop-up, select the checkbox to create your project at the default location OR you can also browse and set a new location of your choice. Click on Next to proceed.
Step 3: On the next screen it will retrieve all the archetypes, please search for maven-archetype-quickstart. It will generate the maven sample project with proper structure.
Step 4: In the next screen, you will have to mention a Group ID and Artifact ID of your own choice; this is the name of your Maven project. Once you click the Finish button, a Maven project will be created in Eclipse with the structure highlighted in the image.
We have apom.xml file created in your Maven project. This file consists of the Group ID and Artifact ID which we have added while creating the project. By default, it consists of dependency for JUnit.
Now, to build a Selenium-Cucumber framework for us to work with, we need to add a dependency for Selenium and Cucumber in pom.xml, which is somewhat similar to adding JAR files. We will be needing dependencies of the following:
Selenium Java - https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java.
Cucumber-core
Cucumber-java
Cucumber-junit
Cucumber-JVM-deps
Cucumber-reporting
We can download all the dependencies from https://mvnrepository.com/search?q=Cucumber and add the required dependency in pom. XML file let's take a simple example of selenium java. Copy the highlighted portion and paste it into the pom.xml file.
Now update the project:
Right-click on Project name - > Maven - > Update project all the dependencies will be added to the project level. Verify the added jar in the Maven dependency section.
Similarly, we can add all the jars in the pom.xml file. After adding the relevant jars, we can create a sample feature file and step definition to run the cucumber project. The sample feature file is depicted in the Figure, we can add a sample step definition file mapped to the feature file.
Execution
We can execute the code as a maven build.
Steps: Right-click on Project -> Run as -> Select option as maven build.
Then in the dialog box select run configurations as depicted in the image.
Takeaway
This article provides a comprehensive guide on how to integrate Cucumber with Selenium and set up a Selenium Maven testing project in Eclipse. It includes the necessary system requirements, steps to create a Maven project, and how to add dependencies for Selenium and Cucumber. Additionally, it provides an example of a feature file and step definition file and explains how to execute the code as a Maven build. If you liked this series, do let me know in the comments and follow us on LinkedIn for more insights on Automation Testing.
Commentaires