tristaanogre's avatar
tristaanogre
Esteemed Contributor
9 years ago
Status:
New Idea

Run A KeywordTest by name

Runner.CallMethod works pretty well with regards to running Keyword tests.  You can do a syntax like:

 

Runner.CallMethod('KeywordTests.TestName.Run', 'parametervalue');

However, this is a bit clunky to me. First of all, if you don't have the name up front but want to parameterize this call, you would need to do a concatenated string for the object name. Secondly, this just seems to be a bit out of the way.  Code Completion already knows all the tests associated with the KeywordTests object so the information is already there.

 

It would be nice to do something like

 

KeywordTests.TestByName('MyTest').Run('parametervalue');

This just seems more intuitive and lends itself to a much cleaner implementation for creating a framework around the tests.

 

Note that I'd prefer the keyword test to be returned by name so that we have access to things like Test.Variables and Test.Parameters (see my other ideas on KeywordTests).

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    In JavaScript/JScript you can use the bracket syntax to access an object property by name, in this case a keyword test by name:

    KeywordTests['TestName'].Run('parametervalue');

     

    UPD: In Python you can use __getprop__:

    KeywordTests.__getprop__("TestName").Run("parametervalue")

    In VBScript and DelphiScript you can use aqObject.GetPropertyValue -- or just GetPropertyValue() -- as an alternative to "eval":

    ' VBScript
    Set test = GetPropertyValue(KeywordTests, "TestName")
    Call test.Run("parametervalue")

    But I agree that KeywordTests.TestByName("TestName") would be nice to have.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Really, HKosova? I did not know that... let me give that a try in my current development.  If so, that's freaking AWESOME and I can get rid of my hated "eval" call...

    Still would be nice to have the possibility of assigning parameter values and executing "Run" on the fly... but perhaps using the same bracket syntax, I can do the same thing... I'll play around.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Sure enough, calling the keyword test via name works AMAZINGLY... Thanks, HKosova.

     

    However, I still cannot assign parameters via the Test.Parameters object... I can access the parameters via the same bracket syntax but I cannot assign values to them outside of sending them to the call.

    So... for those of you who want to know, here's what I'm doing right now...

    function foo() {
        var TestName = 'TC101';
        var parameterlist = '\'value1\', \'value2\'';
        var testObject = KeywordTests[TestName];
        eval('testObject.Run(' + parameterlist + ')');
        
    }

    It's closer to what I want... but what I would REALLY love is to be able to completely get rid of the need for eval...  See my feature request here.