HKosova
9 years agoSmartBear Alumni (Retired)
If I'm understanding your use case correctly, what you need is a way to pass arguments to an arbitrary keyword test dynamically during runtime. Something like:
args = ["param1", 15, true]; // params are read from a file RunKeywordTest("TestName", args);
This can be done in JavaScript/ECMAScript 6 and in Python.
JavaScript example:
let testName = "MyTest1"; let args = ["param1", 15, true]; // params are read from a file
KeywordTests[testName].Run(...args);
// This is the same as
// KeywordTests.MyTest1.Run("param1", 15, true);
The three dots operator "..." (aka spread operator) expands the "args" array into a regular list of arguments that are then passed to the .Run() method.
This way you can have a generic function to run a keyword test by name:
RunKeywordTest("TestWithNoParams"); RunKeywordTest("TestWithParams", ["param1", 15, true]);
RunKeywordTest("TestWithMoreParams", ["foo", "bar", "baz", "qux", "quux"]); function RunKeywordTest(TestName, Args = []) { KeywordTests[TestName].Run(...Args); }
Python has a similar feature, array unpacking:
testName = "MyTest1" args = ["param1", 15, True] KeywordTests.__getprop__(testName).Run(*args) # Same as: # KeywordTests.TestName.Run("param1", 15, true)