Integrate_CucumberBDD_With_Selenium-Part5

Tutorial​​ 18​​ ​​ ​​ ​​ Integrate​​ Cucumber​​ with​​ Selenium​​ – Part​​ 5

What you will Learn :

  • LoginPageSteps.java step definition file

LoginPageSteps.java step definition file​​ 

We will next go to our step definition file LoginPageSteps.java​​ and call all our methods of LoginPage.java that we had written in previous tutorial.

So to that, let us create an object of LoginPage class, see below

Let us import LoginPage class​​ 

 

Notice below that we still have one error because we have not yet defined the LoginPage() constructor

Recall below that we had defined a constructor for LoginPage.java

Now the question is, from where will we get this driver from?​​ 

We will get the driver from our getDriver() method that we had created in DriverFactory.java, see below

So​​ let us call DriverFactory.getDriver() method in the LoginPage constructor​​ ​​ 

So at runtime, whatever driver instance is going on, the getDriver() method will give us that particular driver (thread local concept that we have already studied in previous tutorials)

Please remember that, during runtime, ApplicationHooks.java gets executed before LoginPageSteps.java. In the hooks file, the driver is getting initialized

Once initialized,​​ we get​​ the same driver in​​ LoginPageSteps.java. So getDriver() method is used to get the driver at the runtime​​ and ‘set’ methods are used to set the chromebrowser/firefox browser etc ​​ 

Now you will be able to relate things better.

So, coming back to our LoginPageSteps.java

Let us first launch the url

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

So let us write same over here

Now using the loginPage reference, we can call all the methods of LoginPage class

So, we will​​ get the page title when the user is on login page

This method returns us a String, so we will catch this​​ title in a variable and also print the title

We will now write a​​ junit assertion​​ to assert whether the expected page title matches actual page title. First of all, import org.junit.Assert

In the method argument​​ (see below), let us change ‘string’ to ‘expectedPageTitle’

Next​​ we will write assertion

Next, we will call the ‘contains’ method on pageTitle

We can now pass the same ‘expectedPageTitle’ inside the contains() method

Remember​​ that in our LoginPage.feature file,​​ the​​ expected​​ page title​​ is mentioned​​ ‘Login - My Store’

Now if you notice below, there is an error on line#27 because pageTitle variable is defined in the previous method (line 21)

To resolve this error,​​ let us define pageTitle variable at class level, see below. the same variable is now used at line#22, 28

Save the file.​​ 

Next, we would look at ‘forgot your password link’ method. We can simply call the method that we had created in LoginPage class

Now, this method returns boolean​​ (True/false)​​ as seen below

So we will directly write an assettion over here. So, if the method ‘isForgotpwdLinkPresent’ returns ‘True’, the test will pass, otherwise it will fail

 

We will next take up​​ method to enter username

Let us​​ first​​ change ‘string’ to ‘username’

We can now call the method

Similarly we can enter password

Next we have

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 31st DEC 2024