Page 1 of 1
Calling parameters in user code
Posted: Mon Feb 24, 2020 12:33 pm
by eldorado25
Hi all,
I am trying to use
Code: Select all
string globalParam = TestSuite.Current.Parameters["globalParamName"];
However, each time I do this I get an error
The given key was not present in the dictionary.
Does anyone know where I might be going wrong?
I tried to call TestCase as well but that does not appear to be working for me at the moment
Re: Calling parameters in user code
Posted: Mon Feb 24, 2020 12:39 pm
by odklizec
Hi,
At first, make sure the parameter really exists in Global parameters. At next, make sure you run entire test (test suite) and not just single recording/code module, containing this code
Re: Calling parameters in user code
Posted: Mon Feb 24, 2020 12:56 pm
by eldorado25
Thanks again for your reply
Well I am not sure how this all works
TestSuite.Current = calls the overall Test Suite
my parameter is not a global parameter, and is inside a testcase inside there
so should I be using CurrentTestContainer (which I'm assuming is the smartfolder/test case of the current class):
Code: Select all
string globalParam = TestSuite.Current.CurrentTestContainer.Parameter["globalParamName"];
I've tried this and it seems to be having the same issue
I will give you my Folder Hierachy
TestSuite
->Smart Folder
-->Smart Folder (Where Parameter is)
--->Test Case
---->Smart Folder -> Class (which is trying to call the parameter)
Re: Calling parameters in user code
Posted: Mon Feb 24, 2020 1:00 pm
by eldorado25
Okay so I got it working, but it's a bit long winded,
Code: Select all
string globalParam = TestSuite.Current.CurrentTestContainer.ParentContainer.ParentContainer.Parameters["globalParamValue"];
Just wondering if there was a simpler version to doing this?
Re: Calling parameters in user code
Posted: Mon Feb 24, 2020 1:11 pm
by odklizec
Hi,
You can try this:
Code: Select all
string globalParam = TestSuite.Current.GetTestContainer("tcName").Parameters["globalParamValue"];
But this means you need to know and pass the TC name, containing the parameter in question.
Re: Calling parameters in user code
Posted: Mon Feb 24, 2020 1:18 pm
by eldorado25
Thanks I really appreciate it,
I will keep my slightly convoluted for now as it keeps to my folder hierarchy, I will just have to comment heavily as to why it is like this. I was trying to save myself from calling and binding variables everywhere (which would be very confusing for new testers at my organisation).
Cheers!
Re: Calling parameters in user code
Posted: Mon Feb 24, 2020 1:25 pm
by odklizec
Hi,
I agree that binding parameters via variables is somewhat painful, especially in case of code modules, but I think it's still the best approach
Calling parameters directly from code is straightforward, but could create a mess and make the code hard to understand and debug.