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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

  • Reusable Operational Playbooks With Agent Skills
  • Why Successful LLM Demos Fail in Production
  • Containment Is a Feature: Sandboxing, Egress Control, and Provenance for Autonomous Agents
  • How Has AI Impacted Code Obfuscation?

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Jul. 11, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
27.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook