-
Notifications
You must be signed in to change notification settings - Fork 1
Data Parameter Placeholders
A data parameter placeholder is a text string enclosed in hashes (eg #USERNAME#) which is replaced by an actual data value when the test is run. Data parameter placeholders provide for the following capabilities:
- centralised test data management
- test data that is common to all tests
- test data used by only some tests
- test scripts that can run with different test data sets
- dynamic data involving sequential or random numbers
The example automated test described on the Home page shows the Excel test script and the generated test script object source file (.script.js).
There is a third JavaScript file that contains a JavaScript dictionary object of test data. This file is generated from a centralised test data spreadsheet [TestData.xlsm] (https://github.com/jenglezou/pasilla/blob/master/data/TestData.xlsm "Click to got to the file").
This section will use the example test, but modified to contain data parameter placeholders.
Original test spreadsheet Example.xlsx:
New version ExampleWithDataParameters.xlsx showing placeholders:

As before, it contains only one sheet called Session1.script.js. The difference between original and the new spreadsheet is that the in new one most of the parameter data has been replace by placeholders in the form #PLACEHOLDER#. For example, the username which was testuser1 is now #USERNAME#.
The generated JavaScript file, ExampleWithDataParameters\Session1.script.js, now contains placeholders. It is shown below along with the original version:
// ORIGINAL VERSION ----------------------------------------------------------------------------------------------
var Session1 = [
[{action:'Example.Start',params:[{browser:'chrome',url:'http://www.Example.com'}]}],
[{action:'Example.Signin',params:[{username:'testuser1',password:'3X4mpl3'}]}],
[{action:'Example.DoSomethingA',params:[{param1:'data1',param2:'data2'}]}],
[{action:'Example.DoSomethingB',params:[{param1:'data1',param2:'data2'}]}],
[{action:'Example.DoSomethingC',params:[{param1:'data1',param2:'data2'}]}],
[{action:'Example.DoSomethingD',params:[{param1:'data1',param2:'data2'}]}],
[{action:'Example.DoSomethingE',params:[{param1:'data1',param2:'data2'}]}],
[{action:'Example.Signout',params:[{none:''}]}],
[{action:'Example.End',params:[{none:''}]}]
];
module.exports = Session1;
// NEW VERSION WITH PLACEHOLDERS --------------------------------------------------------------------------------
var Session1 = [
[{action:'Example.Start',params:[{browser:'chrome',url:'http://www.Example.com'}]}],
[{action:'Example.Signin',params:[{username:'#USERNAME#',password:'#PASSWORD#'}]}],
[{action:'Example.DoSomethingA',params:[{param1:'#DATAITEM1#',param2:'#DATAITEM2#'}]}],
[{action:'Example.DoSomethingB',params:[{param1:'#DATAITEM1#',param2:'#DATAITEM2#'}]}],
[{action:'Example.DoSomethingC',params:[{param1:'#DATAITEM1#',param2:'#DATAITEM2#'}]}],
[{action:'Example.DoSomethingD',params:[{param1:'#DATAITEM1#',param2:'#DATAITEM2#'}]}],
[{action:'Example.DoSomethingE',params:[{param1:'#DATAITEM1#',param2:'#DATAITEM2#'}]}],
[{action:'Example.Signout',params:[{none:''}]}],
[{action:'Example.End',params:[{none:''}]}]
];
module.exports = Session1;Test Data Spreadsheet [TestData.xlsm] (https://github.com/jenglezou/pasilla/blob/master/data/TestData.xlsm "Click to got to the file")
An Excel spreadsheet file (shown below) is used as a centralised test data store.

It contains a set of mandatory sheets (Control, GLOBAL.data and Log) and a set of optional sheets (eg LIVE.data, SYSTEST.data, and UAT.data). The optional sheets represent variants of the data. In this case the variants are used to represent a test environment.
| Sheet | Description |
|---|---|
| Control | Contains a single button, Generate Data, which runs a VBA macro. It creates a set of .data.js files which contain the placefolder data in the form of a JavaScript dictionary object. |
| GLOBAL.data | Contains the data that is common to all variants of the data. |
| LIVE.data | A variant containing data specific to the LIVE environment. |
| SYSTEST.data | A variant containing data specific to the SYSTEST environment. |
| UAT.data | A variant containing data specific to the UAT environment. |
| Log | History of generated data files. |
##Generated .data.js Files The Generate Data button runs the VBA code that generates a set of .data.js files. In the example test from above, ExampleWithDataParameters, the following files are generated in the TestData/ folder:
- LIVE.ExampleWithDataParameters.data.js
- SYSTEST.ExampleWithDataParameters.data.js
- UAT.ExampleWithDataParameters.data.js
##Example data file LIVE.ExampleWithDataParameters.data.js This file is generated automatically. It contains a JavaScript dictionary object populated with the lookup data for replacing the placeholders when running a test.
var TestData = (function () {
function TestData() {}
TestData.prototype.load = function (dictData) {
dictData.set('#USERNAME#', 'testuser1');
dictData.set('#PASSWORD#', '3X4mpl3');
dictData.set('#PARAM1#', 'data1');
dictData.set('#PARAM2#', 'data2');
dictData.set('#SESSION1.USERNAME#', 'John');
dictData.set('#NAME#', 'value');
dictData.set('#RANDOM1#', '{RANDOM(100, 20000, 10)}');
dictData.set('#{RANDOM1}#', 'RANDOM(100, 20000, 10)');
dictData.set('#RANDOM2#', '{RANDOM(10, 9999, 1)}');
dictData.set('#{RANDOM2}#', 'RANDOM(10, 9999, 1)');
dictData.set('#SEQUENCE1#', '{SEQUENCE(100, 2)}');
dictData.set('#{SEQUENCE1}#', 'SEQUENCE(100, 2)');
dictData.set('#ENVIRONMENT#', 'LIVE');
dictData.set('#VERSION#', '1');
dictData.set('#CREATEME#', 'True');
dictData.set('#SESSION1.USERNAME#', 'Jane');
};
return TestData;
})();
module.exports = TestData;The LIVE.ExampleWithDataParameters.data.js file is loaded automatically by the test's .pro.js file. This is shown in the code snippet below.
Session.pro.js
// Code snippet that loads the data.js file ...
var Dictionary = require('dictionaryjs');
var dictData = new Dictionary();
try {
var TestData = require("../../tests/TestData/" + browser.params.testEnv +
".ExampleWithDataParameters.data.js");
var testData = new TestData();
testData.load(dictData);
} catch(err) {console.log(err)}Pasilla
Links: Home, [General Concepts](General Concepts), Tutorial - Create a New Test, Data Parameters