Amar Amar - 1 year ago 115
AngularJS Question

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

I am new to

. 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
    file for each test set separately.

  2. Keep all test sets input data in single

  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


Answer Source

Yes. The data can be read from JSON file.

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

{ "UserName":"", "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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download