Setting Up a Testing Project in Protractor with Cucumber and Page Object Model – Grape Up

[ad_1]

For quite a few decades, when it came to automating world wide web UI screening, Selenium was the king. And it is harmless to say it even now is! As a extensively regarded and established automation tests tool, it is usually a default choice for quite a few software assignments. But does it necessarily mean 1 should not take a look at other technologies and frameworks? Of class not! In this report, I will examine the major details behind making use of Protractor and clarify how to set it up for seamless use with Cucumber and Website page Item Model.

The principal level guiding applying Protractor is that it was created generally for tests Angular apps. Given that Angular has its personal individual attributes – techniques, functions, and synchronization, Protractor addresses people to make testing this kind of apps easier and additional reliable. It is worthy of mentioning that Protractor is a wrapper in excess of webdriver.js – the official JavaScript implementation of Selenium Webdriver. What this implies is that in the course of tests improvement distinct Angular elements can be achieved with out-of-the-box take a look at framework techniques and it however looks identical to what would have been coded in a typical Selenium task. On top of that, Protractor is capable of synchronizing with Angular, which also aids with the security of the tests.

The assumptions for placing up the undertaking ended up equivalent to prior endeavors with test automation tasks – the construction has to be obvious (Webpage Item Design) and take a look at scripts have to be distinct and easy to understand, even for non-specialized staff members (Cucumber and Gherkin). The choice of programming language fell on JavaScript considering that Protractor is a node.js software and the other practical option, TypeScript, would demand a bit additional coding. This time the project will benefit from Visible Studio Code as IDE.

To commence placing up the job, 1st, you’ll will need to install node.js. Immediately after putting in it on your equipment, you can confirm that the set up was productive by typing in ‘node -v’ in the terminal. When you’re at it, in the exact put you can also verify the Node Deals Manager, typing in ‘npm – v’. Then, type in ‘npm install -g protractor’ and confirm its productive installation with ‘protractor –version’. Just in situation, you can update the driver from time to time by using the “web driver-supervisor update” command.

Our next step will be setting up the IDE for at ease get the job done. First, in Visual Studio Code put in the “Cucumber (Gherkin) total support” extension. After that is carried out, we have to take care of our dependencies. In our project’s package deal.json file we’ll need to have to incorporate chai and chai-as-promised for assertions, cucumber, and protractor – all in the dependencies part. In devDependencies, we’ll want protractor-cucumber-framework to attain the goal we’re striving for.

To have consolation and clarity inside the progress process, 1 of the features that give it is the skill to swiftly seem up what code is executed driving just about every gherkin phase. To reach that in a Protractor undertaking, we’ll have to have to specify Cucumber choices in the conf.js file. What is essential is the route to the ways folder. 

Then, in the settings.json file, we’ll need to specify the paths to folders that contains move definitions and methods that are executed driving them. We can do this in the subsequent fashion: 

When we do this, we can effortlessly navigate by way of the job by clicking the action/definition/strategy/element specified in the code with a CTRL or CMD button pressed. It is a basic matter, but it can drastically boost productivity and reduce the time put in on creating or debugging checks! 

Our future premise that we require to deal with is operating the assessments by tags. Even though adding a tag to a element file is really uncomplicated, the component in which these are run needs giving a route to Cucumber Feature information in the conf.js file. 

As you can notice in the over piece of code, the cucumberOpts area in the conf.js file requires a variable named ‘tags’ as an empty record. 

Whilst we’re at it, it is vital to stage out that the conf.js file requires to have a segment in which we specify the Cucumber as our tests framework: 

The over-all structure of the automatic testing project established in Page Object Design is related across technologies. An overview for Protractor can be observed underneath:  

The moment you generate all the required documents and complete the configuration, it is time to generate the checks on their own. 

Because we’re functioning in BDD framework, let us get started with a very simple Attribute File with a very simple scenario concentrating on verifying a Registration type (with a tag for working it afterwards) 

When that’s completed, we can specify what occurs in just about every move in /steps/registration.js: 

In that file, we to start with specify the path to the file containing approaches that are heading to be called in each individual of the stage definitions. Then we’re contacting assertion libraries and placing up timeouts. 

Action definition implementation is quite uncomplicated the Cucumber key word precedes a regex and a parameter the human body of a action phone calls a technique from /internet pages/registration.js file. Normally, 1 move calls for just a single approach but test techniques could be a lot more intricate if will need be. Notice that if a strategy returns a Boolean worth, we are invoking assertion at the amount of a step definition (line 23). 

 In the/webpages/registration.js file, we need to specify a locator dictionary for elements that we’re going to interact with. You can do this in the subsequent fashion: 

You should be aware the selectors made use of for locating the components you can use different out-of-the-box approaches for finding elements in Protractor, which have been extensively explained in the official Protractor Guidebook (hyperlink

The exact same goes for procedures made use of to interact with aspects:

(PS. Do not shop your login credentials in the check automation code… The above is just for demonstration uses) 

What comes about higher than is that we’re implementing approaches that we have named in /techniques/registration.js file, making use of the factors we’ve put in the locator dictionary (highlighted in light-weight blue) and interacting with them working with Protractor procedures (highlighted in purple). 

Then it is time to run the checks. In VS Code, open a new terminal window and strike the “web driver-manager start” command. Webdriver really should be up and functioning now. 

To operate the test you’ve written and tagged accordingly, all you require to do now is you have to open an additional new terminal window in VS Code and enter the command:  

protractor protractor.conf.js –cucumberOpts.tags=’@smoke1′ – tagging the preferred element appropriately. 

And there you have it! Now you have a completely ready, set up Protractor tests framework integrated with Cucumber, Web site Object Product which you can operate with the support of tags. If you want to uncover out additional about Protractor, I persuade you to go to the Protractor web page, which consists of in depth documentation with code illustrations listed here.

[ad_2]

Source backlink