Updating global parameters

Experiences, small talk, and other automation gossip.
gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Updating global parameters

Post by gce » Fri Jun 25, 2021 9:04 am

Hi,
I have a global parameter and I am not setting a value for it.
In my code I am doing this:

TestSuite.Current.Parameters["StatementFromFile"]=statement;
Report.Info(TestSuite.Current.Parameters["StatementFromFile"]);
This works! So when i log it then I see the correct statement which I load from a file.
my problem is that the value is not saved.
when I am in another module and bind my variable to this parameter the value is empty.
So do I need something different to achieve this.

I read that the parameter shold be updated in the next testcase
I also tried it out but still blank.
hope that someone can helps me
I also tried many different things I found in the forums but still doesn't work.

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

Re: Updating global parameters

Post by odklizec » Fri Jun 25, 2021 9:51 am

Hi,

Could you please share a screenshot of your test suite and point to the module, where you set the global parameter and the other one, where you try to read the global parameter?

Please see the attached sample project, which does exactly what you want and it works for me?
https://drive.google.com/file/d/1CfoJcV ... sp=sharing
Forum attachment system seems to be currently broken, so I uploaded it to my google drive.
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

gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Re: Updating global parameters

Post by gce » Fri Jun 25, 2021 10:48 am

Hi!
Must it be in a user code module in the ITestModule.Run() function?

I have it in my recording.UserCode and calling this function from the recording:

this is in recording 1 user code where i will call this function from my recording:
public void setParam()
{
TestSuite.Current.Parameters["pqlStatementFromFile"]=statement; //statement is a string from a file-> one line code as string
Report.Info(TestSuite.Current.Parameters["pqlStatementFromFile"]);
}

this is the function i call in recording2 from recording2.UsercCode
public void getParam()
{
Report.Info(TestSuite.Current.Parameters["pqlStatementFromFile"]); // The output is empty
}

Also when I have a variable in recording module and assign it to my parameter it is empty

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

Re: Updating global parameters

Post by odklizec » Fri Jun 25, 2021 11:22 am

gce wrote:
Fri Jun 25, 2021 10:48 am
Hi!
Must it be in a user code module in the ITestModule.Run() function?
No, it does not have to be in ITestModule.Run(). It should work (and works for me) also with custom method. However, the method must be a part of the recording/code module, which is a part of the test suite! In other words, it will most probably not work, if the called method is in external module, which is not a part of the test suite.

This is what I just tried:

Code: Select all

void ITestModule.Run()
 {
    Mouse.DefaultMoveTime = 300;
    Keyboard.DefaultKeyPressTime = 100;
    Delay.SpeedFactor = 1.0;
    setParam();
}
		
public void setParam()
{
    TestSuite.Current.Parameters["globalParam"]="test123";
    Report.Info(TestSuite.Current.Parameters["globalParam"]);
}
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

gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Re: Updating global parameters

Post by gce » Fri Jun 25, 2021 12:19 pm

https://ibb.co/0C76SRs
I have it here.
I really don't know why it does not work.

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

Re: Updating global parameters

Post by odklizec » Fri Jun 25, 2021 12:54 pm

Hi,

OK, but is the LoadSource.rxrec a part of test suite? This is a must! Please show me a screenshot of your test suite, where I can see the location of LoadSource module. And show me also the content of LoadSource.UserCode.cs.
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

gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Re: Updating global parameters

Post by gce » Fri Jun 25, 2021 1:12 pm

Thats my test suite: https://ibb.co/sFrJ6t1
This is my code:

Code: Select all

public void loadPqlSource()
        {
        	string path= @"pqlStatement.txt";
        	string statement = File.ReadAllText(path);
        	Report.Info(statement);
        	TestSuite.Current.Parameters["pqlStatementFromFile"]=statement;
        	Report.Info(TestSuite.Current.Parameters["pqlStatementFromFile"]);
        }

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

Re: Updating global parameters

Post by odklizec » Fri Jun 25, 2021 2:03 pm

Hi,

There seems to be a bound variable in LoadSource module. Where the variable is binded to and what's the content of the variable? Also I assume you are trying to read the updated Global parameter in testModule?
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

gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Re: Updating global parameters

Post by gce » Mon Jun 28, 2021 7:06 am

Hi!
The variable is bound to my global parameter pqlStatementFromFile.
In the global parameters section of my testsuite the value of this variable is empty.

Yeah I am updating my global parameter in loadSource module and want to read/print the updated global parameter.

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

Re: Updating global parameters

Post by odklizec » Mon Jun 28, 2021 7:49 am

Hi,

So my example still does not work work you? If not, please share the solution you are working with. Eventually, try to create new one and implement the code I suggested. It definitely works. So it's either something wrong with your solution (check spelling) or something is overwriting the global parameter?
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

gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Re: Updating global parameters

Post by gce » Mon Jun 28, 2021 8:16 am

your example works fine for me!
I also checked the spelling and all around and it doesn't work for me.
I will to try implement it like you did and will reply if it works then!

gce
Posts: 23
Joined: Mon May 03, 2021 10:31 am

Re: Updating global parameters

Post by gce » Mon Jun 28, 2021 8:51 am

Hi,
I made now an extra code Module and imported it into my testcase.
Now it works well!

Thank you very much!

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

Re: Updating global parameters

Post by odklizec » Mon Jun 28, 2021 9:31 am

You are welcome. Nice to hear it now works for you ;)
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