如何使用空手道框架处理简单的变量和值?

How to work with simple variables and values using Karate Framework?

因为我正在从 https://github.com/intuit/karate#configuration

学习空手道框架

我尝试了以下脚本 (variables.feature) 并执行了。它似乎无法正常工作。谁能帮忙解决这个问题,我附上了我的项目结构供您参考?

Feature: working with variables

Scenario: assigning values to the variables

Given def myVar = 'world'

Then print myVar

* def myNum = myAge

* print myNum

附件:

使用一些代码片段获取以下消息。

您可以使用以下代码片段实现缺少的步骤:

这是我的 pom.xml 文件内容:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.syntel.apitesting</groupId>
  <artifactId>WebservicesTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-apache</artifactId>
        <version>0.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit4</artifactId>
        <version>0.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-testng</artifactId>
        <version>0.6.2</version>
        <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <testResources>
        <testResource>
            <directory>src/test/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </testResource>
    </testResources>        
   </build>
</project>

谢谢

你没有提到你是如何 运行 这个功能的,但让我猜猜,你正在尝试使用 Eclipse IDE 支持。

您能否尝试阅读此问题,看看是否有帮助,谢谢:https://github.com/intuit/karate/issues/90

编辑:我的天哪,您似乎在使用 Java 5 !?请使用Java 8.

EDIT2:正如您在其他答案中所说,您只需要使用 JUnit 运行程序。

终于,我得到了结果并且能够看到正确的响应。早些时候我用 variable.feature 文件来执行,正如我所说的 Right Click -> Run As -> Cucumber Features 这是错误的。转到 TestRunner.java 文件,然后 Right Click -> Run As -> JUnit Test