Ask a Question

How do i get eh number of value in en excel file in specific column?

OV
Frequent Contributor

How do i get eh number of value in en excel file in specific column?

Hi,

 

I'm reading an excel file with few columns and want to select random value from specific column. and i have problem with 2 things:

 

1. I want to select the column by its header or index

 

2. Once i found the right header each column had different values and different number of values below, for those values i would like to select a random value. my question is how do i determine how many values i have for each column so i can use the Random(min, max) func to select a random value.

 

My script:

 

// Open Devices_ModelSetup.xlsx for reading
oExcelApp.Workbooks.Open("C:\\TestComplete Database\\Devices_ModelSetup.xlsx");
for(i = 1; i <= 12; i++)
if(SeriesValueFromUI == VarToString(oExcelApp.Cells(1, i)))
NumberOfModels = oExcelApp.Cells.Range
for(k = 1; VarToString(oExcelApp.Cells(k, i)) != "" ; k++)
ModelValue = VarToInt(oExcelApp.Cells(Random(1, k), i))

 

Thanks

4 REPLIES 4
Marsha_R
Community Hero

What is it that you are trying to accomplish with this?  Maybe we can find you an easier way to do it.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
OV
Frequent Contributor

Hi Marsha,

 

I have few printers models, for each printer model i've created a row in an excel file, each printer model had sub-models but, each printer has a different number of sub-models.

 

I want to randomly select a printer and then randomly  select printer's sub-model, means i first need to get the number of sub-models under the printer i've selected and then select this value from a combobox.

 

Thanks,

 

OV

Marsha_R
Community Hero

@tristaanogre Would this be easier to do with a Table?


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
tristaanogre
Esteemed Contributor

On one level, I understand the use of randomized input data for testing certain functionalities of an application under test... but when I'm doing test automation where I need to have predictable inputs generating predictable results, this is where randomization as a testing tool becomes a bit... cumbersome.

 

To be honest, rather than randomizing the data, I'd do one of two things:

 

1) Run loops to go through and check all sub printers for all printers to make sure they all work... nested for loops or while loops or a for loop in a while loop or something like that.  Automation gives great benefit for executing a LOT of tests faster than executing them manually.  So, rather than randomizing... just test them all.

2) Rather than selecting randomized data, come up with a respresentative subset.  Think about the idea of boundary testing... test low end, high end, mid point, out of bounds low, out of bounds high, extreme high, extreme low, etc...  not saying that those are the cases to use here, but I'm pretty sure that there is a subset of the printers and sub printers that can be used so that, rather than starting with ALL the data and then just randomizing something out of it, pick a few representative values and use them in the test case.

 

 

With either of these two, then you don't have to worry about picking a specific value out of a column... you just create your excel sheet for all the test cases you want to run and build a DDT loop around it and just exercise all the selected test cases.  This then gives you predictability... I know that when I run the loop for my data set, the first test will have one set of printer/subprinter and I'll know what to expect, and the second time, and the third time...  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: