Iterate through controls with variables in path in User Code

Ask general questions here.
Darwin
Posts: 26
Joined: Tue Jul 25, 2017 9:00 pm

Iterate through controls with variables in path in User Code

Post by Darwin » Thu May 10, 2018 7:16 pm

Apologies if this has been asked and answered--if so, I have not been able to find the solution.

I have a number of labels on the screen--the amount can fluctuate as they represent a number of devices connected to the AUT. They have paths similar to this:

Code: Select all

list[@automationid='programmerPanels']/container[$ProgrammerIndex]/text[@caption='Idle']
What I'd like to do in my user code is set $ProgrammerIndex to find a specific control, so I can loop through the "x" number of them and verify they exist, i.e.:

Code: Select all

for (int i = 1; i < totalNumber; i++)
{
    $ProgrammerIndex = i; 
    // verify label(i) exists and do other stuff
}
Is it possible to iterate through controls with variables in their Xpath via user code?

Vielen Dank!

Darwin
Posts: 26
Joined: Tue Jul 25, 2017 9:00 pm

Re: Iterate through controls with variables in path in User Code

Post by Darwin » Thu May 10, 2018 10:38 pm

Never mind--poking through the generated code in my recordings I see where they pass variables to the Repository directly then get the controls back.

E.g.:

Code: Select all

        [TestVariable("2df735a2-b879-4091-8ed9-c7af5026f400")]
        public string ProgrammerIndex
        {
            get { return repo.ProgrammerIndex; }
            set { repo.ProgrammerIndex = value; }
        }

        [TestVariable("03cfebbe-ff37-48fa-a47a-599373edcb59")]
        public string targetFirmwareVersion
        {
            get { return repo.targetFirmwareVersion; }
            set { repo.targetFirmwareVersion = value; }
        }


And then reference the target control a la:

Code: Select all

        Report.Log(ReportLevel.Info, "Wait", "Waiting 5m to exist. Associated repository item: '<my AUT>.UpdateProgrammers.lblFirmwareVersionIndex'", repo.<my AUT>.UpdateProgrammers.lblFirmwareVersionIndexInfo, new ActionTimeout(300000), new RecordItemIndex(0));
        repo.<my AUT>.UpdateProgrammers.lblFirmwareVersionIndexInfo.WaitForExists(300000);
That would be much easier for me than creating multiple recordings for each step and sprinkling user code here and there to incorporate some kind of logical branching.

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: Iterate through controls with variables in path in User Code

Post by tvu » Thu May 10, 2018 10:50 pm

Hi Darwin,

Your original idea should work. You just need to update the parameter by using the repo instance.

Code: Select all

for (int i = 1; i < totalNumber; i++)
{
    repo.ProgrammerIndex = i; 
    // verify label(i) exists and do other stuff
}
Hope that helps.

Darwin
Posts: 26
Joined: Tue Jul 25, 2017 9:00 pm

Re: Iterate through controls with variables in path in User Code

Post by Darwin » Fri May 11, 2018 11:18 pm

Thanks--after noticing that I took a much deeper look at how these recording variables are used and how test cases "bind" to them--and, of course, the Repository--and it's going to free me up to do a LOT more in user code now. And considering the limitations of recordings when it comes to logic, looping, and flexibility in general, that's where I want to do most of my testing.