javascript评估失败,空手道BDD

时间:2019-12-09 13:54:49

标签: javascript bdd karate

我在空手道特征文件中创建了一个javascript函数,如下所示,

* def generateNumber =
      """
        function generateRandomNumberByGivenLength(arg1,arg2) {
              if (arg1 == "GCID") {
                return java.util.UUID.randomUUID() + ''
              }
              else{
                var randomNumberGenerator = Java.type('com.dbs.mdcm.utils.JavaUtils');
                var rg = new randomNumberGenerator();
                return rg.generateRandomNumber(arg2);
              }
        };
      """

Java代码:

public String generateRandomNumber(int n)
    {

        // chose a Character random from this String
        String allowedNumberString = "0123456789";

        // create StringBuffer size of allowedNumberString
        StringBuilder sb = new StringBuilder(n);

        for (int i = 0; i < n; i++) {

            // generate a random number between
            // 0 to allowedNumberString variable length
            int index
                    = (int)(allowedNumberString.length()
                    * Math.random());

            // add Character one by one in end of sb
            sb.append(allowedNumberString
                    .charAt(index));
        }

        return sb.toString();
    }

java文件的路径: com \ dbs \ mdcm \ utils \ JavaUtils.java

有人可以帮助我理解为什么我低于 javascript评估失败错误

java.lang.RuntimeException: javascript evaluation failed: ***'we3lftg9' + generateNumber('CIF',10)***
    at com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:115)
    at com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:103)
    at com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:88)
    at com.intuit.karate.Script.evalJsExpression(Script.java:362)
    at com.intuit.karate.Script.evalKarateExpression(Script.java:284)
    at com.intuit.karate.Script.evalKarateExpression(Script.java:170)
    at com.intuit.karate.Script.assign(Script.java:598)
    at com.intuit.karate.Script.assign(Script.java:524)
    at com.intuit.karate.StepDefs.def(StepDefs.java:305)
    at ✽.* def customerID = 'we3lftg9' + generateNumber('CIF',10)

我正在使用: Java-11和 空手道-0.7.0

这在Java 1.8和空手道0.7.0版本上正常工作。

0 个答案:

没有答案