API 测试 |空手道 |使用 'read' 关键字时出现语法错误

API test | Karate | Syntax Error while using 'read' keyword

我正在尝试使用空手道进行 API 测试。由于请求和响应很长,我需要使用文件来使用它们。但是,'read' 关键字给我一个语法错误:

Scenario: read data from a file  Time elapsed: 0.005 sec  <<< ERROR!
com.intuit.karate.exception.KarateException: syntax error: **'def xyz=read('sample.txt')'**, feature: examples/users/users.featu
re, line: 14
        at com.intuit.karate.cucumber.CucumberUtils.runStep(CucumberUtils.java:247)
        at com.intuit.karate.cucumber.KarateRuntime.runStep(KarateRuntime.java:80)
        at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
        at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
        at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
        at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
        at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58)
        at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
        at com.intuit.karate.junit4.Karate.runChild(Karate.java:134)
        at com.intuit.karate.junit4.Karate.runChild(Karate.java:37)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58)
        at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at com.intuit.karate.junit4.Karate.run(Karate.java:144)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

有什么关于我可能遗漏的建议吗?

空手道 一点 对白色 space 很挑剔,在我看来这是一件好事,因为代码质量的这一方面是默认强制执行的,并且当您的测试套件规模增大时,您会为此感谢 Karate。如果你使用 Cucumber-IDE 支持,这无论如何都会自动发生。

所以请用白色 space 把 = 围起来,这样应该没问题。

* def xyz = read('sample.txt')