DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Externalize Microservice Configuration With Spring Cloud Config
  • What BDD Is and Why You Need It: Java and Behavior Driven Development
  • How to Set up TestCafe and TypeScript JavaScript End-to-End Automation Testing Framework From Scratch
  • WebDriverIO Integration With Cucumber

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Building a Real-Time Change Data Capture Pipeline With Debezium, Kafka, and PostgreSQL
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Protractor With Cucumber

Protractor With Cucumber

Learn how to configure the Protractor testing framework to use with the Cucumber Behavior-Driven Development framework for testing AngularJS applications.

By 
Rathnadevi Manivannan user avatar
Rathnadevi Manivannan
·
Jul. 11, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
27.5K Views

Join the DZone community and get the full member experience.

Join For Free

Overview

Protractor, an end-to-end testing framework, supports Jasmine and is specifically built for AngularJS applications. It is highly flexible with different Behavior-Driven Development (BDD) frameworks such as Cucumber. It allows writing specifications based on the behavior of the application. The greatest feature of Protractor is that it waits until a page is loaded and limits the number of waits and sleeps used in the testing suite.

Cucumber, a BDD framework, is used for web applications for performing acceptance tests. It provides a higher-level view of the testing process of the suite. In this blog, let us discuss configuring Protractor with the Cucumber framework and passing the input parameters by using the property file.

Pre-Requisites

  • Install Java Development Kit.
  • Install Node.js (latest version).
  • Install Protractor using the below command:
npm install -g protractor
  • Check the version of Protractor using the below command:
protractor –version
webdriver-manager update
  • Install Cucumber using the below command:
npm install -g cucumber
npm install --save-dev protractor-cucumber-framework

Use Case

We will discuss passing the input parameter by using the property file in Protractor with the Cucumber framework.

Setting Up a Configuration in Protractor With Cucumber

Cucumber Configuration

To configure Cucumber, use the below command:

cucumberOpts: {
 require: 'features/step_definitions/*.js',
 tags: false,
 format: ['pretty'],
 profile: false,
 'no-source': true,
 }

Running Scripts in a Default Browser

To run a script in a default browser, use the below command:

capabilities: {
 'browserName': 'chrome'
 },

Running Scripts in Other Browsers

To run a script in other browsers, use the below command:

capabilities:[ {
 'browserName': 'Firefox'
 },{
 'browserName': 'safari'
 }
 ]

Viewing the Cucumber.conf.js File

The above Cucumber configuration can be viewed in a single JS file, as shown below:select

Setting Up Feature Files in Protractor With Cucumber

The sample feature file used in this use case is as follows:

  • Feature: Angular Application Testing.
  • Scenario: Protractor and Cucumber Test.
  • Given: Open the Application Login page.
  • When: Enter the valid credentials.
  • Then: Get the stock price of the given ticker.

Configuring the Property File

To configure the property file, perform the following:

  • Install properties reader using the below command:
npm install properties-reader
  • Create a prop.properties file.
  • Configure property file with first_test.JS using the below command:
var propertiesReader = require('properties-reader');
var inputproperties = propertiesReader(/path/properties_file/prop.properties');
  • Pass the below sample parameter as input:
var website = inputproperties.get('Website');

Executing Test Scripts in Protractor With Cucumber

To execute the test script in Protractor, perform the following:

  • Before running the test, start the Selenium server using the below command:
 webdriver-manager start
  • Open another command prompt and run your test using the below command:
 protractor cucumber.conf.js

select

Viewing Test Results

Open the results.json file to view the test result in JSON format, as shown in the below diagram:select

Conclusion

In this blog, we discussed installing and configuring Protractor with the Cucumber framework. We learned about the basic structure of the feature file and about passing the input parameters by using the property file in Protractor with the Cucumber framework.

Cucumber (software) file IO Command (computing) Testing application Framework Property (programming) Use case Behavior-driven development Test script

Published at DZone with permission of Rathnadevi Manivannan. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Externalize Microservice Configuration With Spring Cloud Config
  • What BDD Is and Why You Need It: Java and Behavior Driven Development
  • How to Set up TestCafe and TypeScript JavaScript End-to-End Automation Testing Framework From Scratch
  • WebDriverIO Integration With Cucumber

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!