cancel
Showing results for 
Search instead for 
Did you mean: 

Create checkpoint from string

SOLVED
Highlighted
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?

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Create checkpoint from string


@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

View solution in original post

5 REPLIES 5
Highlighted
Community Leader

Re: Create checkpoint from string

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

Highlighted
Community Manager

Re: Create checkpoint from string

Thank you for advice BenoitB!

 

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


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Occasional Contributor

Re: Create checkpoint from string

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.
Highlighted
Community Hero

Re: Create checkpoint from string


@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

View solution in original post

Highlighted
Community Manager

Re: Create checkpoint from string

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

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors