Integrate_CucumberBDD_With_Selenium-Part1

Tutorial​​ 14​​ ​​ ​​ ​​ Integrate​​ Cucumber​​ with​​ Selenium​​ – Part 1

What you will Learn :

  • Add Selenium-java​​ dependency in pom.xml

  • Add WebDriverManager dependency

  • Add​​ ExtentReports Cucumber6 Adapter​​ dependency

  • Create​​ Login page feature and it’s step definition

  • Add page layer

  • Create DriverFactor class​​ 

  • Create config.properties file

  • AUT walkthrough​​ and create feature file

  • Create Step definition file

Add Selenium-java​​ dependency in pom.xml

We will now integrate cucumber with Selenium so that we can automate end-to-end cucumber scenario.​​ 

Go to the url​​ https://mvnrepository.com/search?q=selenium​​ and search for ‘selenium’. You would find ‘Selenium Java’ in search results

Click ‘Selenium Java’. The below page would come up

Click the stable version link 3.141.59, the below page would come up

Uncheck the checkbox ‘Include comment with link to declaration’, you will see as below

Mouse click the dependency, it gets copied as seen below​​ 

Paste it inside the dependency tag in pom.xml, see below

You can press​​ Ctrl+Shift+F to format the pom.xml file

 

Save the pom.xml file. This would start downloading the dependencies.

Add WebDriverManager dependency

WebDriverManager library is used to automate the management of the drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver. We don't have to download the binaries required for different browsers (Chrome, IE etc).

Go to the url​​ https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager​​ 

Click the stable version link 4.3.1

Copy the dependency and paste it in pom.xml

Save the pom.xml file.

Add ExtentReports Cucumber6 Adapter​​ dependency

Go to​​ 
https://mvnrepository.com/artifact/tech.grasshopper/extentreports-cucumber6-adapter​​ 

Click the stable version link 2.7.0

Copy the dependency and paste it in pom.xml

Add the <scope> line as seen below

Save the pom.xml file.

Create​​ Login page feature and it’s step definition

Create a blank LoginPage.feature file under src/test/java/Features

Create a blank LoginPageSteps.java step definition file under src/test/java/StepDefinitions

Add page layer

Now we will add page layer under src/main/java

Create a package ‘pages’ under src/main/java​​ 

Create LoginPage class inside this package

Create DriverFactor class

Create package ‘factory’ under src/main/java and create DriverFactory.java under this package


Create config.properties file

Create package ‘config’ under src/test/resources and create a file config.properties

Add ‘browser’ property as shown below

AUT walkthrough​​ and create feature file

Launch​​ 
http://automationpractice.com/index.php?controller=authentication&back=my-account​​ ​​ 

Let us find the page title:

Right click > View Page Source > search for ‘title’​​ 

Notice the​​ page title​​ below

​​ 

So let us write our first scenario

Next​​ we have ‘Forgot your password’ link

So below is our 2nd​​ scenario

Next, on the home page, create your own account by entering an email address and click ‘Create an account’

Once you create your own account, login by entering your email address and password

Click ‘Sign in’

Once you sign in, below page comes up

Let us find the page title

​​ So our 3rd​​ scenario becomes

Create Step definition file

Let us run the feature file and copy/paste the missing steps in our step definition file

So we have created the basic building blocks. In our next tutorial, we will write a utility in our DriverFactory.java

Thank you​​ for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 31st DEC 2024