Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top