Protractor for Angular E2E Testing: What is the be

2019-03-22 04:14发布

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.

1条回答
甜甜的少女心
2楼-- · 2019-03-22 04:26

Yes. The data can be read from JSON file.

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

{ "UserName":"uname@blah.com", "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

查看更多
登录 后发表回答