cancel
Showing results for 
Search instead for 
Did you mean: 

Deciding if a test passes or fails

SOLVED
New Contributor

Deciding if a test passes or fails

Hello

So I am new to Test Complete.

I have written some tests, recorded some scripts etc and it is going well.

However, I am unclear on how I can tell my test when I want it to pass or fail.

 

e.g. suppose I have a desktop application

I have a customers current $ balance

I simulate them depositing $100 into their account

I then want to check that their balance is $100 more than at the start of my test

 

All of this I can do.

But how do I tell TestComplete that the test passes if the balance is $100 more than at the start, but fails if it is not.

Currently TestComplete passes the test if it gets to the end without errors.  If it gets to the end but the balance didn't go up by $100 is still passes the test as it is finished.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Leader

Re: Deciding if a test passes or fails

YO!

 

In script mode You can use these solutions:

 

1) https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.htm...

 

2) Create condition and use within a:

  - Log.Checkpoint()

  - Log.Error() -> this one set test item to status "fail"

  - Log.Warning()

 

3) You can also use the Runner class
https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/script/runner/index....

 

 

View solution in original post

3 REPLIES 3
Community Leader

Re: Deciding if a test passes or fails

YO!

 

In script mode You can use these solutions:

 

1) https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.htm...

 

2) Create condition and use within a:

  - Log.Checkpoint()

  - Log.Error() -> this one set test item to status "fail"

  - Log.Warning()

 

3) You can also use the Runner class
https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/script/runner/index....

 

 

View solution in original post

New Contributor

Re: Deciding if a test passes or fails

Great thank you

Highlighted
Community Hero

Re: Deciding if a test passes or fails

@Wamboo 's suggestions are right on point. 

 

Basically, if you think about how you do test manually, you go through checks.  

 

For the example you gave, as a manual tester, you first make a note of the current balance.  You then perform the action.  Then you make a note of the ending balance.  Then you subtract one from another.  Then you check to see if that result = 100.

 

Translate that into an automated test.

 

1) Make note of the current balance -> Create a variable in your test and store the contents of the property of the on-screen component that contains the balance into that variable.  

e.g. 

var startingBalance;

startingBalance = Aliases.myApp.myForm.customerBalance.wText

2) Run the test

3) Record the ending balance after the test

 

e.g.

var endingBalance

endingBalance = Aliases.myApp.myForm.customerBalance.wText

4) Subtract the values and store the difference -> You'll need to convert the string on screen to an integer and subtract.  Of course, if there are special symbols like $ or something for currency, you may need to peel those out.  But, generically.

 

var balanceDifference

startingBalance = aqConvert.VarToInt(startingBalance)
endingBalance = aqConvert.VarToInt(endingBalance)

balanceDifference = endingBalance - startingBalance

5) Now, check that difference for the desired amount.

 

if (balanceDifference = 100) then Log.Message("The test passed")
else Log.Error("The test failed")

Your job, as an automated tester, is to translate what you do in manual tests into code.  What I've described above probably has some fine tuning that you could do to it, you could use property checkpoints in some way as well, but effectively, that's how you write an automated test.


Robert Martin
[Community Expert Group]
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
Extensions available