views:

299

answers:

3

I am using Cucumber + Webrat + Mechanize adapter and want to test contents of pages that are iframed or framed into the selected page.

In other words:

Scenario: View header on webpage
  Given I visit a page containing a frameset
  When there is a header frame
  Then I should see login details in frame header

The problem is of course the last step: I need to navigate to the frame header and investigate it's contents. I can verify the frame tag is here

response_body.should have_selector "frame[src][name=header]"

This leaves me with two questions:

  1. How to read the src attribute and navigate to that page
  2. How to navigate back to the original page
A: 

This would answer the first part of the question

Then /^I should see login details in frame header$/ do
  within 'frame[name=header]' do |frame|
    frame_src = frame.dom.attributes["src"].value
    visit frame_src
    response_body.should contain "Log in with digital certificate"
    response_body.should_not contain "Log out"
  end
end
Jesper Rønn-Jensen
A: 

Hi Jesper, you don't actually have to do it that way. Because your browser is already loading the frames automatically, you simply need to tell selenium(and thus webrat) which frame you want to look at.

When /^I select the "(.*)" frame$/ do |name|
  selenium.select_frame("name=#{name}")
end
Joe Martinez
I use mechanize and not selenium in order for my test to run headless. I like the DSL you posted, though. But that does not seem to be implemented in the webrat/mechanize adapter.
Jesper Rønn-Jensen
Ah right, I failed to notice where you mentioned it was mechanize. I wish I could use that but have to test a bunch of Ajax calls as well.
Joe Martinez
A: 

try this in the step definition:

within_frame("headerid") do 
  assert page.has_content? "login details"
end
ikko karima