Saturday, May 14, 2011

Nested frames

Web Application Testing in Ruby
Nested Frames
Sometimes a web page that is referenced by the tag is also a page that contains a tag. This is a nested frame. To deal with this, simply access the nested frame like this:

ie.rame(:name, "rame").rame(:name, "nested_frame")

Web Application Testing in Ruby

Web Application Testing in Ruby

Firewatir (and maybe Watir and Watir-webdriver too) is somewhat stateful when interacting with iframes. Calling frame.locate switches Firewatir's internal context into the frame. Once Firewatir's internal context is switched to the iframe code can interact with that frame's elements. However, interacting with those elements resets Firewatir's context back to the root document. So repeated calls to locate can be used to establish the right internal context before subsequent element interactions. Related bug. Here is a code snippet used to interact with an AJAX button in an iframe that does not respond to click events, but rather responds to a sequence of mousedown/mouseup events.

browser.frame(:index, 1).locate
browser.div(:id, "somebutton").fire_event("onmousedown")
browser.frame(:index, 1).locate
browser.div(:id, "somebutton").fire_event("onmouseup")

Web Application Testing in Ruby

Web Application Testing in Ruby

Why do I get an access denied error when trying to access a frame?
This error message is due to Internet Explorer's attempt to prevent cross-window domain scripting (also known as cross-site scripting, or XSS). For security reasons, IE prevents embedded code in one frame from accessing another if the frame contents come from different domains. Watir runs into the same barriers when you attempt to navigate from a page hosted from one site to a frame hosted by another.

You may try one or more of the following methods to resolve this issue:

Navigate directly to the subframe (and the server that hosts it). That is, instead of having your script click on the link, use ie.goto("").
Add the particular host to the Internet Explorer Trusted Sites list. From IE's menu bar, choose Tools / Internet Options; click on the Security tab; click on the Trusted Sites icon; click on the Sites... button; type the name of the site into the field labelled "Add this Web site to the zone:". You may need to uncheck the box labelled "Require server verification ( https: ) for all sites in this zone." Click OK to finish the process.
Create an alias in the hosts file. This text file is typically in the folder c:\windows\system32\drivers\etc. Add a line in the form foosystem

Replace with the IP address of the host that is serving up the frame contents. Then access the frame using https://foosystem/testsystem.
Set Internet Explorer to its lowest possible security setting. From IE's menu bar, choose Tools / Internet Options; click on the Security tab; click on the Default Level button, and slide the slider to the Low setting; then click on OK to finish the process.
Watir 1.4 If none of these work, and you are still getting annoying error messages about Access Denied when your scripts run, you can turn off these warnings.

ie.logger.level = Logger::ERROR
Many web applications use frames. If you are having trouble accessing objects on a web page, be sure to check to see if the application is using frames. To find out, view the source of the page and look for or