Tutorial 19 – Integrate Cucumber with Selenium – Part 6
What you will Learn :
Continue with LoginPageSteps.java step definition file
Continue with LoginPageSteps.java step definition file
This is continuation of previous tutorial.
So far we have written the below methods in our step definition file
We would next take up the below method
Remember that the title of the home page that we are talking about here is the title that we get when we sign-in with username/password
We have already mentioned this title in our feature file, see below
Now, technically speaking, the step numbers 5 and 17 in our feature file above perform the same thing, get the title of the page. So in line number 17, we can remove the word ‘home’, so now we have
So we can now remove the below method from our step definiton file
So let us remove the method, see below
Now, for the two steps (5 and 17) seen below, we can create one common step definition
To do that let us remove the word ‘login’ from the below method in our step definition file, see below
So we can now use the below common method in our step definition file to get the title of login page as well as the home page
Now the question is, how to verify line number 18 in our feature file, see below?
This would be verified using the same common method that we have already written on our step definition file, see below
You must have noticed that we use @Then to write assertions. However @When is for writing actions and @Given is for writing pre-condition
The steps would be executed in the same order that we have written in our feature file
Below is complete step definition code
In our next tutorial, we would write our Runner file and conclude our page object framework design model using cucumber.
Thank you for reading!