cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to test if an element doesnt exist

SOLVED
Highlighted
New Contributor

Best way to test if an element doesnt exist

Hi

 

What is the best way to test if an element doesn't exist in Test Complete?

 

I dont have any sample code to share, but here is a business requirement scenario:

  1. Testcase 1 - check a button is visible for admin
  2. Testcase 2 - check the same button is not visible for user

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

Re: Best way to test if an element doesnt exist

Exists is the only property that does not fail if not found.

 

Another trick I use is adding the "VisibleOnScreen" property to the name mapping of the object so that it does not exist until its actually usable on screen.  Also the "Enabled" property but my particular application this can be unreliable.

 

Another thing to watch out for is the time-outs on negative tests.  If the Project Default is applied you could be waiting a while for a test to pass.  I use 500-1000ms typically but this depends on the application/environment.

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

Re: Best way to test if an element doesnt exist

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

 

Wait for the button or other object to show up and continue depending on the results of the Wait method.

Highlighted
Community Leader

Re: Best way to test if an element doesnt exist

Hi, there is a few possible options:

 

1) WaitWindow

 

var p = Sys.Process("app");

Indicator.PushText('Checking object...');
var obj = p.WaitWindow("propValue", "Value", -1, 1000);
Indicator.Clear();

if(obj .Visible)
    obj.Click();

 

2) Aliases

 

Aliases.app.obj1.RefreshMappingInfo();
var activeObject = Aliases.app.obj1.FindAllChildren("propName", "*");

if(aqObject.GetProperties(activeObject ).Count != 0)
    return true;
else
    return false;

 

3) Exist

 

var p = Sys.Process("Impuls");
var obj= p.WaitWindow("propName", "propValue", -1, 1000);
if(obj.Exists == true) {
     obj.Find("propName", 'propValue', [treeValue]).Click();
}

 

4) Wait for element until it's exist

 

function waitUntil(obj, licznik) {
  var licznik = licznik || 60;
  for (var i = 1; i <= licznik; i++) {
    if (obj.Exists == true) {
      aqUtils.Delay(1000);
    } else {
      break;
    }
  }
}
Highlighted
New Contributor

Re: Best way to test if an element doesnt exist

Hi and thanks for the replies but how would wait or exist work ? Remember these are two different test cases. It should never be visible in Test case 2 so would it not fail as an element not found ?

 

I will read up on Aliases and explore that route.

Highlighted
Contributor

Re: Best way to test if an element doesnt exist

Exists is the only property that does not fail if not found.

 

Another trick I use is adding the "VisibleOnScreen" property to the name mapping of the object so that it does not exist until its actually usable on screen.  Also the "Enabled" property but my particular application this can be unreliable.

 

Another thing to watch out for is the time-outs on negative tests.  If the Project Default is applied you could be waiting a while for a test to pass.  I use 500-1000ms typically but this depends on the application/environment.

View solution in original post

Highlighted
Community Manager

Re: Best way to test if an element doesnt exist

Awesome advice, everyone!

 

@delito Did the replies help? If so, could you mark the best one as a solution? Thank you.


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors