Protractor for Angular E2E Testing: What is the best approach to manage test data?

All we need is an easy explanation of the problem, so here it is.

I am new to Angular and Protractor. I have written couple of protractor test cases to automate registration, login and some other pages. To execute a test case for example student registration, I need to pass some data like name,dob,age,address etc, right now I hardcoded those values in my test cases which is not best practice so I want to externalize these input data values for all my protractor test cases. I have below thoughts around this but not able to decide which one is the best approach and industry standard.

  1. Keep input data in JSON file for each test set separately.
  2. Keep all test sets input data in single JSON file.
  3. Keep the test data in .js file read it from there.

please suggest me the best approach and any other best practices I should consider while writing protractor UI test cases as I am completely new to this framework.I am using protractor with jasmine 2.x.

-Amar.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Yes. The data can be read from JSON file.

Step 1: Create a JSON file and add it into your project folder

{
"UserName":"[email protected]",
"Password":"blahblah",
}

Step 2: Import the file into your protractor.conf.js and assign it to params

exports.config = {
    directConnect: true,
    params: require('./testdata.json'),

Step 3: Access data in your test cases by referring the key values using ‘browser.params’ object

element(by.css('input[type=email]')).sendKeys(browser.params.UserName);

refer my blog for more information
Data Driven Testing in Protractor Frameworks

POM Design Pattern in Protractor Frameworks

Configuring Explicit Waits in protractor E2E Framework – Best Practices

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply