最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Capybara:Webkit unable to find iframe or its content - Stack Overflow

programmeradmin7浏览0评论

I allow users to share photos with other individuals. When the user is viewing a photo and its description, they can click on "share" and a new page loads. On this page the fill in an email address (and optional ments - not tested here) and click "Share Photo". The systems sends an email to the recipient with a link contained and the subject line includes the name of the photo. The page with the Share form also displays a list of individuals the photo has already been shared with.

The full page load is a source of plaints from users. They want a modal window to quickly load and minimize navigation. I agree.

I use shadowbox.js to load the Share page into an iframe in a modal window. It works well and allows a nice fallback to the old page if needed.

But - I just can't get my tests to pass. In particular, Capybara:Webkit just can't find the iframe.

The environment is: Rail 3.0.9 capybara 0.4.1.2 capybara-webkit 0.5.0 cucumber 1.0.2

The Cucumber story:

Feature: Share photo

@javascript
Scenario: User shares photo
  When I follow "Share"
  Then I should see "Share Old Man Photo" inside "#sb-player"
  And I should see information about who I've shared this photo with
  When I fill in "Share with" with "[email protected]"
  And I press "Share Photo"
  Then "[email protected]" should receive an email with subject "Old Man photo has been shared with you"

My step:

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end

The Fail Message:

(::) failed steps (::)

Unable to locate frame.  (Capybara::Driver::Webkit::WebkitError)
./features/step_definitions/sharing_steps.rb:94:in `/^I should see "([^"]*)" inside "([^"]*)"$/'
features/user_shares_photo.feature:21:in `Then I should see "Share Old Man Photo" inside "#sb-player"'

Failing Scenarios:
cucumber features/user_shares_photo.feature:19 

I've tried every bination of element ids. I just can't get Capybara:Webkit to recognize the iframe.

Any ideas or solutions? I can't deliver with failing test and am considering pitching the whole iframe approach - but I'd like to find a solution.

Thanks

I allow users to share photos with other individuals. When the user is viewing a photo and its description, they can click on "share" and a new page loads. On this page the fill in an email address (and optional ments - not tested here) and click "Share Photo". The systems sends an email to the recipient with a link contained and the subject line includes the name of the photo. The page with the Share form also displays a list of individuals the photo has already been shared with.

The full page load is a source of plaints from users. They want a modal window to quickly load and minimize navigation. I agree.

I use shadowbox.js to load the Share page into an iframe in a modal window. It works well and allows a nice fallback to the old page if needed.

But - I just can't get my tests to pass. In particular, Capybara:Webkit just can't find the iframe.

The environment is: Rail 3.0.9 capybara 0.4.1.2 capybara-webkit 0.5.0 cucumber 1.0.2

The Cucumber story:

Feature: Share photo

@javascript
Scenario: User shares photo
  When I follow "Share"
  Then I should see "Share Old Man Photo" inside "#sb-player"
  And I should see information about who I've shared this photo with
  When I fill in "Share with" with "[email protected]"
  And I press "Share Photo"
  Then "[email protected]" should receive an email with subject "Old Man photo has been shared with you"

My step:

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end

The Fail Message:

(::) failed steps (::)

Unable to locate frame.  (Capybara::Driver::Webkit::WebkitError)
./features/step_definitions/sharing_steps.rb:94:in `/^I should see "([^"]*)" inside "([^"]*)"$/'
features/user_shares_photo.feature:21:in `Then I should see "Share Old Man Photo" inside "#sb-player"'

Failing Scenarios:
cucumber features/user_shares_photo.feature:19 

I've tried every bination of element ids. I just can't get Capybara:Webkit to recognize the iframe.

Any ideas or solutions? I can't deliver with failing test and am considering pitching the whole iframe approach - but I'd like to find a solution.

Thanks

Share Improve this question edited Jul 31, 2011 at 17:55 glimpse nirvana asked Jul 31, 2011 at 15:29 glimpse nirvanaglimpse nirvana 3213 silver badges8 bronze badges 1
  • Does it work with a different Capybara driver? – Mark Thomas Commented Aug 1, 2011 at 18:41
Add a ment  | 

1 Answer 1

Reset to default 6

Need to add time to allow the iframe to open/populate. Sleep 5 did it.

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  sleep 5
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end
发布评论

评论列表(0)

  1. 暂无评论