角度E2E测试量角器:管理测试数据的最佳方法是什么?

角度E2E测试量角器:管理测试数据的最佳方法是什么?

问题描述:

我是AngularProtractor的新手.我写了几个量角器测试用例,以自动进行注册,登录和其他一些页面.要执行一个测试用例(例如学生注册),我需要传递一些数据,例如姓名,出生日期,年龄,地址等,现在我在测试用例中对这些值进行了硬编码,这不是最佳实践,因此我想将这些输入数据值外部化我所有的量角器测试用例.我对此有以下想法,但无法决定哪种方法是最佳方法和行业标准.

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. 分别将每个测试集的输入数据保存在JSON文件中.
  2. 将所有测试集的输入数据保留在单个JSON文件中.
  3. 将测试数据保留在.js文件中,然后从那里读取.
  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.

请为我提供最佳的方法以及在编写量角器UI测试用例时应考虑的其他最佳实践,因为我对这个框架是完全陌生的.我正在将量角器与jasmine 2.x一起使用.

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.

-阿马尔.

是.可以从JSON文件读取数据.

Yes. The data can be read from JSON file.

第1步:创建一个JSON文件并将其添加到您的项目文件夹中

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

{ "UserName":"uname@blah.com", "Password":"blahblah", }

{ "UserName":"uname@blah.com", "Password":"blahblah", }

第2步:将文件导入您的protractor.conf.js并将其分配给params

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

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

第3步:通过使用"browser.params"对象引用键值来访问测试用例中的数据

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

配置显式等待在量角器端到端框架中-最佳做法