For numerous several years, when it came to automating website UI screening, Selenium was the king. And it is risk-free to say it nevertheless is! As a broadly known and tested automation tests device, it is normally a default preference for numerous computer software initiatives. But does it signify one particular should not explore other systems and frameworks? Of training course not! In this article, I will discuss the primary points behind using Protractor and demonstrate how to established it up for seamless use with Cucumber and Page Object Model.
To get started setting up the challenge, 1st, you will need to install node.js. Soon after setting up it on your equipment, you can verify that the installation was profitable by typing in ‘node -v’ in the terminal. While you are at it, in the same put you can also verify the Node Offers Supervisor, typing in ‘npm – v’. Then, type in ‘npm put in -g protractor’ and verify its prosperous set up with ‘protractor –version’. Just in scenario, you can update the driver from time to time by applying the “web driver-supervisor update” command.
Our subsequent action will be placing up the IDE for snug work. First, in Visible Studio Code set up the “Cucumber (Gherkin) total support” extension. After which is completed, we have to just take treatment of our dependencies. In our project’s deal.json file we’ll will need to involve chai and chai-as-promised for assertions, cucumber, and protractor – all in the dependencies area. In devDependencies, we’ll require protractor-cucumber-framework to obtain the intention we’re striving for.
To have convenience and clarity within just the growth method, a person of the features that offer it is the potential to swiftly glimpse up what code is executed behind just about every gherkin phase. To realize that in a Protractor task, we’ll need to specify Cucumber alternatives in the conf.js file. What is needed is the path to the steps folder.
Then, in the configurations.json file, we’ll will need to specify the paths to folders made up of action definitions and techniques that are executed at the rear of them. We can do this in the subsequent fashion:
When we do this, we can quickly navigate by way of the undertaking by clicking the move/definition/system/element specified in the code with a CTRL or CMD button pressed. It is a very simple detail, but it can considerably improve productiveness and decrease the time invested on building or debugging checks!
Our upcoming premise that we require to deal with is working the checks by tags. Though adding a tag to a characteristic file is quite easy, the section exactly where these are run requires providing a path to Cucumber Function files in the conf.js file.
As you can observe in the earlier mentioned piece of code, the cucumberOpts part in the conf.js file requires a variable named ‘tags’ as an vacant listing.
When we’re at it, it is vital to point out that the conf.js file requires to have a segment in which we specify the Cucumber as our screening framework:
The overall structure of the automated screening challenge established in Web page Item Product is similar throughout technologies. An overview for Protractor can be observed below:
The moment you make all the vital files and finish the configuration, it is time to produce the assessments them selves.
Since we’re functioning in BDD framework, let us get started with a easy Attribute File with a basic state of affairs concentrating on verifying a Registration form (with a tag for jogging it afterwards)
At the time that is carried out, we can specify what happens in each individual step in /methods/registration.js:
In that file, we first specify the route to the file made up of methods that are likely to be known as in each and every of the stage definitions. Then we’re calling assertion libraries and location up timeouts.
Step definition implementation is very clear-cut the Cucumber keyword precedes a regex and a parameter the body of a action phone calls a process from /internet pages/registration.js file. Normally, one stage phone calls for just a person method but test techniques could be much more intricate if want be. Discover that if a method returns a Boolean worth, we are invoking assertion at the amount of a move definition (line 23).
In the/internet pages/registration.js file, we require to specify a locator dictionary for features that we’re going to interact with. You can do this in the next manner:
Be sure to be aware the selectors made use of for locating the factors you can use many out-of-the-box approaches for finding elements in Protractor, which have been thoroughly explained in the formal Protractor Information (url)
The exact goes for techniques made use of to interact with features:
(PS. Do not shop your login qualifications in the examination automation code… The over is just for demonstration purposes)
What occurs higher than is that we’re employing strategies that we have named in /techniques/registration.js file, working with the factors we have place in the locator dictionary (highlighted in gentle blue) and interacting with them employing Protractor procedures (highlighted in purple).
Then it is time to operate the checks. In VS Code, open a new terminal window and hit the “web driver-supervisor start” command. Webdriver need to be up and jogging now.
To run the test you have created and tagged accordingly, all you require to do now is you have to open up yet another new terminal window in VS Code and enter the command:
protractor protractor.conf.js –cucumberOpts.tags=’@smoke1′ – tagging the desired feature appropriately.
And there you have it! Now you have a ready, set up Protractor tests framework integrated with Cucumber, Webpage Object Product which you can run with the assistance of tags. If you want to locate out a lot more about Protractor, I really encourage you to go to the Protractor web-site, which has complete documentation with code examples listed here.