Answered

Passing lists to functions

I am trying to pass lists into functions and getting mixed results.

So to start out I am creating a list with a process that looks something like this

In the above image, the source and reference files are string text file names.  The list is created successfully

When I set up to pass the list into a function I get inconsistent results.   Mostly though the variable does not get passed in.   Is passing of lists into functions supported?   If so, is there a standard way to do it?

 

 

 

 

 

 

 

 

0
9 comments
Avatar
Joseph Hamdan

Hi William,

Could you please elaborate on what you are trying to do with functions? Were you trying to pass the variable values into the Parameters section of the Function or in the steps of a function?

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Sure.  I have a function which processes some filenames.  I would like to use the function to process a varying number of file names.  The alternative to that is to write multiple functions to accept multiple numbers of files.   Since the number of parameters into the function is fixed, one way I thought to handle that is to pass in a list. 

I am also passing in the size of the list as a separate variable.   Normally lists in Subject7 allow me to extract out the size which if they passed in cleanly I could do. 

In a traditional programming language, this might be handled by passing an array of names to the function.

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

Sorry, we still don't understand the question. Would it be possible to provide a test case export and let us know the steps you need help with?

Since it cannot be attached to this post, you can reply via email and we'll pick up the file.

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

I got the file, thank you.

Would you please confirm these points:

1. The type in the parameters of the function/extension is set to Text, not Choice

2. You included the variable name of the list as well as the field? If you specify only the variable name of the list without the field, you would see UNDEFINED as below:

In this screenshot, the field in the list was specified and variable was resolved successfully. As you can see, passing values is already supported

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Just to verify, yes the extension is set to Text.  Should it be set otherwise?  

Also, with regard to your solution.  That submits an element of the list to the function, but not all elements of the list.   The goal is to submit the entire list and have the function process the list.

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

No, Text is good. I was just confirming because Choice parameter is designed to show an error in case values on the function differ from the ones being passed.

Regarding passing the whole list, this can only be done with Loop. Please check scenarios 2 and 3 in this article:

https://subject7.atlassian.net/wiki/spaces/SD/pages/879493553/SET+LIST+Command

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Ok, so you are confirming the original question, which is that there is no way to pass a list as a parameter.   My alternative which I have been using is to just keep the list as a global value and use it in the function that way.  
Having to create a loop in a test every time it calls the function sort of defeats the purpose.

 

Thanks.

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

As shown in the previous images, it is possible to pass the list, but not the entire list in a single line, so one field can be specified or using loops.

By Global Value, do you mean that you used global variables to pass the entire list?

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Yes, I mean global variable.   This is the method used to pass values into a function before parameters were added.

It would be nice if parameters supported all data types in Subject7. 

I have several use cases where I have a function which validates values in a table.   The reason for this kind of entry is that the table  values including the number of rows in the table change through the test session.   It would be nice to be able to formulate the values I would like to test for into a list and pass that into the function easily.   It would keep from having to write multiple functions for every state of the table.   

In addition, I don't always know what the values in the table will be before the test runs.   The values are read in one area and compared to values in another.   Pr-defining the values before testing does not always work.

 

 

0
Comment actions Permalink

Please sign in to leave a comment.