我自己的 DSL 位于 rspec、cucumber 之上
我有兴趣在我的 Cucumber webrat BDD 套件上应用另一层抽象,它了解我正在使用的 DOM。
目前我正在编写类似以下示例的步骤定义:
response_body.should have_selector("div", :id => 'left-side-bar') do |div|
div.should have_selector("h1", :content => 'Hello')
... other stuff
end
我知道我可以使用 xpath 和其他各种方式来执行此操作,但我想使用我自己的 DSL,如下所示:
left_sidebar.should have_heading("Hello")
基本上,我想表示我的客户需要此类菜单项的项目特定实体、 DSL 中的块或小部件、列、页眉页脚等。
我该怎么做?这实用吗?我的申请不是铁路申请(如果这很重要)
I'm interested in applying another layer of abstraction on my cucumber webrat BDD suite that knows about the DOM I am working with.
Currently I am writing step definitions something like this example:
response_body.should have_selector("div", :id => 'left-side-bar') do |div|
div.should have_selector("h1", :content => 'Hello')
... other stuff
end
I know I can do this with xpath and various other ways but I want to use my own DSL like this:
left_sidebar.should have_heading("Hello")
Basically, I want to represent the project specific entities my client requires such menu items, blocks or widgety things, columns, header footer and such in the DSL.
How would I do this? Is this practical? My application isn't a rail application (if that matters)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来很像页面对象模式:
http://code.google.com/p /selenium/wiki/PageObjects
这当然很实用,并且您的项目不是 Rails 应用程序也没有什么区别。
基本上,您需要定义一堆对测试站点的页面\组件进行建模的对象,并提供访问这些对象上的页面内容的方法。一个优点是有关页面标记的所有知识都保存在这些对象中,因此如果页面标记发生更改,您只需更新一次。
我倾向于包含有用的辅助方法,例如,在页面上定位 HTML 表并将其转换为哈希数组,以便在 Cucumber 步骤中轻松进行比较。
This sounds a lot like the page object pattern:
http://code.google.com/p/selenium/wiki/PageObjects
It's certainly practical, and makes no difference that your project isn't a rails app.
Basically you need to define a bunch of objects that model the pages\components of the site under test, and provide methods to access the page content on those objects. One advantage is that all of the knowledge about page markup is kept in these objects, so if the markup of the page changes you only need to update in once place.
I tend to include useful helper methods that, for example, locate an HTML table on a page and convert it into an array of hashes for easy comparison in cucumber steps.