Forum Discussion

thebick's avatar
thebick
Occasional Contributor
5 years ago

Create checkpoint from string

How can I create a checkpoint based on the vaue of a string?

Background:

An operation in my desktop application (among other things) creates a file consisting of data lines (a) that could be in any order, and (b) some of which could change per invocation and shouldn't be checked. So a file comparison is out. I need to be able to check the values in the files.

I want to make an actual Checkpoint (not just Log.Warning) of the comparison. But CheckProperty is a function only of aqObject, not aqString.

And I find nothing on SmartBear.com showing how I can make an aqObject from a string.

I am writing the test in Python.

So how?


  • thebick wrote:
    The data are already in a file format, and I do not have the permission to create a .json file. Can I just create an aqObject and assign the text as some property of the object? It may be possible, but I don't see anything in the documentation to indicate if it is, and if so, how to do it.

    aqObject doesn't work that way.  That's kind of what BenoitB was indicating.  You don't need to create a JSON file, necessarily, but you should be able to, for many code languages, create your own custom objects.  JavaScript is pretty easy in that you can simply use the prototyping way of creating objects from functions or even create classes.  You could potentially create a Dictionary object from the available Scripting resources in your Windows environment.  There are  number of ways of doing this... but basically, it's a matter of building some custom code to create your object and assigning the properties.

    But then... you may be complicating things more than you need to.

    You could simply do aqString.Compare (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/compare.html).  Pass in the two strings (The one from your baseline and the one from the application) and test to see if the result of Compare is 0.  If it's zero, they match and you can use Log.CheckPoint to log a "Passed" result.  If it's not zero, they don't match, and you can use Log.Warning or Log.Error (your choice) to log the failure.

    Something like this.


    function stringCheckpoint(baselineString, testString) {
        if aqString.Compare(baselineString, testString, true) = 0 {
             Log.CheckPoint(testString + " is correct")
        }
        else {
             Log.Warning("The two strings do not match", "Baseline: " + baselineString + " Test: " + testString)
    
    }
    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thank you for advice BenoitB!

       

      thebick will this approach work for you? Please let us know.

      • thebick's avatar
        thebick
        Occasional Contributor
        The data are already in a file format, and I do not have the permission to create a .json file. Can I just create an aqObject and assign the text as some property of the object? It may be possible, but I don't see anything in the documentation to indicate if it is, and if so, how to do it.