Webrat 验证 iframe 或框架集中的内容

发布于 2024-08-16 23:18:56 字数 491 浏览 3 评论 0原文

我正在使用 Cucumber + Webrat + Mechanize 适配器,并且想要测试 iframe 或框架到所选页面中的页面内容。

换句话说:

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

问题当然是最后一步:我需要导航到框架标题并调查其内容。我可以验证框架标签是否在这里

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

这给我留下了两个问题:

  1. 如何读取 src 属性并导航到该页面
  2. 如何导航回原始页面

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

撑一把青伞 2024-08-23 23:18:57

这将回答问题的第一部分

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

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
意中人 2024-08-23 23:18:57

你实际上不必这样做。因为您的浏览器已经自动加载帧,所以您只需告诉 selenium(以及 webrat)您想要查看哪个帧。

When /^I select the "(.*)" frame$/ do |name|
  selenium.select_frame("name=#{name}")
end

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
笔落惊风雨 2024-08-23 23:18:57

在步骤定义中尝试这个:

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

try this in the step definition:

within_frame("headerid") do 
  assert page.has_content? "login details"
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文