Forum Discussion

mash_ruves's avatar
mash_ruves
New Contributor
13 years ago

Accessing multiple instance of same 'exe' name

Hi,



What I want to do for my Test App, is a scenario similar to one explained below:



Open 30 instances of Notepad (notepad.exe), and type '1' is 1st instance, '2' in 2nd instance and '3' in 3rd and so on.



And I want to create a loop for above monotonous task.

Please suggest if its possible via TestComplete 9...?



Coz, what I see at present is the name mapping is based on exe name and TC9 tries to add a digit as suffix.

But I want to get this done dynamically.



I hope above query is meaningful.



Thanks,

Manish



Test Script at present:


Sub Test1

  Dim edit

  Call TestedApps.notepad.Run(1, True)

  Set edit = Aliases.notepad.wndNotepad.Edit

  Call edit.Click(11, 11)

  Call edit.Keys("1")

  Call TestedApps.notepad.Run(1, True)

  Set edit = Aliases.notepad1.wndNotepad.Edit

  Call edit.Click(11, 11)

  Call edit.Keys("2")

End Sub




Somewhat expected:


Sub Test1



  Dim edit



For i = 1 to 30

  Call TestedApps.notepad.Run(1, True)

  Set edit = Aliases.notepad(+ Str(i)).wndNotepad.Edit

  Call edit.Click(11, 11)

  Call edit.Keys(Str(i))

Next





End Sub ' Wanted to explain just the expected logic. Discard the syntax errors ;)
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Manish,



    You may try Eval() function. The code will be like this:




    Sub Test1



      Dim edit

      Dim obj



    For i = 1 to 30

      Call TestedApps.notepad.Run(1, True)

      Set obj = Eval("Aliases.notepad" & aqConvert.IntToStr(i))

      Set edit = obj.wndNotepad.Edit

      Call edit.Click(11, 11)

      Call edit.Keys(Str(i))

    Next

    End Sub



    Though this will require creation of 30 identical subtrees in Namemapping and Aliases. I think that the better approach is to not use Aliases and work with native TestComplete objects. Something like this:

    Sub Test1



      Dim edit

      Dim obj



    For i = 1 to 30

      Call TestedApps.notepad.Run(1, True)

      Set obj = Sys.WaitProcess("notepad, i)

      Set edit = obj.Window("Notepad", "* - Notepad", i).Window("Edit", "", 1)

      Call edit.Click(11, 11)

      Call edit.Keys(Str(i))

    Next

    End Sub