Forum Discussion

sameerjade's avatar
sameerjade
Frequent Contributor
4 years ago

Parameterizing Regions (images) under Stores in a function

Hello,

I am trying to parameterize regions (images) under Stores but it seems to not work. I tried with these 2 methods, 'Region.Check' and 'Region.Compare'. Here is what I have tried:

 

First workflow:

function ValidateRegion1(myRegion, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam)
{
onscreenObj = myAppWindow;
Regions.myRegion.Check(onscreenObj, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam);
}

Run: ValidateRegion1(myRegion1);

Result: It fails with error: "TypeError: region.Check is not a function"

 

Second workflow:

function ValidateRegion2(myRegion, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam)
{
onscreenObj = myAppWindow.Picture();
Regions.Compare(myRegion, onscreenObj, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam);
}

Run: ValidateRegion2(myRegion1);

Result: It fails with error: Cannot get a picture object from the input parameter. Although I passed the Picture method to my 'myAppWindow' object.

 

Is there a way to parameterize regions so that I can create and use a function for multiple region comparisons?

 

I found this link but here they are showing how to parameterize the 'onscreenObj' object but still hard-coding the region object. My onscreenObj object is going to be same but I have several regions to use for comparison, so I want to parameterize the region object.

https://support.smartbear.com/testcomplete/docs/testing-with/checkpoints/regions/parameterizing.html

 

Any help is appreciated. Thanks!

  • Hi,

     

    It is my guess that you pass string as the value of myRegion input parameter in both cases.

    I.e. you call  ValidateRegion1() function like this:  ValidateRegion1('region1', ...)

    If my guess is correct, then you should use eval() or evaluate() function depending on what is provided by your script language:

    eval('Regions.' + myRegion + '.Check(onscreenObj, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam)');

    and

    Regions.Compare(eval(myRegion), onscreenObj, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam);

     

    Does this help?

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    It is my guess that you pass string as the value of myRegion input parameter in both cases.

    I.e. you call  ValidateRegion1() function like this:  ValidateRegion1('region1', ...)

    If my guess is correct, then you should use eval() or evaluate() function depending on what is provided by your script language:

    eval('Regions.' + myRegion + '.Check(onscreenObj, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam)');

    and

    Regions.Compare(eval(myRegion), onscreenObj, transparentParam, mouseParam, pixelTolParam, colorTolParam, maskParam);

     

    Does this help?

     

    • sameerjade's avatar
      sameerjade
      Frequent Contributor

      The eval() function works perfectly! That is exactly what I needed. Thanks!

       

      Yes, you are correct that I was passing string as the value of myRegion input parameter in both cases.

       

      Regards,