获取MD5 hasmap进行比较

时间:2018-06-07 04:03:32

标签: import karate

我正在尝试使用空手道获取字符串的MD5哈希值进行比较。

我创建了一个具有以下内容的common.feature:

  • 功能:跨

  • 使用的常用方法
  • 背景

    def getMDhash = function(pdfFile){return DigestUtils.md5Hex(pdfFile).toUpperCase()}
    
  • 场景:示例,使用其他要素文件进行调用:

    • 功能:全部计算
  • 情景:试错

    call read('common.feature')
    def final = getMDhash('my first attempt')
    print final
    

我已添加:

import org.apache.commons.codec.digest.*; 

在* test.java文件中。

但是,执行时我仍然遇到此错误:

  

场景:试验和错误经过的时间:0.019秒<<<错误!   java.lang.RuntimeException:javascript评估失败:getMDhash('我的第一次尝试')           在com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:115)           at com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:103)           在com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:88)           在com.intuit.karate.Script.evalJsExpression(Script.java:362)           在com.intuit.karate.Script.evalKarateExpression(Script.java:284)           在com.intuit.karate.Script.evalKarateExpression(Script.java:170)           在com.intuit.karate.Script.assign(Script.java:598)           在com.intuit.karate.Script.assign(Script.java:524)           在com.intuit.karate.StepDefs.def(StepDefs.java:305)           在?。* def final = getMDhash('我的第一次尝试')(testSuite / users / dummy.feature:7)   引起:javax.script.ScriptException:ReferenceError:“DigestUtils”未在第1行定义           在jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470)           在jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:454)           在jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406)           在jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402)           在jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)           在javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)           在com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:108)           at com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:103)           在com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:88)           在com.intuit.karate.Script.evalJsExpression(Script.java:362)           在com.intuit.karate.Script.evalKarateExpression(Script.java:284)           在com.intuit.karate.Script.evalKarateExpression(Script.java:170)

1 个答案:

答案 0 :(得分:0)

你似乎错过了DigestUtils的负担。尝试:

* def getMDhash = function(pdfFile){ var DigestUtils = Java.type('replace.me.DigestUtils'); return DigestUtils.md5Hex(pdfFile).toUpperCase(); }

有关类似示例,请参阅文档的此部分:https://github.com/intuit/karate#http-basic-authentication-example