NotExists()waits default time no matter what result is

Class library usage, coding and language questions.
Voland
Posts: 7
Joined: Wed Jul 05, 2017 1:29 pm

NotExists()waits default time no matter what result is

Post by Voland » Mon Jul 10, 2017 9:37 am

Hi, Im using Validate.NotExists(RepoItemInfo itemInfo) method to validate that item was successfully removed.

If I press shift+pause during its work and stop it waiting 1.5 min it reports this success message

Element for item '<element>' does not exist (Failed to find item '<element>'. No element found for path './/element[...] within 1.5m.).

I'm not sure what this means. I thought that it should not wait 1.5min if it does not find corresponding value <exists> in RepoItemInfo object. Can I set the timeout to some smaller value? Is there any other suitable way to solve my task? Or maybe I'm doing something wrong? Help would be appreciated :D

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: NotExists()waits default time no matter what result is

Post by krstcs » Mon Jul 10, 2017 9:05 pm

I think you are misunderstanding how Ranorex works in regards to finding elements.

The timeout value is how long Ranorex will look for an element before it decides it can't find the element and fail. On "NotExists()" this is reversed such that Ranorex will still try to find the element for the whole timeout, and then if it isn't found, it passes. If it is found during the timeout period, that step will fail.
Ranorex needs to know how long you want it to keep looking for an element before it decides it can't find it. If you don't give it some amount of time, it will just keep searching forever. The timeout only tells it the MAX amount of time to search. It will search over-and-over for each matching element for the given path until it either (a) finds the element, or (b) hits the timeout.

Think of it this way: If I told you to stand by the road for 2 minutes and tell me if you see a red car, you would stop waiting after either the 2 minutes or after a red car came by. If you hit the two minutes without a car, you would tell me that the "test" was a failure. If you DID see a red car, you would report success. If I changed it around and said "Check for NO red cars for two minutes", what would you do? You would wait for either two minutes or until you saw a red car. This time you would tell me my request was a failure if you saw the car within two minutes, but would report a success if not.

Ranorex is the same way with it's Exist and NotExists methods, including WaitFor, Validate, etc.
Shortcuts usually aren't...

Voland
Posts: 7
Joined: Wed Jul 05, 2017 1:29 pm

Re: NotExists()waits default time no matter what result is

Post by Voland » Tue Jul 11, 2017 9:03 am

Thanks for clarification, krstcs!

If I map my problem on your example it would look like this:

Ranorex waits for red car to disappear (NotExists()) for 1.5 min
Ranorex knows that car does not exist any longer, yet it waits all the timeout time.
Ranorex reports ?success after the timeout reaches.
Ranorex reports success if I Manually cancel wait (lets say after 10sec of search) for method during test run with Shift+Pause.

The most confusing part is success log together with full timeout waiting.
Logically it should either report success earlier or report failure after timeout of 1.5min.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: NotExists()waits default time no matter what result is

Post by krstcs » Tue Jul 11, 2017 4:18 pm

Ranorex will always wait for the WHOLE timeout, or until it finds the item. You're basically telling Ranorex to search for 1.5 minutes but that if it ever finds that element to fail. That is the NOT in NotExists. Basically it's just a helper method wrapping the Exists() method, and Exists will report TRUE if it finds the element in the timeout, and FALSE if it hits the timeout without finding the element.

NotExists just puts a logical NOT ("!") in front of Exists() like this:

Code: Select all

public bool Exists() {
  if (found) return true;
  return false;
}

public bool NotExists() {
  return !Exists();
}
Shortcuts usually aren't...

Voland
Posts: 7
Joined: Wed Jul 05, 2017 1:29 pm

Re: NotExists()waits default time no matter what result is

Post by Voland » Wed Jul 12, 2017 1:29 pm

Ranorex will always wait for the WHOLE timeout, or until it finds the item
The issue I am talking about concerns the second part of your sentence.
or until it finds the item
As I said, NotExists() reports success message AFTER full time out.
ALSO it will report same success message BEFORE full time out. ( If I press SHIFT + PAUSE to disable this wait during test run )

So I assume that it confirms absence of element almost immediately, yet it waits for full timeout.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: NotExists()waits default time no matter what result is

Post by krstcs » Wed Jul 12, 2017 1:59 pm

That is a false assumption.

When you press 'Shift-Pause' you are ending the timeout prematurely, and since Ranorex hasn't yet found the item at that point, it will pass when using NotExist.

As I said, Ranorex keeps searching until either it finds the object or it hits the timeout (shift-pause ends the timeout early, cancelling the search). If you hit shift-pause while Exists() is working, it will return FALSE because it didn't find the item before you canceled the search.

Again, NotExists is just a negation of Exists.

NotExists() == !Exists()

I'm not sure how else to explain it. :D
Shortcuts usually aren't...

Voland
Posts: 7
Joined: Wed Jul 05, 2017 1:29 pm

Re: NotExists()waits default time no matter what result is

Post by Voland » Thu Jul 13, 2017 8:26 am

I am absolutely aware of the expected logic for such function. And I agree with your statements.

The fact is that it should behave in two ways:

1. NotExists() confirms that element does NOT EXIST :

confirms that element Not exists before timeout => reports SUCCESS message

2. NotExists() DOES NOT confirm that element does NOT EXIST :

hits the wait timeout of 1.5min by default => reports FAILURE message

The issue is that it HITS TIMEOUT and reoports SUCCESS message. It should either report FAILURE, or report this success much earlier, as nothing happens in that period of time. That is what I am talking about. This clearly is a bug. So perhaps this should be moved to "Bug reports".
When you press 'Shift-Pause' you are ending the timeout prematurely, and since Ranorex hasn't yet found the item at that point, it will pass when using NotExist.
It should, but it reports SUCCESS message here. This is not logical.
If I press shift+pause during its work and stop it waiting 1.5 min it reports this success message
I was talking about it in my first post

Voland
Posts: 7
Joined: Wed Jul 05, 2017 1:29 pm

Re: NotExists()waits default time no matter what result is

Post by Voland » Thu Jul 13, 2017 10:45 am

I get it now what you were pointing me at. So basically this is the expected logic for not exists method.

It does not seem logical or convenient for me to use this method with RepoItemInfo without being able to specify the timeout.
Yet I understand that it is as it is, so I will probably think of other solution or implementation of this method.
Thank you for your time and explanations :)

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: NotExists()waits default time no matter what result is

Post by krstcs » Mon Jul 24, 2017 8:16 pm

Sorry for the late response.

Exists offers the ability to override the timeout if you use it from the RepoItemInfo. Validate.Exists/NotExists, only allows it when passing in the path, which you can get from the RepoItemInfo, so it should be possible in your situation.

RepoItemInfo.Exists:
https://www.ranorex.com/Documentation/R ... ists_1.htm

Validate.Exists:
https://www.ranorex.com/Documentation/R ... ists_9.htm
Shortcuts usually aren't...