Imagine you are using TestComplete on a home made calculator, and you want to confirm it's computing 2+2 correctly (answer should be 4).
You have a script, "Compare.py" that should looks something like:
def CompareAnswer(n): if n == 4: return true // test continues return false // this should cause the test to fail/stop.
How would I go about sending a value accessed from an object that I am testing back to a script such as one above?
Solved! Go to Solution.
I'm no Python guy... but generally speaking, doesn't matter what language.
Let's say that there is a text field in your calculator application that contains that answer. Let's say, in NameMapping, it looks something like
Aliases.MyCalculator.resultText
Let's say that object is a pretty standard text object. That means that the value of the result would be found in the "wText" property of the object.
So, with all that, given the function you defined in Python, to check 2+2 = 4, you'd perform 2+2 on your calculator and then do
CompareAnswer(Aliases.MyCalculator.resultText.wText)
Within your function, I'd probably convert the "n" parameter to an integer using aqConvert.VarToInt since you're comparing the parameter to the integer 4... this ensures that you are comparing apples to apples.
I'm no Python guy... but generally speaking, doesn't matter what language.
Let's say that there is a text field in your calculator application that contains that answer. Let's say, in NameMapping, it looks something like
Aliases.MyCalculator.resultText
Let's say that object is a pretty standard text object. That means that the value of the result would be found in the "wText" property of the object.
So, with all that, given the function you defined in Python, to check 2+2 = 4, you'd perform 2+2 on your calculator and then do
CompareAnswer(Aliases.MyCalculator.resultText.wText)
Within your function, I'd probably convert the "n" parameter to an integer using aqConvert.VarToInt since you're comparing the parameter to the integer 4... this ensures that you are comparing apples to apples.
You're a beast. That was quick, and well written and easily understandable.
Can't thank you enough.
Now it's time to start looking into name mapping.
You know, if documentation were written by you I think these forums would be a ghost town 😛
Thanks for the kind words. 🙂
As for the documentation.... yeah, it's a help file that tells you, basically, "These are the things that TestComplete has". There are some basic assumptions, though, that generally you have received some sort of basic training in how to use TestComplete or similar automation tool. That's why SmartBear supplies the free monthly 101 training and other similar free webinars that help you learn this kind of stuff.
There was a book written a few years ago by a third party. Look for the TestComplete Cookbook. I think it's a bit out of date (written in 2013) but it MIGHT help you at least get the basics.
In the meantime.... happy to help. That's what these forums are for. 🙂