Is it possible to test data using a protractor?

What I would like to get is Protractor testing to extract data from a separate data file (e.g. CSV, JSON, etc.) so that I can modify the data without having to touch the test script code.

Is this possible with Protractor?

+5
source share
3 answers

You can use browser.params to read custom test data.

To read from a JSON file, just add params to your configuration file

 exports.config = { params: require('./your-params-file.json'), }; 

NodeJS automatically converts the JSON file to a Javascript object that is easily accessible from any of your tests through browser.params.whateverYourJSONHas .

If you really need to use CSV, try using a parser like csvtojson or google / open another question about "NodeJS convert CSV file to POJO array"

+8
source

I'm not sure if you could figure it out or not. however, I was able to do just that.

Here is what your json might look like:

 [ { "someId": "signInInput", "sendSomeKeys": " j@j.com " }, { "someId": "passwordInput", "sendSomeKeys": "password" } ] 

And here's how to implement it in your test:

 'use strict'; var testData = require('./path/to/json.json'); describe('your test', function() { testData.forEach( function (data) { it('should read from an external json', function(){ element(by.id(data.someId)).sendKeys(data.sendSomeKeys); }); }); }); 
+1
source

You can simply iterate using the javascript "map" function without any loops:

 var testParams = testConfig.testArray; testParams.map(function(testSpec) { it('write your test here', function() { //test code here }); }); 
0
source

Source: https://habr.com/ru/post/1201204/


All Articles