Forum Discussion

gus's avatar
gus
Contributor
9 years ago
Solved

The operation cannot be performed, because the user session is disconnected.

Hi,

 

I have a GUI test suite which I need to run on a remote computer according to a schedule, and I came to a problem I seem to unable to circumvent.

 

To put it simple, the test suite performs GUI testing of a rich Windows client. The test package contains a VB script which launches TestExecute and supplies the various parameters required. I run this script on a test machine, accessed via Remote Desktop (that is, if the computer is named XY, the script is run on XY, accessed remotely, and launches TestExecute on XY). As part of this script, I have included a tscon.exe redirection so that the remote desktop window can be closed. I have created a scheduled task running this VB script regularly.

 

When I run the script directly, it properly closes the remote desktop connection, and completes the tests successfully. When run by the task scheduler, it fails at some point with the error The operation cannot be performed, because the user session is disconnected.

 

The relevant portion of my VB script ([...] indicates removed code]:

 

 

' Paramteres --------------------------------------------------------------------------------------
'	

Dim TCPath 		' Path to TestComplete.exe
Dim ProjectSuite	' Full path of the project suite to invoke
Dim LogFolder 		' Path to log folder
Dim IniConfPath 	' Path to the configuration ini file
Dim LetAlone 		' Set to True when test runs on remote desktop which you don't want to 
			' keep open
' Set parameter values
TCPath 		= [...]
ProjectSuite 	= [...]
LogFolder 	= [...]
IniConfPath 	= [...]
LetAlone 	= true

' Global variables --------------------------------------------------------------------------------
'
Dim fso			' For file system access
Dim sh			' Shell object for environment variables

Dim operationalLog	' Log file for Test Complete runtime / command line errors
Dim businessLog		' Test log in MHT format

Dim timestamp		' Timestamp of invocation
Dim sessionName		' Session name for remote desktop sessions


' Preparatory steps -------------------------------------------------------------------------------

silent = false
timestamp = Now()

Set fso = CreateObject("Scripting.FileSystemObject")	
Set sh = CreateObject("WScript.Shell")

[...]
		

' Check if we need to redirect session so that GUI tests can run even when 
' remote desktop session is terminated.
If LetAlone Then
	' Get session name
	sessionName = sh.ExpandEnvironmentStrings("%SESSIONNAME%")	
	
	' Redirect session

' Version 1: when run manually on the remote computer ' sh.Run "tscon.exe " & sessionName & " /dest:console"

' Version 2: when run by task scheduler sh.Run "tscon.exe 0 /dest:console" End If ' Compose command line for test execution Dim command command = [...] ' Launch test sh.Run command, bWaitOnReturn = False

 

When starting manually on the remote desktop, the code line

 

sh.Run "tscon.exe " & sessionName & " /dest:console"

is uncommented, and code line

sh.Run "tscon.exe 0 /dest:console"

is commented. It properly obtains the session name and redirects it to the console, the connection is closed, and the test completes successfully. However I found that task scheduler always creates a session with ID of zero, so for the production configuration, the first line is commented out, and the second is made effective. The script properly closes the connection when run by task scheduler, and it performs successfully one of the GUI tests. This test opens the tested application and measures startup time by waiting for a control on its main screen to appear.

 

The second test is more complex, and it includes steps of clicking a DevEx XtraBars ribbon. This is the point where it fails:

Aliases.Foo.Ribbon.ClickItem("Project|Create Project|New Project|DropDownButton|New Project");

Do you have any tips for a workaround? What other differences may there be between running under a "real" remote session and under the session 0 created or used by Task Scheduler? I cannot get the point why it succeeds under a named session, and why not under session 0.

 

  • Honestly, I don't think you need a VBScript at all... Just have that generic user created with sufficient privileges on the machine, mostly with No-Screen-Saver, and connect to the machine using that account... Configure your taskschedular to run TestComplete with cmdline parameters properly, you can even launch the task manually to check it, then simply exit using the cmd I suggested... Your test will run without you being connected... you can reconnect to it and watch it without even disrupting it...  just make sure you exit properly... by redirecting the session to the console...

     

    Session id of your user is accessible through the task manager, User tab...

     


    gus wrote:

    Hi, I'm sure it helps, however I need to ask for the details. Where and how should I exit from the script with redirection? Do you mean I should replace my call to tscon with the one provided? And how can I make sure that generic user (which is our goal to implement) always runs in session 2?


     Session on which it will run depends on which you have logged in as that user...  that often depends on the amount of users accessing that PC concurrently...

     

     

8 Replies

  • Your issue seems to relate to the ScreenSaver and  GroupPolicies.

    TaskScheduler isn't a standard user, rather a system process, hence not using a "session console"

     

    Your remote session works because you have an "active" console...

    In order to have TaskScheduler run your test, you need to leave your session open so it is used by the task.

     

    So instead of disconnecting the RDP session by script, simply exit it with a redirection so it is left open for the taskScheduler.

     

    I have a generic user that has a No-Screen-Saver policy on each of my virtual machines....  it runs source code updates every night before launching nightly tests... When I set up, I connect using that account to the remote machine and exit using a cmd line : tscon 2 /Dest:Console, so the session stays open for the taskscheduler..

     

    Hope this helps...

    • gus's avatar
      gus
      Contributor

      Hi, I'm sure it helps, however I need to ask for the details. Where and how should I exit from the script with redirection? Do you mean I should replace my call to tscon with the one provided? And how can I make sure that generic user (which is our goal to implement) always runs in session 2?

      • rrivest's avatar
        rrivest
        Contributor

        Honestly, I don't think you need a VBScript at all... Just have that generic user created with sufficient privileges on the machine, mostly with No-Screen-Saver, and connect to the machine using that account... Configure your taskschedular to run TestComplete with cmdline parameters properly, you can even launch the task manually to check it, then simply exit using the cmd I suggested... Your test will run without you being connected... you can reconnect to it and watch it without even disrupting it...  just make sure you exit properly... by redirecting the session to the console...

         

        Session id of your user is accessible through the task manager, User tab...

         


        gus wrote:

        Hi, I'm sure it helps, however I need to ask for the details. Where and how should I exit from the script with redirection? Do you mean I should replace my call to tscon with the one provided? And how can I make sure that generic user (which is our goal to implement) always runs in session 2?


         Session on which it will run depends on which you have logged in as that user...  that often depends on the amount of users accessing that PC concurrently...