Ask a Question

Locating away where Copying and Pasting Data into a Web Textbox with multiple user accounts


Locating away where Copying and Pasting Data into a Web Textbox with multiple user accounts

I have a Website where I go outside of the Website and Copy in a Word File and a Excel Spreadsheet to the Web Textbox.

The files are the same whether I am in my system or another users system and the file names are the same. The only difference

is going to be the path for getting the files. 

Which property can I setup in TestComplete to select the test to select this file where the users names have changed.

In my case the system has it setup where it is C:\users\Largent\desktop\ and then the files names.


i guess theres many different ways to do this. 

the below is one way, in python.


Assumptions are:

Filepath that you are trying to create is always going to be C:\users\SOMEUSER\Desktop\YOURFILE

YOURFILE above is static (you said that the name remains the same),

and every user is storing that file at the desktop level under their own user account.


Given that each user ALSO works from the same machine each time, each user will have a unique hostname (a computer name essentially).

Using this hostname, we can create a function to input the SOMEUSER value using the below snippet

in the dictionary of the below code snippet, the keys are the hostnames of each individual's machines, and the corresponding values are the individuals names that will go in place of SOMEUSER above

def test1():
    user = Sys.HostName
    id_dict = {
            "SB-MA-123456": "",
            "Some_Other_HostName": "Another.User",  
            "Third Persons Hostname": "Largent",\
    username = id_dict.get(user, "Invalid testCase") #get username by name from dictionary above
    #return username  #output hostname
    filePath = "C:\\users\\" + username + "\\Desktop\\" + "myFile.txt" #this last txt file is static since you said it was so.
    return filePath


with the resulting output of this snippet being that newly created filepath that you wanted.

and you can use this as an input to whatever you are currently doing to open that file



Justin Kim

The host names are on virtual boxes this is how we run this company right now. So a actual host name is is always different depending on the day. My profile remains the same though. In addition and this will be how all testers are login to this although they will have the same Word and Excel files so those are the same.


As for the script do I use this in the Unit test or is there another part of the application that I am missing. Because it did not work at all on my machine.

actually i overcomplicated things

theres a Sys.UserName property that will get you this username. so the script would look like 

def test3():
  username = Sys.UserName
  filePath = "C:\\users\\" + username + "\\Desktop\\" + "myFile.txt" 
  return filePath

and as for where to use it, theres a "Script" test item in your project explorer:


right click, add new item

remember though, the scripting language is the one you chose at the beginning at the time of your project creation. you can also see this in the very bottom of your window while you are in the scrip editor.



and now to use this script snippet in your keyword tests, just drag and drop the relevant script unit into your Keyword test.




Justin Kim

A couple of  last questions my host name changes because I am on a virtual machine. All my settings are set up by my user profile so how do 

I get this set against various user profiles. Second do I need to export my scripts to a script file?





my second reply should solve that problem for you, since we are no longer using hostname, but using the Sys.UserName instead (which should give you the "Largent" or any other username value that you wanted; that is, whoever logged on to the VM with testcomplete should run this script and expect to get their username filled into that path)

as for exporting as a script file, that is not possible (nor would it be helpful, since you cannot run these scripts outside of the TC environment) 

Justin Kim

I worked with Technical Support and here is the way which seems to work for everyone. 

We created a object method with the following parameters:


TestedApps.WINWORD.Params.ActiveParams the operation is a command line set and the code is "/n \"" + aqEnvironment.GetEnvironmentVariable("USERPROFILE") + "\\Desktop\\Myword.docx\" /o"


This seems to be working on for other users.

Showing results for 
Search instead for 
Did you mean: