cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a value back to a TestComplete script?

SOLVED
Contributor

How to pass a value back to a TestComplete script?

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: How to pass a value back to a TestComplete script?

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.

 

 


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

3 REPLIES 3
Highlighted
Community Hero

Re: How to pass a value back to a TestComplete script?

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.

 

 


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
Contributor

Re: How to pass a value back to a TestComplete script?

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 😛

Highlighted
Community Hero

Re: How to pass a value back to a TestComplete script?

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. 🙂


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
New Here?
Join us and watch the welcome video:
Top Kudoed Authors