Page 1 of 1

Updating global parameters

Posted: Fri Jun 25, 2021 9:04 am
by gce
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.

Re: Updating global parameters

Posted: Fri Jun 25, 2021 9:51 am
by odklizec
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.

Re: Updating global parameters

Posted: Fri Jun 25, 2021 10:48 am
by gce
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

Re: Updating global parameters

Posted: Fri Jun 25, 2021 11:22 am
by odklizec
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"]);
}

Re: Updating global parameters

Posted: Fri Jun 25, 2021 12:19 pm
by gce
https://ibb.co/0C76SRs
I have it here.
I really don't know why it does not work.

Re: Updating global parameters

Posted: Fri Jun 25, 2021 12:54 pm
by odklizec
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.

Re: Updating global parameters

Posted: Fri Jun 25, 2021 1:12 pm
by gce
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"]);
        }

Re: Updating global parameters

Posted: Fri Jun 25, 2021 2:03 pm
by odklizec
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?

Re: Updating global parameters

Posted: Mon Jun 28, 2021 7:06 am
by gce
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.

Re: Updating global parameters

Posted: Mon Jun 28, 2021 7:49 am
by odklizec
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?

Re: Updating global parameters

Posted: Mon Jun 28, 2021 8:16 am
by gce
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!

Re: Updating global parameters

Posted: Mon Jun 28, 2021 8:51 am
by gce
Hi,
I made now an extra code Module and imported it into my testcase.
Now it works well!

Thank you very much!

Re: Updating global parameters

Posted: Mon Jun 28, 2021 9:31 am
by odklizec
You are welcome. Nice to hear it now works for you ;)

Re: Updating global parameters

Posted: Mon Jan 02, 2023 10:48 am
by gosen11
gce wrote:
Mon Jun 28, 2021 8:51 am
Hi,
Dream League Soccer modI made now an extra code Module and imported it into my testcase.
Now it works well!

Thank you very much!
Hey sir I have followed your guide and which also worked on me. You just made my day thank you 8)