API тест | Каратэ | Синтаксическая ошибка при использовании ключевого слова read

Я пытаюсь использовать карате для тестирования 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$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.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$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.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)

Любые предложения о том, что мне может не хватать?


person Shubs    schedule 04.06.2018    source источник
comment
Было бы полезно, если бы вы показали код, который сгенерировал эту ошибку.   -  person Dragonthoughts    schedule 04.06.2018
comment
Функция: образец сценария тестирования карате Сценарий: печать данных в журнале * печать 'hello' Сценарий: чтение данных из файла * def temp = 'hello world' * print temp * def xyz = read ('sample.txt')   -  person Shubs    schedule 04.06.2018
comment
пытаюсь прочитать простой текстовый файл: * def xyz = read ('sample.txt')   -  person Shubs    schedule 04.06.2018


Ответы (1)


Каратэ немного привередничать с пустым пространством, что, на мой взгляд, хорошо, потому что этот аспект качества кода применяется по умолчанию, и вы будете благодарить Karate за это, когда размер вашего набора тестов растет. Если вы используете поддержку Cucumber-IDE, это все равно произойдет автоматически.

Поэтому, пожалуйста, заключите = в пробел, и все будет в порядке.

* def xyz = read('sample.txt')
person Peter Thomas    schedule 04.06.2018
comment
большое спасибо! это сработало. любая подсказка, как «писать» в файл? - person Shubs; 04.06.2018
comment
поддержка записи в файл намеренно отсутствует, она вам никогда не понадобится. вы можете добиться этого, если действительно необходимо, обратитесь к этому ответу и комментариям для получения подробной информации: stackoverflow.com/a/47515880/143475 - person Peter Thomas; 04.06.2018