Forum Discussion

atulghumade's avatar
atulghumade
New Contributor
7 years ago

Use Image from Image repository using for Loop

Hello Team,

Scenario:

"ImageRepository" has few images:

      ImageSet:

                     Image_1

                     Image_2

                     Image_3

                     .

                     .

                     Image_n

 

  • I can simply make "If_else"  and make multiple nested if's and Can use the following Statement:

         ImageRepository.ImageSet.Image_1.ClickM()

 

But How can use "for loop" and call the image from Image repository?

Like,

for n in "456":

  ImageRepository.ImageSet.Image_n.ClickM()

 

  • Hi,

     

    You need to use eval() or evaluate() function, depending on the scripting language of your test project.

    Algorithm:

    -- create a string that represents full name of the image/object;

    -- execute eval() to resolve the string to the object;

    -- call required method of the object.

     

    Sample pseudocode:

    var index = 1;

    var strObjName = aqString.Format('ImageRepository.ImageSet.Image_%i', index);

    var oObj = evaluate(strObjName);

    oObj.ClickM();

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    You need to use eval() or evaluate() function, depending on the scripting language of your test project.

    Algorithm:

    -- create a string that represents full name of the image/object;

    -- execute eval() to resolve the string to the object;

    -- call required method of the object.

     

    Sample pseudocode:

    var index = 1;

    var strObjName = aqString.Format('ImageRepository.ImageSet.Image_%i', index);

    var oObj = evaluate(strObjName);

    oObj.ClickM();