简体   繁体   English

如何在Ruby中的多个项目之间共享一些常见的页面对象和黄瓜步骤定义

[英]How can i share some common page objects and cucumber step definitions between multiple projects in Ruby

We have multiple projects that use some common step definitions and page objects in the cucumber tests. 我们有多个项目在黄瓜测试中使用一些常见的步骤定义和页面对象。 I want to not duplicate such common stuff in each projects but would prefer having a way to share these between multiple projects. 我不想在每个项目中重复这些常见的东西,而是希望有一种在多个项目之间共享这些东西的方法。

Has anyone done such a thing before? 有人做过这样的事吗?

I am using Ruby. 我正在使用Ruby。

Shared steps could be packed as gem, and included as a dependency in both projects. 共享的步骤可以打包为gem,并作为两个项目的依赖项包含在内。

For example, we have a gem named 'common', which contains common.rb: 例如,我们有一个名为“ common”的gem,其中包含common.rb:

When(/^I share steps$/) do
  puts "And I do!"
end

Then(/^I should be able to use it from another project$/) do
  puts "seems ok!"
end

Then we could create features/step_definitions/common_steps.rb in every dependent project, which consists of a single line: 然后,我们可以在每个相关项目中创建features/step_definitions/common_steps.rb ,该项目由一行组成:

require 'common'

Then we just use these shared steps like usual: 然后,我们像往常一样使用这些共享步骤:

Feature: Sample
  Scenario: Sample
    When I share steps
    Then I should be able to use it from another project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM