Forum Discussion

sonya_m's avatar
sonya_m
Icon for Alumni rankAlumni
5 years ago
Solved

[TechCorner Challenge #2] Dragging One Element to Another

Hi Community! Here's one more interesting challenge for you to complete!

 

Drag and drop is quite a simple task that is performed in TestComplete by using the Drag action. However, it might be that the destination changes its position on the screen, so you need to recalculate the destination coordinates every time.

 

Task: Create a function that takes two objects as parameters and drags the first object to the center of the second one.

Difficulty:

 

Have fun!🙂

 

  • Hi Luukdb!

     

    Your issue here lies in the AqDateTime.Now function. This will return the current date/time in a format that is not compatible with Windows file system naming conventions. 

     

    We have a format function you can use to retrieve the date/time and format it in various ways to match the date/time required and for Windows file name conventions. This is the 'aqConvert.DateTimeToFormatStr' method. 

     

    You can find information for this method here = https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/datetimetoformatstr.html

     

    An example of how to integrate this into your code is below. Note I have a 'log.Message' operation so that we can see what the raw and formatted dates look like.

     

     

    aqFile.Copy("c:\\file1.txt", "c:\\copy\\file1.txt");
    
    function RenameXMLFile()
    {
      
     var timeNowRaw = aqDateTime.Now()
     var timeNowFormatted = aqConvert.DateTimeToFormatStr(timeNowRaw,"%m%d%Y_%H%M")
     
     Log.Message("Unformatted raw date from aqDateTime.Now =  " + aqDateTime.Now())
     Log.Message("Formatted Date = " + aqConvert.DateTimeToFormatStr(timeNowRaw, "%m%d%Y_%H%M"))
     
     var OldPath = "c:\\file1.txt";
     var NewPath = "c:\\copy\\file1copy"+ timeNowFormatted + ".xml";
    
     
     // Renames the file
     aqFileSystem.RenameFile(OldPath, NewPath);
    }