Javatpoint Logo
Javatpoint Logo

How to create Selenium Maven Project in Eclipse?

Before creating Selenium Maven testing Project for cucumber testing in Eclipse, first we must have the following dependencies in our computer system:

  • Java
  • Eclipse
  • Cucumber Eclipse Plugin
  • Web driver Java Client
  • Selenium

Here we are creating a Maven project to test the registration feature through the data table:

Step 1

In order to create a Maven project first, Go to File → New → Others → Maven → Maven Project → Next.

After clicking the Next, a window will prompt. In this window, we need to provide group Id (group Id identifies the project uniquely across all projects). We have provided group Id as "com.javatpoint." You can give any name on your own choice.

Also, provide artifact Id (artifact Id represents the name of the project). We have provided artifact Id as "CucumberTesting." You can give any name on your own choice.

Click on Finish.

Step 2

Open pom.xml by using the following steps:

  • Go to package explorer on the left side of the Eclipse window.
  • Expand the project which is created for data table testing in cucumber then select its pom.xml file.
  • Now open pom.xml and add the following dependencies.

Add dependency inside pom.xml for Selenium: This will indicate to Maven, which Selenium jar files will be downloaded from the central repository to the local repository.

  • In pom.xml file, create a dependencies tag (<dependencies></dependencies>), inside the project tag.
  • Now, inside the dependencies tag, create a dependency tag (<dependency></dependency>), and provide the following information within it.

Step 3

Add dependency inside pom.xml for Cucumber-Java: It will indicate to Maven; which Cucumber files will be downloaded from the central repository to the local repository.

  • Now, inside the dependencies tag (<dependencies></dependencies>), create a dependency tag (<dependency></dependency>), and provide the following information within it.

Step 4

Add dependency for Cucumber-Junit: It will indicate to Maven, which Cucumber JUnit files will be downloaded from the central repository to the local repository.

  • Now, inside the dependencies tag (<dependencies></dependencies>), create a dependency tag (<dependency></dependency>), and provide the following information within it.

Step 5

Add dependency for Junit: It will indicate to Maven, which JUnit files will be downloaded from the central repository to the local repository.

  • Now, inside the dependencies tag (<dependencies></dependencies>), create a dependency tag (<dependency></dependency>), and provide the following information within it.

After completing all dependencies, verify binaries.

  • Once pom.xml is completed successfully, then save it.
  • Go to your Project → Clean - It can take a few minutes.

Now, create a package named dataTable under src/test/java folder of your project.

Step 6

Create a Feature file:

  • Inside the package dataTable, create a feature file, named dataTable.feature.
  • Inside the feature file, write the following text.
Feature - Data table
Verify that the new user registration is successful after passing correct inputs.
Scenario:
Given the user on the user registration page.
When user enter invalid data on the page
| Fields                 | Values              |
| First Name             | Preeti              |
| Last Name              | Sharma              |
| Email Address          | someone@gmail.com   |
| Re-enter Email Address | someone@gmail.com   |
| Password               |PASSWORD             |
| Birthdate              | 02                  |
Then the user registration should be successful.
  • Save this file.

Step 7

Creation of the step definition file:

  • Create the step definition file inside the package dataTable with extension ".java" and named as 'dataTable.java.'
  • Inside the step definition file, write the following code.

Step 8

After creating the step definition file now, we need to create a runner class file.

  • Create a runner class inside the package dataTable with extension ".java" and named as RunTest.java.
  • Inside runner class RunTest.java, write the following code.

Save this file, and run the test by using the following options:

  • Select the runner class i.e., RunTest.java file inside your package.
  • Right-click on it, and select the option, Run as → JUnit.

If your execution is successful, you will observe the following things:

  • JavaTpoint website gets loaded.
  • We will see the home page or the page provided by the respective website.
  • Data can be entered on the registration page.
  • Submit button will be clicked.





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA