Service Virtualization

Expand all | Collapse all

Edit and save a file using Devtest

Jump to Best Answer
  • 1.  Edit and save a file using Devtest

    Posted 05-03-2016 02:52 PM

    Hi,

    I am trying to open, edit and save a .dat file dynamically during execution. Do we know if Devtest can do that? Thanks in advance for sharing your experiences and/or ideas!



  • 2.  Re: Edit and save a file using Devtest

    Posted 01-13-2017 03:35 PM

    What version of DevTest are you on?



  • 3.  Re: Edit and save a file using Devtest

    Posted 01-30-2017 01:05 PM

    9.5



  • 4.  Re: Edit and save a file using Devtest
    Best Answer

    Posted 01-30-2017 02:27 PM

    I tried this approach in 9.5.1 and it seems to work.  Your final solution will need a bit of work to meet your specific requirements.

    Steps:

    - Create file with extension .dat  ( 1 row containing words "Temp File" )

    - Create a two step test case to read, manipulate, and store the data.

     

    Step 1 - uses the Parse Text as Response step to read the file and store the contents in a property "fl_myFile".  I added a scriptable assertion that places fl_myFile in a local variable, adds the string "\r\n    Added new row" and set the string back into fl_myFile and returns true so as not to trip the assertion into failing the test case.

     

    Step 2 - uses a Do Nothing step and I placed a Save Property Value to File filter on the step.  I filtered in "fl_myFile" and added the location as the same location and file name as the file read in the Parse Text as Response step.

     

    If I do not check the Append Mode option, the file is overwritten with the content in fl_myFile.  If I check the Append Mode, the content is appended to the bottom of the file.

    Sample Data:

    Test Case:

    Step 1: Read Input File Location same as Save Property to File location:

     

    Step 1: Scripted assertion adds content to property:

     

    Step 2: Save Property to File:

     

     

    Result (Append Mode Unchecked causes full replacement):

     

    Result (Append Mode Checked appends content in property to end of file):

    Notice, that the test case is appending the entire amount of content to the file; hence there are two Temp File Created and two Added new row lines.  Add a bit of custom logic to update data in place or add new data as desired.