Forum Discussion

ThWatcher's avatar
ThWatcher
Occasional Contributor
12 years ago

Proper Way to Copy String?

Hello and thank for any help anyone can give me.



A couple of weeks back, I added code to my main test routines to save the data file generated by the program under test.  It went like this:

-----------------

DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).WPFObject("Border", "", 1).WPFObject("mDBFileLabel").get_Text();

---------------



The value being copied was of the format (C:\Documents and Settings\username\My Documents\DataModel Projects\20130319-110144.dm')

without the parenthisis.



This worked fine except that at the end of the test run, when it came time to copy the data file to a new location, the variable 'DM_dbPathFileName' was blank.



I finally figured out that what was actually stored in 'DM_dbPathFileName' was a reference to the text in the window and not the actual text.  When the window went away, so did the text(path/filename) that I needed.



I couldn't leave the window open because the window has to be closed to close the file.  Can't copy the file till it is closed.



I fixed it by creating a routine to force the copying of the actual text rather than a reference to the text.

----------------

function GetActualText( Reference )

{

   ref = "'" + Reference + "'";

   return aqString.SubString( ref, 1, GetLength( ref ) - 2 );

}

--------------





My question is: Is there a proper, or at least better, way to do this?





Again, thanks for any help anyone can give.



ThWatcher

4 Replies

  • ThWatcher's avatar
    ThWatcher
    Occasional Contributor
    @Tanya:  I tried using the 'Text' property (I think because it's a label, it uses 'Text' instead of 'wText'), but it still gave me the same problem. 





    I found the problem(a few days after my first post).  Just now have time to post back here just what I found, in case some one else runs into the same.





    The line:

    --------------

    DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).WPFObject("Border", "", 1).WPFObject("mDBFileLabel").get_Text();

    -------------



    Or the line:

    ----------

    DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).WPFObject("Border", "", 1).WPFObject("mDBFileLabel").Text;

    ----------



    is where I'm getting the text from the field in the window that is open during the testing.



    But, this does not copy the text into the var DM_dbPathFileName.  What it does is copy a reference to the text location.



    At the end of the testing, just before I tried to copy the data file created by the program under test, I close the program being tested.  (Have to close the program to close the data file.)  As a result of closing the program, the window where the text resides is closed.  As a result of closing the window, the reference now points to nothing and results in an empty string.



    Every direct copy of the text field that I tried resulted in copying the reference, not the actual text.



    What I ended up doing was to extract the actual text by the following. (I made a function out of it in case I need to do it elsewhere.):



    -------------------------

    function GetActualText( Reference )

    {

       var ref = "'" + Reference + "'";   // Single quotes inside of double quotes.

       var refText = aqString.SubString( ref, 1, aqString.GetLength( ref ) - 2 );

       return refText;

    }

    -----------------------



    Does anyone know if there is there a better way to force the actual text out of a reference to the text?

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Rickie,


     


    I suppose that you can use TestComplete's wText property to get the text from the label. Here is the example:




    DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.

     DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).

      WPFObject("Border", "", 1).WPFObject("mDBFileLabel").wText;



  • Just a shot in the dark, but did you try calling tostring() on the text property?



    DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).WPFObject("Border", "", 1).WPFObject("mDBFileLabel").Text.ToString()
  • ThWatcher's avatar
    ThWatcher
    Occasional Contributor
    I'll give that a try. (May not be able to try it for a few days.  In the middle of testing a release.)



    If it works, or doesn't, I'll post back here.



    Thanks.