EkremMese1
7 months agoContributor
Storing Excel file's columns and rows into array with script testing
Hello everyone,
I am working to create a method to randomly choose dropdown values from dropdown controls. But my dropdown values are changing based on what you choose in previous dropdown. For example:
If you choose a value for Region dropdown, Rayon dropdowns values are changing accordingly.
That's why I retrieve values from DataBase and create an excel source and I want my code to choose randomly.
To do that, first I need to store the excel in a 2 dimensional array.
Here is my Excel table:
Here is my code to store this excel in array:
function randomValueFromMultipleColumns() {
//Initialize the external data source
var Driver = DDT.ExcelDriver("C:\\Users\\Mes124360\\Desktop\\TestData\\TestData_EIDSS_V7.xlsx", "Simple" );
//retrieve number of columns to use in the loop
var columnCount = DDT.CurrentDriver.ColumnCount;
//create an empty array to store the column names
var tableArray = [];
var columnsArray = [];
//iterate through the columns to populate the array
for (var i = 0; i < columnCount; i++) {
var columnName = DDT.CurrentDriver.ColumnName(i);
columnsArray.push(columnName);
}
Log.Message(columnsArray);
Log.Message(columnsArray[2]);
Log.Message(columnsArray.length);
var rowCount = 0;
for ( var i = 0; i < 3; i++) {
var row = [];
while(!Driver.EOF()) {
row.push(DDT.CurrentDriver.Value(columnsArray[i]));
Driver.Next();
}
Log.Message(row);
tableArray.push(row);
}
Log.Message(tableArray);
}
But when I run my code in the console I don't get what I expected:
Does anyone has an idea?