本文介紹了空手道:[main]info com.tuit.karate-karate.env系統(tǒng)屬性為:空的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!
問題描述
使用生成的令牌嘗試執(zhí)行下一個場景時的令牌身份驗證流獲取錯誤:
[main]infocom.tuit.空手道-空手道系統(tǒng)屬性為:空
我使用了以下代碼:
功能文件:
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
Runner類:
package Runner;
import com.intuit.karate.junit4.Karate;
import com.intuit.karate.KarateOptions;
import org.junit.runner.RunWith;
@RunWith(Karate.class)
@KarateOptions(features = "classpath:Runner/login.feature")
public class LoginRunner{}
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>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>
空手道-config.js
function() {
var env = karate.env; // get system property 'karate.env'
karate.log('karate.env system property was:', env);
karate.configure("ssl", true)
if (!env) {
env = 'qa';
}
var config = {
env: env,
}
if (env == 'dev') {
// customize
// e.g. config.foo = 'bar';
} else if (env == 'e2e') {
// customize
}
return config;
}
注意:令牌身份驗證流執(zhí)行成功
預(yù)期:應(yīng)提取存儲在變量中的令牌并執(zhí)行下一個方案
實際:獲取錯誤[Main]信息com.intuit.karate
-空手道系統(tǒng)屬性為:空
推薦答案
infocom.tuit.karate-karate.env系統(tǒng)屬性為:空
您收到的消息是由于您的空手道配置.js中的代碼
karate.log('karate.env system property was:', env);
如果您以
身份運行maven命令
mvn test -Dkarate.env=e2e
您將得到類似
的內(nèi)容
INFO com.intuit.karate - karate.env system property was: e2e
。
但這不會解決accesToken的問題。
如所述here by Peter Thomas
這些方案應(yīng)獨立運行。
每個方案都應(yīng)該能夠獨立運行。
您可以在單獨的功能中定義身份驗證,并根據(jù)需要在場景中調(diào)用它
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
這篇關(guān)于空手道:[main]info com.tuit.karate-karate.env系統(tǒng)屬性為:空的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,