For a lot of yrs, when it came to automating website UI screening, Selenium was the king. And it is safe and sound to say it still is! As a broadly recognized and established automation screening tool, it is often a default selection for quite a few program initiatives. But does it signify a single should not investigate other systems and frameworks? Of class not! In this report, I will examine the major points at the rear of using Protractor and make clear how to established it up for seamless use with Cucumber and Web page Object Design.
To start off environment up the job, initial, you’ll want to install node.js. Following putting in it on your equipment, you can verify that the set up was effective by typing in ‘node -v’ in the terminal. Although you are at it, in the exact spot you can also verify the Node Packages Manager, typing in ‘npm – v’. Then, form in ‘npm put in -g protractor’ and verify its productive set up with ‘protractor –version’. Just in situation, you can update the driver from time to time by utilizing the “web driver-supervisor update” command.
Our next move will be placing up the IDE for at ease function. First, in Visible Studio Code install the “Cucumber (Gherkin) full support” extension. When which is carried out, we have to get treatment of our dependencies. In our project’s deal.json file we’ll will need to incorporate chai and chai-as-promised for assertions, cucumber, and protractor – all in the dependencies segment. In devDependencies, we’ll want protractor-cucumber-framework to achieve the aim we’re striving for.
To have comfort and clarity in the progress method, just one of the characteristics that provide it is the means to promptly seem up what code is executed driving just about every gherkin stage. To reach that in a Protractor challenge, we’ll want to specify Cucumber options in the conf.js file. What is important is the path to the steps folder.
Then, in the options.json file, we’ll will need to specify the paths to folders made up of stage definitions and solutions that are executed guiding them. We can do this in the pursuing fashion:
When we do this, we can quickly navigate through the project by clicking the stage/definition/method/ingredient specified in the code with a CTRL or CMD button pressed. It’s a basic matter, but it can considerably improve productivity and lessen the time spent on developing or debugging assessments!
Our up coming premise that we need to have to deal with is managing the checks by tags. Even though introducing a tag to a element file is rather simple, the aspect in which these are operate calls for providing a path to Cucumber Element documents in the conf.js file.
As you can observe in the previously mentioned piece of code, the cucumberOpts portion in the conf.js file requires a variable named ‘tags’ as an vacant record.
Though we’re at it, it is crucial to point out that the conf.js file desires to have a part in which we specify the Cucumber as our testing framework:
The general composition of the automated screening job developed in Site Object Product is related throughout systems. An overview for Protractor can be noticed below:
The moment you create all the vital documents and complete the configuration, it is time to produce the exams them selves.
Given that we’re operating in BDD framework, let’s begin with a uncomplicated Function File with a straightforward circumstance concentrating on verifying a Registration kind (with a tag for managing it later)
As soon as that’s carried out, we can specify what comes about in just about every phase in /methods/registration.js:
In that file, we initially specify the path to the file made up of strategies that are heading to be called in every single of the phase definitions. Then we’re calling assertion libraries and setting up timeouts.
Action definition implementation is quite easy the Cucumber search phrase precedes a regex and a parameter the entire body of a phase calls a technique from /pages/registration.js file. Ordinarily, one particular step phone calls for just a single approach but test methods could be much more intricate if have to have be. Discover that if a process returns a Boolean benefit, we are invoking assertion at the degree of a action definition (line 23).
In the/pages/registration.js file, we have to have to specify a locator dictionary for elements that we’re likely to interact with. You can do this in the subsequent method:
Remember to note the selectors employed for finding the factors you can use different out-of-the-box techniques for locating components in Protractor, which have been thoroughly explained in the official Protractor Information (backlink)
The very same goes for techniques used to interact with aspects:
(PS. Do not retailer your login credentials in the take a look at automation code… The higher than is just for demonstration needs)
What comes about earlier mentioned is that we’re utilizing strategies that we have identified as in /techniques/registration.js file, applying the things we have put in the locator dictionary (highlighted in mild blue) and interacting with them working with Protractor methods (highlighted in purple).
Then it is time to run the checks. In VS Code, open a new terminal window and strike the “web driver-supervisor start” command. Webdriver should really be up and running now.
To operate the take a look at you’ve prepared and tagged accordingly, all you need to do now is you have to open up one more new terminal window in VS Code and enter the command:
protractor protractor.conf.js –cucumberOpts.tags=’@smoke1′ – tagging the wished-for attribute appropriately.
And there you have it! Now you have a prepared, set up Protractor testing framework built-in with Cucumber, Website page Object Product which you can operate with the help of tags. If you want to discover out a lot more about Protractor, I encourage you to go to the Protractor site, which consists of in depth documentation with code illustrations listed here.