global parameter in DOM Xpath

Ask general questions here.
rk325
Posts: 23
Joined: Mon Mar 27, 2023 6:02 pm

global parameter in DOM Xpath

Post by rk325 » Wed Mar 29, 2023 7:33 pm

I am using "pure C# code" tests, not recording anything to test a Web Application. Therefore I have defined my own C# module and tests are running fine from there. However, the DOM path of my repository is still hard coded: /dom[@domain="http://mytestwebsite/login"]
I need to find a way of using a parameter or variable for the value @domain, but how?
/dom[@domain=$parDom] ---> does not work, $parDom is empty.

parDom is a Global Variable, but I want to read its value from an excel file.
The only thing I was able to do was, inside my code module:
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;     
            TestSuite.Current.Parameters["parDom"] = dom;
           Report.Log(ReportLevel.Info, "parDom = " + TestSuite.Current.Parameters["parDom"]);

dom is a local variable to this module that binds to an excel file.
This works, I see in the log the value of parDom as it is in the excel file.

How, where do I pass the actual value of parDom so that it gets capture by the dom xpath in /dom[@domain=$parDom] .

Your help will be very appreciated.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: global parameter in DOM Xpath

Post by Stub » Thu Mar 30, 2023 3:32 pm

Set the 'parDom' variable in your Repository by assigning to it from your 'parDom' global parameter.

rk325
Posts: 23
Joined: Mon Mar 27, 2023 6:02 pm

Re: global parameter in DOM Xpath

Post by rk325 » Thu Mar 30, 2023 9:56 pm

Do you mean by setting the Base Path in the repository to:
Item                                                                            Path
ApplicationForTesting                                        Base:/dom[@domain=$parDom] 
Yes, I am doing that. Now I need to bind that global variable $parDom to a value from an excel file.
I don't know how to do that.
I know how to bind module variables to an excel file, but $parDom is a global variable.
And again, I do not use recording modules, my program is all code modules.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: global parameter in DOM Xpath

Post by Stub » Fri Mar 31, 2023 9:00 am

Code: Select all

Repo.parDom = [value from Excel file];