Ask a Question

Create checkpoint from string

SOLVED
thebick
Occasional Contributor

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?

5 REPLIES 5
BenoitB
Community Hero

About creating object from string:

Use JSON parsing  to create an object from a string perhaps ?

I think it's json.loads(myString) that do the job in Python (need import json).

But you must prepare the text file before to be json-compatible.

 

You can also use splitting method which give you an array (see split demo here:  https://support.smartbear.com/testcomplete/docs/scripting/working-with/strings/python.html#Comparing )

 

 

Un sourire et ça repart

sonya_m
SmartBear Alumni (Retired)

Thank you for advice BenoitB!

 

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


Sonya Mihaljova
Community and Education Specialist

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.
tristaanogre
Esteemed Contributor


@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)

}

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
sonya_m
SmartBear Alumni (Retired)

Thank you Community!

 

@thebick did this answer your question? If yes, please mark the best answer as a solution for future referenceSmiley Happy


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: