Skip to content

Data Parameter Placeholders

John edited this page Mar 22, 2015 · 9 revisions

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

Example Test with Data Parameter Placeholders

The example automated test described in 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.

Excel test script - ExampleWithDataParameters.xlsx

Original test spreadsheet Example.xlsx: ![Example.xlsx.png]([Example.xlsx.png] [https://github.com/jenglezou/pasilla/blob/master/documentation/ImagesForWiki/Example.xlsx.png)

New version ExampleWithDataParameters.xlsx showing placeholders: ![Example.xlsx.png]([ExampleWithDataParameters.xlsx.png] [https://github.com/jenglezou/pasilla/blob/master/documentation/ImagesForWiki/ExampleWithDataParameters.xlsx.png)

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#.

JavaScript test script - Session1.script.js

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;

Clone this wiki locally