Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 空手道:[main]INFO com.intuit.Karate-Karate.env系统属性为:null_Java_Karate - Fatal编程技术网

Java 空手道:[main]INFO com.intuit.Karate-Karate.env系统属性为:null

Java 空手道:[main]INFO com.intuit.Karate-Karate.env系统属性为:null,java,karate,Java,Karate,尝试使用生成的令牌获取错误执行下一个场景时,令牌身份验证后流程: [main]INFO com.intuit.karate-空手道系统属性为:null 我使用了以下代码: 功能文件: Feature: Login Token Authentication http://symex.dyndns.org:6586/ Background: url 'http://symex.dyndns.org:6586/' Scenario: Token Authentication flow * path

尝试使用生成的令牌获取错误执行下一个场景时,令牌身份验证后流程:

[main]INFO com.intuit.karate-空手道系统属性为:null

我使用了以下代码:
功能文件:

Feature: Login Token Authentication http://symex.dyndns.org:6586/
Background: url 'http://symex.dyndns.org:6586/'
Scenario: Token Authentication flow

* path 'token'
* form field grant_type = 'password'
* form field client_id = 'demoapp'
* form field client_secret = 'demopass'
* form field username = 'xxxx
* form field password = 'xxxx'
* method post
* status 200

* def accessToken = response.access_token

Scenario: ForeignCurrencyStockBalance

* path 'api/v1/ForeignCurrencyStockBalance'
* header Authorization = 'Bearer ' + accessToken
# * param access_token = accessToken
* method GET
* status 200
<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>com.MyFirstAPI</groupId>
    <artifactId>MyFirst</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.6.0</maven.compiler.version>
        <karate.version>0.9.3</karate.version>
    </properties>    

    <dependencies>
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>            
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit4</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>       
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-Werror</compilerArgument>
                </configuration>
            </plugin>
        </plugins>        
    </build>       
</project>
跑步者等级:

Feature: Login Token Authentication http://symex.dyndns.org:6586/
Background: url 'http://symex.dyndns.org:6586/'
Scenario: Token Authentication flow

* path 'token'
* form field grant_type = 'password'
* form field client_id = 'demoapp'
* form field client_secret = 'demopass'
* form field username = 'xxxx
* form field password = 'xxxx'
* method post
* status 200

* def accessToken = response.access_token

Scenario: ForeignCurrencyStockBalance

* path 'api/v1/ForeignCurrencyStockBalance'
* header Authorization = 'Bearer ' + accessToken
# * param access_token = accessToken
* method GET
* status 200
<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>com.MyFirstAPI</groupId>
    <artifactId>MyFirst</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.6.0</maven.compiler.version>
        <karate.version>0.9.3</karate.version>
    </properties>    

    <dependencies>
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>            
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit4</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>       
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-Werror</compilerArgument>
                </configuration>
            </plugin>
        </plugins>        
    </build>       
</project>
包运行器;
导入com.intuit.karate.junit4.karate;
导入com.intuit.karate.karate选项;
导入org.junit.runner.RunWith;
@RunWith(空手道类)
@KarateOptions(features=“classpath:Runner/login.feature”)
公共类登录运行程序{}
POM.XML:

Feature: Login Token Authentication http://symex.dyndns.org:6586/
Background: url 'http://symex.dyndns.org:6586/'
Scenario: Token Authentication flow

* path 'token'
* form field grant_type = 'password'
* form field client_id = 'demoapp'
* form field client_secret = 'demopass'
* form field username = 'xxxx
* form field password = 'xxxx'
* method post
* status 200

* def accessToken = response.access_token

Scenario: ForeignCurrencyStockBalance

* path 'api/v1/ForeignCurrencyStockBalance'
* header Authorization = 'Bearer ' + accessToken
# * param access_token = accessToken
* method GET
* status 200
<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>com.MyFirstAPI</groupId>
    <artifactId>MyFirst</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.6.0</maven.compiler.version>
        <karate.version>0.9.3</karate.version>
    </properties>    

    <dependencies>
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>            
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit4</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>       
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-Werror</compilerArgument>
                </configuration>
            </plugin>
        </plugins>        
    </build>       
</project>
注意:令牌身份验证流已成功执行

预期的:应该pic存储在变量中的令牌并执行下一个场景吗

Actual:获取错误[main]信息
com.intuit.karate
-karate系统属性为:null

INFO com.intuit.karate-karate.env系统属性为:null

是由于您的Karate-config.js中的代码而收到的消息

karate.log('karate.env system property was:', env);
如果您以以下方式运行maven命令

mvn test -Dkarate.env=e2e
你会得到这样的结果

INFO com.intuit.karate-karate.env系统属性为:e2e

但这不会解决accessToken的问题。 如前所述 这些场景应该独立运行

每个场景都应该能够独立运行

您可以在单独的功能中定义身份验证,并在需要时在场景中调用它

Scenario: ForeignCurrencyStockBalance
* path 'api/v1/ForeignCurrencyStockBalance'
* def authentication = read('classpath:authentication.feature')
* def userLogin = call authentication
* header Authorization = 'Bearer ' + userLogin.access_token
* method GET
* status 200