hi! can i use arrays in UI vision?
Yes! See here: Nested Variables or Variables Inside Variables Requested - #3 by admin
Plus, the DemoExecuteScript
macro that ships with UI Vision has a demo of using an array.
Hi. Thank you for replay. Is it possible to convert array to csp string or to json? also convert string or json ton array?
For CSV (string) to array see here: How to read a CSV file with a changing number of columns
Array to string: What would be the purpose of this? It can be done, but the method depends on what you want to achieve.
V5.5.6 adds Selenium IDE style array support e. g. ${a[0][5]}
and a new way to import/export arrays to/from CSV files.
- csvRead: csvRead - Daten-driven Testing
- csvSave: csvSave - Daten-driven Testing
- See the new DemoCsvReadArray demo macro (ships with UI.Vision)
- Good use case for arrays: How to mark a row in a CSV line as processed?
To create a Javascript array, use the executeScript_Sandbox command:
executeScript_sandbox |
var arr = []; for(var x = 0; x < 5; x++){arr[x] = []; for(var y = 0; y < 3; y++){arr[x][y] = (x+1)*(y+1);}}; return arr | myArray
To loop over an array you can use forEach.
The example below creates a 5x3 array, stores the values in the myArray array variable and then saves the array to a CSV file.
{
"Name": "DemoArray",
"CreationDate": "2022-4-19",
"Commands": [
{
"Command": "store",
"Target": "fast",
"Value": "!replayspeed"
},
{
"Command": "comment",
"Target": "Create an array and save the content to a CSV file",
"Value": ""
},
{
"Command": "executeScript_sandbox",
"Target": "var arr = []; for(var x = 0; x < 5; x++){arr[x] = []; for(var y = 0; y < 3; y++){arr[x][y] = (x+1)*(y+1);}}; return arr",
"Value": "array1"
},
{
"Command": "comment",
"Target": "Manually set two array values ",
"Value": ""
},
{
"Command": "executeScript_sandbox",
"Target": "var newArr = ${array1}; newArr[0][2] = 'Hello World'; return newArr",
"Value": "array1"
},
{
"Command": "executeScript_sandbox",
"Target": "var newArr = ${array1}; newArr[2][1] = 'This is how you set an array value'; return newArr",
"Value": "array1"
},
{
"Command": "csvSaveArray",
"Target": "array1",
"Value": "data_from_array.csv"
}
]
}
Macro result: