How to use dynamic values for Karate Features

后端 未结 1 1826
感动是毒
感动是毒 2021-01-22 06:45

I\'ve a need where I should use dynamic values in the features of my karate tests.

I\'ve came accross with some of the questions and answers like this: How to read input

1条回答
  •  盖世英雄少女心
    2021-01-22 07:13

    I am providing a simplified example below, but am sure you will find the answers to your questions here. It is easy to loop over data and build XML in Karate using the karate.set(varName, xPath, value) API:

    * table users
      | accountNo   | subsID         | mobile       | subsType  |
      | '113888572' | '113985218890' | '1135288836' | 'asd'     |
      | '113888573' | '113985218891' | '1135288837' | 'qwe'     |
      | '113888582' | '113985218810' | '1135288846' | 'asd'     |
    
    * def xml = 
    * def fun =
    """
    function(u, i) {
      var base = '/users/user[' + (i + 1) + ']/';
      karate.set('xml', base + 'account', u.accountNo);
      karate.set('xml', base + 'mobile', u.mobile);
      karate.set('xml', base + 'type', u.subsType);
    }
    """
    * eval karate.forEach(users, fun)
    * match xml ==
    """
    
      
        113888572
        1135288836
        asd
      
      
        113888573
        1135288837
        qwe
      
      
        113888582
        1135288846
        asd
      
    
    """
    

    0 讨论(0)
提交回复
热议问题