Integrate_CucumberBDD_With_Selenium-Part4

Tutorial​​ 17​​ ​​ ​​ ​​ Integrate​​ Cucumber​​ with​​ Selenium​​ – Part​​ 4

What you will Learn :

  • LoginPage class

  • By Locators​​ (Object repository)

  • Constructor of page class

  • Page actions

LoginPage​​ class​​ 

For every page, we will create a separate page class.​​ Let us start by creating Loginpage class.

Inside the LoginPage class, we have to peform the below 3 actions:

  • We have to create​​ the ‘By’ locators

  • We have to​​ create​​ a​​ constructor

  • We have to create page actions

We will be using the concept of encapsulation – the locators would be private and the page actions or page methods will be public in nature.

Also, every class will have its private WebDriver

By Locators​​ (Object repository)

We will now create the private ‘By’ locators. The first one would be email id

Let us launch our AUT and inspect email id field​​ http://automationpractice.com/index.php?controller=authentication&back=my-account

Notice that the id is ‘email’​​ 

So can write the same id as seen below

Similarly for password

Similarly inspect the Sign in button

So we can write

Next, let us inspect ‘Forgot your password’ link, see below​​ 

So we can write

Constructor of page class

We wil now write the constructor of our page class. The constructor name will remain same as the class name. This constructor says that,​​ 

“you give me the WebDriver and I will give the same WebDriver to this particular driver​​ ​​ ”

So

Page actions

Page actions are the features or the behaviour of the page in the form of methods. The first​​ action​​ that we are going to write is getLoginPageTitle().​​ We will use the in-built selenium method getTitle() to get the page title.​​ This method will return us a string​​ 

Our next method will be to find whether ‘Forgot password link” is present

Note that we have already defined the ‘forgotPwdLink’ locator in line#13, we are simply re-using it in our method.

Further, we can use isDisplayed() method that returns a boolean, so we can write

Our next method would be to enter username in the ‘Email address’ field, see below. In the method argument, we will send the username (which is a string). The same username would then be send to the ‘sendkeys’ method. In the ‘By Locator’, we pass the ‘emailId’ locator​​ 

Now,​​ from where the ‘username’ would be coming? It would be coming from step definition file which in turn gets the username from feature file, see below

Similarly​​ we will write a method​​ for entering the password

Next method would click the ‘Sign In’ button. We use the click() method to click the button

So we have​​ created 5 methods and we have 4​​ locators.​​ 

Below is the complete​​ LoginPage java​​ code that we have written so far:


Look at the Loginpage.feature file that we created earlier. We have written​​ page actions​​ for all the scenarios:​​ 

We will continue in our next tutorial.​​ 

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 10th Nov 2024