如何将页面对象模式与 Cucumber 和 Webrat / Selenium 一起使用?

发布于 2024-08-27 18:27:23 字数 514 浏览 4 评论 0原文

我正在查看一个黄瓜测试套件,它现在有点脆弱;许多小步骤,并且对页面本身一无所知。

我想分解出一系列 Selenium PageObjects 中的步骤定义所涉及的逻辑。 作为

但是,因为我使用的是 Webrat 而不是 Selenium,所以一切都必须通过 Webrat 模型。所以我不能这样做,

class MyPage < Selenium::WebPage

end

因为这增加了直接依赖。

因此,我必须通过 Webrat 路由所有内容,同时仍然保持 Selenium Page 对象的优点。我看不到这方面的文档:如果有人有关于 Webrat + PageModel 的任何内容,我很乐意看到它。

I'm looking at a cucumber test suite that is somewhat brittle right now; many small steps, and no knowledge of the page itself.

I'd like to factor out the logic involved in the step definitions inside a series of Selenium PageObjects. As seen here.

However, because I'm using Webrat and not Selenium, everything has to go through the Webrat model. So I cannot do

class MyPage < Selenium::WebPage

end

because that adds a direct dependency.

So I have to route everything through Webrat while still maintaining the Selenium Page object goodness. No documentation on this that I can see: if someone has anything on Webrat + PageModel I'd love to see it.

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

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

发布评论

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

评论(2

人事已非 2024-09-03 18:27:23

结果答案是:

class MyPage < BasePage
  def visit
    @world.visit "/"
  end

end

class BasePage
  def initialize(world)
    @world = world
  end
end

然后在步骤定义中:

Given /I am awesome/ do
  page = MyPage.new(self)
  page.visit
end

Turns out the answer is:

class MyPage < BasePage
  def visit
    @world.visit "/"
  end

end

class BasePage
  def initialize(world)
    @world = world
  end
end

And then in a step definition:

Given /I am awesome/ do
  page = MyPage.new(self)
  page.visit
end
(り薆情海 2024-09-03 18:27:23

我们刚刚发布了一些听起来就像您想要的东西。
看看 Gizmo - http://rubygems.org/gems/gizmo/
与 (webrat | capybara)、(cucumber | rspec) 等配合使用。

we just released something that sounds just like what you were after.
take a look at Gizmo - http://rubygems.org/gems/gizmo/
works with (webrat | capybara), (cucumber | rspec) etc..

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