空手道-在当前特征文件中生成随机字母数字字符串 [英] Karate -Generate random alphanumeric string in the current feature file

查看:98
本文介绍了空手道-在当前特征文件中生成随机字母数字字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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" 

我无法执行此操作.能否让我知道代码在哪里出现问题.sessionId也未打印在黄瓜报告中.是否应在功能文件中删除函数前后的引号.打印在报告中.谢谢

I am not able to run this.Can you please let me know where the code has issues.The sessionId is not printed in cucumber report also.Should the quotes before and after function be removed in the feature file.The function gets printed in report. Thanks

推荐答案

我仅看到语法相关的问题,请尝试

I see syntax related issues only, Try this,

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"

这篇关于空手道-在当前特征文件中生成随机字母数字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆