This is a migrated thread and some comments may be shown as answers.

What is the best practice / solution to verify that an element DOES NOT exist using a coded step?

3 Answers 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gregory
Top achievements
Rank 1
Gregory asked on 10 Mar 2014, 02:19 AM
I am trying to verify that a web element does not exist based on a database flag.  Based on the flag, a notification badge will display on-screen.  To verify that it displays when the DB flag = TRUE, I am using element.isvisible.  This will not work for verifiying when the DB flag = FALSE because the element is not created and cannot be found (so the test fails).  I am assuming (perhaps incorrectly) that I can somehow use some type of NOT EXISTS on the element.  How would this be done or is this even the best way to go about it?

3 Answers, 1 is accepted

Sort by
0
Accepted
Shashi
Top achievements
Rank 1
answered on 10 Mar 2014, 11:59 AM
Gregory,

Here is how I would do this (Telerik or others may give you other ways - or you may come up with some yourself after reading this):
a) Get the application into the state where the notification is visible (if you already have a test written to get you to that point, use Run to Step to run up to the appropriate step and then go into record mode).
b) Record Wait for Exists and Wait for Visible statements on the badge element (don't worry about the check for the db flag at this point - you will build that in later).
c) Convert the Wait for Exists to a Wait for Not exists (you can do this from the Step properties).  You may also want to reduce the timeout to a sufficiently short time. This is so that test is not waiting unnecessarily in the scenario where the notification is not expected - however, it should wait long enough to catch the notification if it does appear when it shouldn't.
d) Convert both steps into coded steps
e) Modify one of the coded steps to the following (this is pseudo-code).  Depending on which coded step you modify, copy the code of the other Wait statement into this coded step.
    if (db flag = True)
        Wait for Visible on notification flag
    else
        Wait for Not Exists on notification flag
f) Delete the other coded step. 

By the way, if the db flag is user-configurable (it may be called something else), you may want to consider having the test go to the appropriate screen and extract the value first (into an extracted variable) and then use that value in the checks.  This is better than querying the database directly as it keeps the test operating entirely on the UI layer (as they should wherever possible - since they are supposed to use the application like an end user would).

Hope that helps,
Shashi
0
Gregory
Top achievements
Rank 1
answered on 10 Mar 2014, 08:38 PM
Shashi,

Thanks so much for the help...this did exactly what I needed it to do!
0
Boyan Boev
Telerik team
answered on 11 Mar 2014, 12:05 PM
Hi,

@Shashi, we appreciated your help. I have updated your Telerik point.

@Gregory, I am glad to hear that Shashi could help you. If you need further assistance, please let us know.

Regards,
Boyan Boev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Gregory
Top achievements
Rank 1
Answers by
Shashi
Top achievements
Rank 1
Gregory
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or