Question

So, I want to write seperate tests for several sites but utilise a single framework to do so. I want to structure my Cucumber framework in a way that all code specific to the particular site is not tied up with overall framework code.

At the moment, I have the following structure:

- features
  - site1_feature.feature 
  - site2_feature.feature
  - step_definitions
    - site1.rb
    - site2.rb 
  - support 
    - config 
      - site1_domain.yaml
      - site2_domain.yaml
    - pages 
      - page_object.rb
      - site1_homepage.rb
      - site2_homepage.rb
    - env.rb
    - world_ext.rb

So right now my problem is this:

I can move site1_feature.feature and site1.rb into its own folder, and invoke cucumber on that folder. That's fine, except, everything under the support folder has stuff that belongs to different sites:

  • site1_domain.yaml should go in a folder with the site1 features and SDs

  • page_object.rb is a "abstract" class which I use as a superclass to make PageObjects, such as the code in site1_homepage.rb which I want to package with all the site1 features, etc.

  • env.rb is more general setup code that I want to not be connected to any bunch of tests.

But Cucumber requires the presence of a support dir in the features directory, so I can't see how to get the general framework stuff:

  • page_object.rb
  • env.rb
  • world_ext.rb

seperate from the site-specific test code. Any pointers?

Was it helpful?

Solution

You could extract the common framework files into its own folder, say "common". Then, for each of the sites, you could simply require those common framework files.

For example, you could structure your common framework and site specific folders as:

- common
  - common.rb
  - support 
    - pages 
      - page_object.rb
    - env.rb
    - world_ext.rb 
- site1
  - features
    - site1_feature.feature       
    - step_definitions
      - site1.rb    
    - support 
      - config 
        - site1_domain.yaml
      - pages 
        - site1_homepage.rb      
      - env.rb
- site2
  - features
    - site2_feature.feature       
    - step_definitions
      - site2.rb    
    - support 
      - config 
        - site2_domain.yaml
      - pages 
        - site2_homepage.rb      
      - env.rb     

The common\common.rb would require all of the common framework files:

require 'support\pages\page_object'
require 'support\env'
require 'support\world_ext'

The site1\env.rb (and for site2) would require require the common.rb to get all of the common framework files:

require_relative '../../../common/common'    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top