Ask a Question

Data driven loop round collection of variables

Lee_M
Contributor

Data driven loop round collection of variables

I have a test that is made up of 3 parts

  1. Log in
  2. test for the correct user
  3. Log out

 

Log in passes URL as a parameter, the test works fine.

 

I now have 2 environments:
Live and test on different URLs - both MUST URLs be stored as separate string vars (liveUrl, testUrl)

Given that both environments share the same credentials,  is there any way to loop these so they share the same test?

 

a DDT loops using a var (excel sheet, table, DB)

 

How can I loop round the 2 vars

 

The only way I can work around this problem is to programmatically populate a table var with these 2 separate values before runtime

 

Does anyone have any solutions/suggestions on this problem?

10 REPLIES 10
Marsha_R
Community Hero

Re: Data driven loop round collection of variables

Use an Excel sheet to store the URLs and DDT loop to step through the sheet.  Login reads the sheet, gets the URL, then continues on.  DDT loop repeats this for each line in the sheet, so it could be 2 URLs or 100.

Lee_M
Contributor

Re: Data driven loop round collection of variables

This is just working the problem from a different angle

I still need a script to pull out the variables into separate instances

 

I need var1, var2 for other users to see and reference - I can't have them digging through CSV files as this could make this

 

but thanks for the suggestion

Marsha_R
Community Hero

Re: Data driven loop round collection of variables


@Lee_M wrote:

This is just working the problem from a different angle

 

 


Yes, it is.  Since we are guessing at what you really want to do, all we can do is offer alternatives.

 

I myself don't understand how accessing a data file with two URL entries is asking someone to dig through a file, but I guess that's just me.  I would consider that to be safer than asking them to change a variable or table value in TestComplete.

 

Good luck with your script!

Lee_M
Contributor

Re: Data driven loop round collection of variables

Marsha,

 

Thanks for your input and confirmation that I took the only approach available for this situation

 

The idea is for visibility

  • Live_URL
  • Test_URL

are clearer and shorter to read for a non-programmer, rather than something like:

 

Lee_M_1-1624346055291.png

Which I can create in another structure

 

 

 

AlexKaras
Community Hero

Re: Data driven loop round collection of variables

Hi,

 

Why not to create a new variable (TestedURL), assign it (somewhere) value of either Live_URL or Test_URL and use this new variable in your KW tests?

 

Regards,
  /Alex [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
================================
Lee_M
Contributor

Re: Data driven loop round collection of variables

This is what I have done

 

@Marsha_R suggested an excel spreadsheet - I have used a table variable, which is just a different type of variable but I feel can be used a little more ablatively than the excel solution for my purposes.

 

Either way, the answer I was looking for was that you CAN'T make a DDT loop over a series of variables unless it is a structured data type

AlexKaras
Community Hero

Re: Data driven loop round collection of variables

Hi,

 

you CAN'T make a DDT loop over a series of variables unless it is a structured data type

Yes, correct for the built-in data loop operation.

Actual implementation may vary and some code sample might help to better understand your needs and idea.

For example (untested jscript pseudocode)

var test_url = ...;

var pod_url = ...;

var arr = [test_url, prod_url];

for each (var url in arr) { // DDT loop

  ...

}

 

 

P.S.

From initial message:

Live and test on different URLs - both MUST URLs be stored as separate string vars (liveUrl, testUrl)

I do not see the reason to store these two URLs in a separate variables (unless both of them are used within one test), but probably due to the fact that I know almost nothing about your actual test.

Store them as separate data entries for DDT or just easy switching between tested environments - yes, but store them in a separate standalone variables (i.e. not array, table variable, etc.) - no.

 

Regards,
  /Alex [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
================================
Lee_M
Contributor

Re: Data driven loop round collection of variables

@AlexKaras, this is similar to the way I am making the DDT loop var.

 

Live and Test as separate vars

 

All programmatic tests can have the vars together as I know where and what they are called/

For creating new tests I would like to have the distinction of 2 uniquely named vars for visibility (make it easier for people to create tests

 

 

AlexKaras
Community Hero

Re: Data driven loop round collection of variables

Hi,

 

Well, your initial statement remains correct: In order to be used in a DDT or any other kind of a loop, all loop elements must be a part of some structure that can be iterated through (array, list, dictionary, file, etc.).

So it is not possible to iterate through two separate standalone variables. (At least this is not possible using regular means available to the regular developer/end-user.)

 

make it easier for people to create tests

Again, unless the test depends on the target URL, I don't really see how the knowledge of the URL can simplify test creation. If the test is created for specific environment (test or prod) then the knowledge of exact URL value barely helps either - you are just creating test for the functionality that must exist on test or prod and explicitly state that this given test is not expected to be executed on any but this specific test environment.

But these are regular generic considerations and you definitely know better what is required and who are your users for this given case.

So the initial statement remains unchanged and everything else is just exchange of opinions. 🙂

 

Regards,
  /Alex [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
================================
cancel
Showing results for 
Search instead for 
Did you mean: