Frames are not well liked it seems. Digging around the web I find that lot of people consider using frames very poor practice. Now I'm not a web developer so I really wouldn't know about that. But what I can tell you is that automating frames can be tricky. There's some things you'll need to know if you want to save yourself a lot of frustration. And here we go (all this stuff is in the context of Test Studio):

  •  You need to find Frames before you can use them

Frames contains objects. If you want to automate the stuff that's inside of a given Frame - you need to find it first. The good news is that Test Studio handles this for you automatically. Let's look at an example:

 

If we click on this button - the button along with its container Frame will get added to the Elements Explorer: 

Frames are located based on a few attributes they may or may not have: BaseURL ; Id ; Index ; Name ; Query. BaseURL is really just the src attribute of the frame by the way.

The bad news is that sometimes one or more of these can be dynamic. That is its value can change over time causing your test not to find the frame and fail with an exception that looks like this:

You will have to remedy the situation by going into the Properties for the Frame and editing the way the Frame is found. The goal is to exclude anything that might be dynamic:

 

If you're getting errors - my advice is to get rid of everything except the BaseURL. Removing the ID, Index or Name values will be a problem. Searching for the wrong ID, Index of Name on the other hand will fail the test.

  • Frames are treated as a browser

This is not going to have a big impact on your automation effort unless you decide to do some coding. Basically a Frame is its own browser that is separate from the actual browser its contained in. So let's go back to the above example and say you want to search for an element inside of the page. You could do something like this:

Element e = Find.ById("myElementId");

This will not work for elements inside of the Frame. It will only search among the things that are outside of the frame. If you want to go into the Frame you'll have to uhm... go into the Frame. You have to invoke the search on the Frame:

Element e = Pages.HttpLocalhost12083HTMLPag.FrameFrame0.Find.ById("MyElementId");

In this instance I'm using Test Studio's definition to access the frame. You will manually need to add it into the Elements Explorer (either by recording inside of the Frame or using "Add To Project elements").

If you're trying to manually invoke a javascript - you will also need to do it on the Frame. So instead of this:

ActiveBrowser.Actions.InvokeScript("$('#item_select').change()");

you would do this:

Browser frm = ActiveBrowser.Frames["Frame_0"];
frm.Actions.InvokeScript("$('#item_select').change()");

About the author

Stoil Stoichev

Stoil Stoychev

has been helping customers solve their complex testing challenges leveraging his in-depth knowledge of Telerik Test Studio. He has traveled the globe fine-tuning his technical expertise and helping our valued clients succeed. In his spare time he enjoys motorcycles, live music and various sports.


Related Posts

Comments

Comments are disabled in preview mode.