Forum Discussion

Petewilson's avatar
Petewilson
Contributor
6 years ago

Running on a specific device, when 2 are connected, defaults back to the 1st connected.

I have a script that  tests a mobile application on 2 different iPads. It is all run through Jenkins and basically the parameters are passed from Jenkins to a text file and TC reads that text file into its Temporary Variables.

 

One of these Variables is called 'Device' and is the name of the, you guessed it, Device. I have 3 devices and if i connect device A to the pc and select it to run from Jenkins it runs fine. It is the same for devices B and C, as long as i only have 1 device connected.

 

It gets a bit more interesting if i have multiple devices connected,say in order A then B. Device A connected and run through jenkins runs fine, but if i select device B, 2nd connected, in Jenkins and run, it installs the application on device B, but then continues running on device A.

 

My code is written in Delphi and i set the Current Device straight from the name in the Variable, which is named the same.

 

procedure SetMobileDevice;
begin
  Mobile.SetCurrent(Project.Variables.Device, 1);
end;

And this is the code that stops running on the device selected and reverts back to the 1st device connected. This is in a different script, but same project than the code above.

procedure OpenAboutScreen;
var 
  TopNav                            : OleVariant;
begin
  TopNav := Aliases.Device.processApplication.window0.toolbar0;
  Topnav.Button('About').Click;
end;

I have connected the devices in a different order to prove it is reverting back to the 1st connected.

 

Any pointers or guidance would be appreciated

 

  • AlexKaras's avatar
    AlexKaras
    6 years ago

    Hi,

     

    You did not mention it initially, but assuming that both devices are with iOS, I would say that you are getting expected behaviour.

    > Aliases.Device.processApplication.window0.toolbar0;

    The case here is that when TestComplete resolves the above line of code, it tries to find the device that meets its identification criteria - i.e. the device with iOS. As soon as such device is found, TestComplete continues with the found device (as it has no reasons to behave differently) and looks for the processApplication object on this device.

     

    You may consider these options to cope with this problem:

    a) Add device name as one more identification parameter for Device object and set it (parameter) to get its value from the project variable (which you initialize to the required value at test start);

    b) If you can guarantee that processApplication is running on the device, you may switch to the Required Children pane for the Device object (see your screenshot) and set processApplication as a required child. With this setting, TestComplete will be instructed to identify device not only by the OS name, but also look for the running application. And if the application is not found for the first device, TestComplete will check another device.

     

    Hope, the above made things more clear.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > Aliases.Device.processApplication

    How Device object is mapped in your NameMapping?

     

    • Petewilson's avatar
      Petewilson
      Contributor

      Morning Alex,

       

      Name mapping screenshot attached. Obviously have something setup incorrectly just not sure what.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        You did not mention it initially, but assuming that both devices are with iOS, I would say that you are getting expected behaviour.

        > Aliases.Device.processApplication.window0.toolbar0;

        The case here is that when TestComplete resolves the above line of code, it tries to find the device that meets its identification criteria - i.e. the device with iOS. As soon as such device is found, TestComplete continues with the found device (as it has no reasons to behave differently) and looks for the processApplication object on this device.

         

        You may consider these options to cope with this problem:

        a) Add device name as one more identification parameter for Device object and set it (parameter) to get its value from the project variable (which you initialize to the required value at test start);

        b) If you can guarantee that processApplication is running on the device, you may switch to the Required Children pane for the Device object (see your screenshot) and set processApplication as a required child. With this setting, TestComplete will be instructed to identify device not only by the OS name, but also look for the running application. And if the application is not found for the first device, TestComplete will check another device.

         

        Hope, the above made things more clear.