2

I'm writing scenarios for QA engineers, and now I face a problem such as step encapsulation.

This is my scenario:


  When I open connection    
  And device are ready to receive files
  I send to device file with params:
    | name | ololo |
    | type | txt   |
    | size | 123   |

All of each steps are important for people, who will use my steps. And I need to automate this steps and repeat it 100 times. So I decide create new step, which run it 100 times.

  1. First variant was to create step with other steps inside like:

  Then I open connection, check device are ready and send file with params 100 times:
    | name | ololo |
    | type | txt   |
    | size | 123   |

But this version is not appropriate, because:

  • people who will use it, will don't understand which steps executes inside
  • and some times name of steps like this are to long

    1. Second variant was to create step with other steps in parameters table:

  I execute following steps 100 times:
    | When I open connection                |    
    | And device are ready to receive files | 
    | I send to device file                 | 

It will be easy to understand for people, who will use me steps and scenarios.

But also I have some steps with parameters,

and I need to create something like two tier table:


  I execute following steps 100 times:
    | When I open connection                |    
    | And device are ready to receive files | 
    | I send to device file with params:    |
    |    | name | ololo |                   |
    |    | type | txt   |                   |
    |    | size | 123   |                   | 

This is the best variant in my situation. But of cause cucumber can't parse it without errors ( it's not correct as cucumber code ).

How can I fix last example of step? (mark with bold font)

Does cucumber have some instruments, which helps me?

Can you suggest some suggest your type of solution?

Does someone have similar problems?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
bmalets
  • 3,207
  • 7
  • 35
  • 64
  • Do you really want to open connection and check for device ready 100 times ? From what I understand, your business requirement would be to send the file with required params 100 times, so you could do that after opening connection & checking device ready once itself. otherwise, I'd suggest your first variant is better to use. – Sam Feb 10 '14 at 14:56
  • I came up with these steps just for example. Device works by appropriate protocol. So I have steps like "I send 23.x message", "Then I send 54.x message with parameters: (here table)", "I receive some data", send other type of message. So there's many protocol steps, steps must be encapsulated and visible (it's very important)... – bmalets Feb 10 '14 at 15:09
  • If there's no way to do this, I'll modify Cucumber source... make new methods with necessary functionallity in Cucumber::Core::Ast::DataTable class. – bmalets Feb 10 '14 at 15:13

1 Answers1

2

I decide to change symbols "|" to "/" in parameters table, which are inside. It's not perfect, but it works:

This is scenarios steps:


 I execute following steps 100 times:
    | I open connection                     |    
    | device are ready to receive files     | 
    | I send to device file with params:    |
    |    / name / ololo /                   |
    |    / type / txt   /                   |
    |    / size / 123   /                   |

This is step definition:


And /^I execute following steps (.*) times:$/ do |number, table|

  data = table.raw.map{ |raw| raw.last }
  number.to_i.times do
    params    = []
    step_name = ''
    data.each_with_index do |line,index|
      next_is_not_param = data[index+1].nil? || ( data[index+1] && !data[index+1].include?('/') )
      if !line.include?('/')
        step_name = line
        #p step_name if next_is_not_param
        step step_name if next_is_not_param
      else
        params += [line.gsub('/','|')]
        if next_is_not_param
          step_table = Cucumber::Ast::Table.parse( params.join("\n"), nil, nil )
          #p step_name
          #p step_table
          step step_name, step_table
          params = []
        end
      end
    end
    #p '---------------------------------------------------------'
  end
end

bmalets
  • 3,207
  • 7
  • 35
  • 64