Skip to content

Modus-Logo-Long-BlackCreated with Sketch.

  • Services
  • Work
  • Blog
  • Resources

    OUR RESOURCES

    Innovation Podcast

    Explore transformative innovation with industry leaders.

    Guides & Playbooks

    Implement leading digital innovation with our strategic guides.

    Practical guide to building an effective AI strategy
  • Who we are

    Our story

    Learn about our values, vision, and commitment to client success.

    Open Source

    Discover how we contribute to and benefit from the global open source ecosystem.

    Careers

    Join our dynamic team and shape the future of digital transformation.

    How we built our unique culture
  • Let's talk
  • EN
  • FR

Add Flexibility to Automation Tests with Protractor

Published on April 21, 2016
Last Updated on January 20, 2023
Application Development, Quality Assurance

In a previous post, we talked about the value of using modules created by the community to enhance the functionality of Protractor, using Jasmine Data Provider as an example. While user generated plugins are awesome, it’s important not to forget how robust Protractor is on its own. If you’re willing to read the API docs on it and do a little experimenting, you’ll find that Protractor has a number of built in features that can add yet another facet to your automation stack. One of those features is configuration parameters.

Why Parameters?

Protractor configuration parameters are…well, parameters! They are key-value pairs that can be defined within your configuration file and are then injected into your spec files where you would normally have hard coded values. More importantly, their values can be defined at the command line right before running. All of this is useful for a few reasons:

Keeps your code DRY

    – If you know you’re going to be using the same values in multiple spec files (i.e login email and password), parameters are great for removing unnecessary repetition.

Adds flexibility

    – Being able to change parameter values at runtime makes it easier to run the same tests with different data (think testing users with different admin privileges) all while never touching your code!

Increases security

    – Having passwords hard coded in your spec files sucks. Parameters give you the ability to keep them out and instead provide them at run time.

If all of this sounds great to you, then stay tuned! This tutorial will show you how easy it is to start using parameters in your own automation stack. Let’s do it.

Photo of Agitated Man pointing at Protractor Logo

Adding Parameters

An example used above was adding parameters for email and password values. These are good examples because more often than not in end-to-end testing, you’re going to be logging in a bunch. We’ll use these values below in our tutorial. To get parameters working properly, code needs to be added in two files: the Protractor config file, and the spec file you want to use the parameter in.

To start, add this code to your conf.js file:

module.exports = {
  params: {
    login: {
      email: 'default',
      password: 'default'
    }
  },
    //  * other config options *
}

Here, the parameters are defined so that the spec file will know what values to inject when referenced. In the example above, ‘default’ is the supplied value for each, but you can pass any string to it since that value can be changed at runtime. If you’d like to have the option to run your tests without parameter flags in the command line (which we’ll get to later in the tutorial) you can change them to values your application actually uses.

Next, you can reference these parameters in your spec file with code that looks like this:

describe('describe some test', function() {

  it('describe some step', function() {
    $('.email').sendKeys(browser.params.login.email);
    $('.password').sendKeys(browser.params.login.password);
  });
});

Now, instead of using hard coded values, Protractor will use what is provided in the config file unless the user changes those values via the command line when running the spec file. To do this, add these flags to your protractor call:

protractor conf.js --parameters.login.email=example@gmail.com 
--parameters.login.password=foobar

And that’s it! Wherever you reference those parameters in your spec files, these new values will be filled in.

Conclusion

Parameters are just one of the many Config options Protractor provides right out of the box. For a full list you can check out Protractor’s example configuration file on their GitHub. Use any cool config options in your own test suite? Let us know in the comments!

Posted in Application Development, Quality Assurance
Share this

Andrew Owen

Andrew Owen graduated from the School of the Arts at Virginia Commonwealth University and was Modus Create's first (w)intern. He is a fan of black coffee, blacker beer, and biking in between gaming. During his free time, he is a freelance photographer and videographer. While at Modus Create, Andrew filled the role of QA Engineer and Organizer of the NoVA.JS Meetup.
Follow

Related Posts

  • Debugging ProtractorJS Automated Tests in WebStorm
    Debug Protractor Automated Tests in Webstorm

    Debugging automated tests assures that the tests behave as intended and avoid false positive /…

  • Things to Consider with Protractor Automated Tests Structure
    Protractor Automated Tests Structure

    Defining a good test project approach is not an easy task. Testing is highly dependent…

Want more insights to fuel your innovation efforts?

Sign up to receive our monthly newsletter and exclusive content about digital transformation and product development.

What we do

Our services
AI and data
Product development
Design and UX
IT modernization
Platform and MLOps
Developer experience
Security

Our partners
Atlassian
AWS
GitHub
Other partners

Who we are

Our story
Careers
Open source

Our work

Our case studies

Our resources

Blog
Innovation podcast
Guides & playbooks

Connect with us

Get monthly insights on AI adoption

© 2025 Modus Create, LLC

Privacy PolicySitemap
Scroll To Top
  • Services
  • Work
  • Blog
  • Resources
    • Innovation Podcast
    • Guides & Playbooks
  • Who we are
    • Our story
    • Careers
  • Let’s talk
  • EN
  • FR