william_roe's avatar
william_roe
Super Contributor
9 years ago
Status:
New Idea

Passing Code Expression as Parameter Value in Keyword Test

It would be useful to be able to pass a code expression as a parameter to keyword tests. I have the need to pass dates to a keyword tests (object type is fine) but have no ability to specify a code expression as the parameter (second image). As an example I would like to pass four weeks from today as the EndDate: aqDateTime.AddDays(aqDateTime.Today(), 28)

 

CodeExpression3.png

 

CodeExpression.png

CodeExpression2.png

 

This sort of code is unmaintainable: 

 

CodeExpression4.png

 

10 Comments

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    I store my different date calculations as string variables

     

    Daily   String   aqDateTime.AddDays(aqDateTime.Today(),7)

    Weekly String  aqDateTime.AddDays(aqDateTime,Today(),28)

    Monthly String aqDateTime.AddMonths(aqDateTime,Today(),12) 

     

    Then pass them in as parameters the same way 

     

    EndDate  String  Variables.Daily

     

    Use eval in the on screen action to get the object

     

    MyDateField   Keys   eval(EndDate)

     

  • william_roe's avatar
    william_roe
    Super Contributor

    What data type would the 'EndDate' parameter date be in your case? I guess my programmer background wants it to by type specific but string would be fine for the purposes of populating an input field.

     

    I'll give it a try.

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    It's a string too.  All strings till you need to use it and then eval(string).

  • william_roe's avatar
    william_roe
    Super Contributor

    I don't get the statment "store different date calculations as string variables". I've added the following parameters (first image) but would still need the nested if statements (second image) which wouldn't be a gain. What am I missing? When calling the KeyWord test the option to pass a code expression (third image) would allow for a single paramter (EndDate).

     

    parms.png

     

    parms2.png

    Code Expression in Parm.png

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Daily and Weekly and Monthly should be project variables rather than parameters.

     

    Then keyword test SetCycleCountingSchedule should have a parameter SetDate which is a string.

     

    so if your subcycle was daily you might use

     

    RunKeywordTest     SetCycleCountingSchedule  (2, Project.Variables.Daily)

     

    and inside SetCycleCountingSchedule you will have

     

    DateField  Keys  eval(KeywordTests.SetCycleCountingSchedule.Parameters.SetDate)

     

     

  • william_roe's avatar
    william_roe
    Super Contributor

    So the nested if statement would remain - not an improvement. Allowing code expressions to be passed as parameter value would remove the need for 'subcycle' and simply allow the EndData to passed to the test. Thus the feature request.

     

     

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Can't you call SetCycleCountingSchedule with just one of the Daily/Weekly/Monthly parameters, then take out the nested if and just have

     

     

    EndDate   Keys    eval(KeywordTests.SetCycleCountingSchedule.Parameters.EndDate)

     

     

    then the daily/weekly/monthly choice gets made when you call SetCycleCountingSchedule and not inside the test itself

     

    RunKeywordTest  SetCycleCountingSchedule (2,Project.Variables.Daily)

    RunKeywordTest  SetCycleCountingSchedule (2,Project.Variables.Weekly)

    RunKeywordTest  SetCycleCountingSchedule (2,Project.Variables.Monthly)

     

     

     

     

  • william_roe's avatar
    william_roe
    Super Contributor

    Seems wasteful to scope a global variable just to call a KeyWord test. Hence the desire to pass as a parameter as code expression..

  • william_roe's avatar
    william_roe
    Super Contributor

    Global variables can become unmanageable if there are too many. If individual consumers of the global variables aren't aware of what others consumers are doing with the global variable it could cause problems. Scope is critical element to writing manageable code and should be as narrow as possible.