Forum Discussion

Largent803's avatar
3 years ago

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.

  • hkim5's avatar
    3 years ago


    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) 

6 Replies

  • 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


    • Largent803's avatar

      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.

      • hkim5's avatar

        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.