Forum Discussion

sandysang's avatar
sandysang
Contributor
2 years ago

confirm about error :The operation cannot be performed, because the user session is disconnect

Hi , 

Till now, I want to confirm : I trigger the automation test by task schedule on remote desk, but seems failed, and all test cases show the error about :The operation cannot be performed, because the user session is disconnect

and I saw the document that if I need to run successful I need to do the following things :

 

1) do not lock the local computer and do not let computer sleep 

2)change the local registry according the document 

Is there any other things I need to do if I need to run successful ? and I want to know is it the right thing I need to do ? or if I can not do this by permission reason , is there any other method let me to run automation test successful ?

19 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    This is not a limitation of TestComplete but essential behavior of Windows OS that active unlocked user session must exist in order GUI application can render its interface. Without graphical interface  been rendered, UI objects do not exist and thus TestComplete cannot find them.

    There might be more than one way to provide unlocked user session and TC's documentation describes probably one of the most generic ways of how this can be done.

     

    • sandysang's avatar
      sandysang
      Contributor

      Hi  rraghvani

      PREVIEW
       
      I have tried the method, but still failed, because we need to call other windows app for test 
       

      E:\AutomationTest\APPLE\AppleWMS_Test\Script>for /F "skip=1 tokens=3" %s in ('query user hlcla02') do (C:\Windows\System32\tscon.exe %s /dest:console )

      E:\AutomationTest\APPLE\AppleWMS_Test\Script>(C:\Windows\System32\tscon.exe 9 /dest:console )

      E:\AutomationTest\APPLE\AppleWMS_Test\Script>(C:\Windows\System32\tscon.exe 29 /dest:console )

      I have run the bat file before the test, but it still failed

      my test steps is ,run the bat to disconnect then run the test scripts 

      the bat file as following :

      for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
      %windir%\System32\tscon.exe %%s /dest:console
      )

      if I comment the bat file ,the test can run pass, I am not sure why ?

       
       
       
  • I've come up with a WSL2 solution.
    WSL with Ubuntu and remmina app preconfigured to connect to the test environment
    The script below is run from the pipeline to activate remmina session

    REMINNA_FILE_PATH= 'PATH TO YOUR .remmina FILE HERE'
    EXPECTED_ERROR='PDU_TYPE_DATA'
    
    echo $(date)'Started *** *** *** *** *** *** *** ***'
    cat /dev/null >nohup.out
    nohup remmina $REMINNA_FILE_PATH & disown
    
    if timeout 30 tail -n 100 -f ./nohup.out | grep --line-buffered -m 1 $EXPECTED_ERROR; then
      echo $(date) $EXPECTED_ERROR 'catched' $RVALUE
      cat /dev/null >nohup.out
      exit 0
    else
      echo $(date) $EXPECTED_ERROR 'not catched' $RVALUE
      cat /dev/null >nohup.out
      exit 1
    fi

    The issue I didn't figure out:
    The script continues running while the session is active so I just set a 1-minute timeout for this operation in the pipeline.

    BTW It would be cool If someone could give advice, on how to continue running the pipeline after the specific error was caught in the script

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    My setup:

    I have a VM, and I will only use user 'UserX' to log into the machine to run the automation.

     

    I have a batch file, which contains this statement only

    for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console)

    Running this batch file, will disconnect user 'UserX' that's logged on, but the session will remain active.

     

    I have a task schedule setup on the VM, which I can trigger from my local machine using Computer Management (via Connect to another machine option) application. The task schedule runs a PowerShell script, similar to a batch file, which runs SessionCreator using parameters /UseActiveSession and /ScreenResolution:"1920*1080" (or I can run TestExecute)

     

    Running:

    From when the VM is restarted - I log onto the VM using user 'UserX', I then run the tscon batch file to disconnect 'UserX'. I then run the task schedule from my local machine, will which run SessionCreate (or TestExecute) on the VM using the active sessions of user 'UserX'.

    If I log on the VM using 'UserX' and look at Task Manager, Users tab. I will see two active sessions.

    • sandysang's avatar
      sandysang
      Contributor

      Hi rraghvani

      Thank you for you kindly answer

      I think the different is that I use testcomplete.exe to run test, not set the screen size, am not sure whether it is impact 

      and I find the root cause is that : when disconnect function is open, the windows application about company can not connect to database automationally.

      • kakabubu's avatar
        kakabubu
        Contributor

        I can't get it.
        #1. Are you running the tests on your local machine (Machine_1)? 
        Or
        #2. Are you running the tests on another local machine (Machine2), where you are connected by RDP from (Machine_1)?

        IF your case is  #2 
        THEN you should configure these regedit staff on Machine_1 where the RDP session is opened to the Machine_2

        Also, did you try the solution with WSL? Works like magic for me.
        My fault I send you the wrong script in the previous comment. 

        I actually use the inline script in the YAML file:

          - bash: |
              remmina #INSERT YOUR PATH TO .remmina SESSION CONFIG FILE HERE 
            displayName: Take RDP session on WSL
            timeoutInMinutes: 1
            continueOnError: true

        It will always fail by timeout unfortunately, or last forever if you not using the timeout property, so that's why the continueOnErro is here. I just did not invest enough time to make a proper script that will release remmina process and continue the pipeline
         

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    When connected to your remote desktop machine, if you were to run your batch file (do not use tscon or logout), does it run? 

    • sandysang's avatar
      sandysang
      Contributor

      Hi rraghvani 

      I use my computer (machine_1)  remote to remote machine(machine_2)

      then I write python script to call all progress which I need , the scripts step as following :

      1)change to admin to run disconnect

      def is_admin():
      try:
      return ctypes.windll.shell32.IsUserAnAdmin()
      except:
      return False

      if not is_admin():
      ctypes.windll.shell32.ShellExecuteW(None,"runas",sys.executable,"",None,1)

      2) disconnect (call bat file which is show above)
      disconnect_remote()
      3) run test case 
      run_testcomplete()--->subprocess.call(["E:\\AutomationTest\\APPLE\\launchTest.bat", launch_html, launch_xml])

      the bat file config : 

      @echo off

      "c:\Automation\x64\Bin\TestComplete.exe" "E:\AutomationTest\APPLE\AppleWMS_Test\AppleWMS_Test.pjs" /run /project:"Apple_Test" /ExportLog:"%1" /ExportSummary:"%2" /SilentMode /exit

       

      if I do not do step 2 disconnect, the test can pass , if I add the step2, test will failed 

       

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    1. On your remote desktop machine, could you create a batch file that just contains this statement (ensure %1 and %2 are populated)

    "c:\Automation\x64\Bin\TestComplete.exe" "E:\AutomationTest\APPLE\AppleWMS_Test\AppleWMS_Test.pjs" /run /project:"Apple_Test" /ExportLog:"%1" /ExportSummary:"%2" /SilentMode /exit

    Can you run your batch file, to ensure that your automation works?

     

    2. Can you create a task schedule, that will run the above batch file Can you run this task schedule, to ensure your automation works? 

     

    3. Could you create another batch file that just contains this statement

    for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console)

    Can you run this batch file, which will disconnect your sessions.

     

    4. Using your local machine, launch Computer Management, click Actions and select 'Connect to another computer...'. Enter your remote desktop machine name. Once connected, can you run the task schedule that you created in Step 2. Check that your automation has run on the remote desktop machine (look at the ExportLog and ExportSummary results)

     

     

    I want you to test the above scenarios to ensure that they work. 

    • sandysang's avatar
      sandysang
      Contributor

      Hi,

      when I run which you mentioned about 1,2,3 it all can work , but now we find that, when disconnect the remote desk, the test complete still run ,but can not click button 

       

       

      find that it still meet some failed part:

      I create image repository and try to double click it to enter into our system , but failed , it show can not find image and can not do double click when I run under disconnect mode, but when do not under this mode, testcase can pass. I am not sure why ?

       

       
       

       

       
       

       

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Log onto your VM, and launch the task schedule (step 4) from your local machine, you will see the automation running on the VM, and you should then be able to diagnose any issues.

     

    Your VM screen resolution may be of a different size when disconnected, so the image repository will most likely fail. You can within your keyword test, output the screen resolution

    Log.Message("Resolution: " + Sys.Desktop.Width + "x" + Sys.Desktop.Height);

    to ensure it's what you expect.

     

    • sandysang's avatar
      sandysang
      Contributor

      Hi 

      I have test it 

       

       

      the screen size is different between pass and failed test ,so how can I set the screen size before disconnect test ?

    • sandysang's avatar
      sandysang
      Contributor

      Hi 

      even I change the screen size , still can not find the image and the test still failed(I have change the screen size as 1920*1080 which can run successful without disconnect) , and change method is according from Solved: Screen Resolution - SmartBear Community

      without disconnect

      with disconnect

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    As mentioned previous, I use SessionCreator using parameters /UseActiveSession and /ScreenResolution:"1920*1080".

     

    If you were to run Step 4, your automation should run and at least output to the log file, the resolution.

     

    What is the purpose, in your instance, of using the image repository?

    • sandysang's avatar
      sandysang
      Contributor

      Hi rraghvani,

      Thank you for answering me ,Because we need to double click some element, so I create image repository and do double click

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Are you not able to identify the object, using the Object Spy tool?

    • sandysang's avatar
      sandysang
      Contributor

      Hi ,

       

      yes, so we use the image to do double click, our system like bellowing :

       

      we try to double click the middle's link ,when double click , it can enter into the system .we when use spy tool, we can just get all the item can not focus to this link , so we use operations about image based action to do it 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Can the Object Spy tool not identify that link in your "Item Description" column? Also, links are usually single click.

     

    You should check whether your application is supported by TestComplete, see Supported Technologies and Applications

     

    With image based, you need to ensure your environment is correctly setup - e.g. resolution, colour, scaling etc.