Calling parameters in user code

Ranorex Spy, Recorder, and Studio.
eldorado25
Posts: 21
Joined: Tue Aug 06, 2019 4:14 pm

Calling parameters in user code

Post by eldorado25 » Mon Feb 24, 2020 12:33 pm

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6036
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calling parameters in user code

Post by odklizec » Mon Feb 24, 2020 12:39 pm

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

eldorado25
Posts: 21
Joined: Tue Aug 06, 2019 4:14 pm

Re: Calling parameters in user code

Post by eldorado25 » Mon Feb 24, 2020 12:56 pm

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)

eldorado25
Posts: 21
Joined: Tue Aug 06, 2019 4:14 pm

Re: Calling parameters in user code

Post by eldorado25 » Mon Feb 24, 2020 1:00 pm

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?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6036
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calling parameters in user code

Post by odklizec » Mon Feb 24, 2020 1:11 pm

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

eldorado25
Posts: 21
Joined: Tue Aug 06, 2019 4:14 pm

Re: Calling parameters in user code

Post by eldorado25 » Mon Feb 24, 2020 1:18 pm

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!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6036
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Calling parameters in user code

Post by odklizec » Mon Feb 24, 2020 1:25 pm

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration