在当前特征文件 - 生成空手道随机字母数字字符串(Karate -Generate random a

2019-09-28 01:14发布

I am trying to generate alphanumeric string of length 5 in Karate.I am trying the below code.


Feature: Test user

 Background:

   Given url AM_HOST  
"  
   * def random_string =  

    function(s) {  
      var text = "";  
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";  
      for (var i = 0; i < s; i++)  
        text += possible.charAt(Math.floor(Math.random() * possible.length));  
      return text;  
    }  

    * def sessionId =  random_string(5)  
    * print sessionId  
"  
   >Scenario: Verify return user  
    Given path 'user/<sessionId>'  
    When method get  
    Then status 404  
    And match response.message == "User Not Found" 

我不能够运行this.Can请你让我知道在哪里的代码issues.The的sessionId不黄瓜报告印在功能被删除之前和功能之后also.Should的报价文件。该功能获取打印报告。 谢谢

Answer 1:

我看到的只是语法有关的问题,试试这个,

Feature: Test user

 Background:
 Given url AM_HOST
 * def random_string =
 """
 function(s) {
   var text = "";
   var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
   for (var i = 0; i < s; i++)
     text += possible.charAt(Math.floor(Math.random() * possible.length));
   return text;
 }
 """
 * def sessionId =  random_string(5)

Scenario: Verify return user 
 Given path 'user/' ,sessionId 
 When method get 
 Then status 404 
 And match response.message == "User Not Found"


文章来源: Karate -Generate random alphanumeric string in the current feature file