2017-09-14 18 views
1

基本的に私はちょうど空手テストフレームワークから始まりました。おそらく何かが本当にシンプルに欠けていますが、埋め込み式が正しく解決されるようです。それは、印刷ラインに到達したときに続いて、私は値が空のjsオブジェクト{}karate DSLの組み込み式はjsonの値を置き換えません

ある。このような出力を得る

Feature: Test Service 

    Background: 
    * url 'http://testurl:8080' 
    * def localDateTime = Java.type('java.time.LocalDateTime') 

    Scenario: Successful request 

    * def createDateTime = LocalDateTime.now() 
    * def testRequest = 
    """ 
    { 
     createDateTime: "#(createDateTime)", 
     expiryDateTime:"#(localDateTime.now().plusMinutes(5))" 
    } 
    """ 
    * print testRequest 
    * set testRequest.createDateTime = createdTime 
    * print testRequest 

:私はフィーチャーファイルを持っている場合ので、それは同じことカップルの方法がありませんように

16:43:28.580 [main] INFO com.intuit.karate - [印刷] {"createDateTime":{}、 "expiryDateTime":{}} 16:43:28.586 [メイン] DEBUG com.jayway.jsonpath .internal.PathCompiler - キャッシュされたパスを使用する:$ true []

また、パスが設定されているように見えます30.612 [メイン] DEBUG com.jayway.jsonpath.internal.CompiledPath - 評価パス:32:

16:そうのような最初のprint文のための$ [ 'createDateTime'] 16:32:30.613 [メイン] DEBUG com.jayway.jsonpath.internal.JsonReader - パスを$ ['createDateTime']に設定する新しい値2017-09-14T16:32:30.566 16:32:30.629 [main] DEBUG com.jayway.jsonpath.internal.CompiledPath - 評価パス:$ ['expiryDateTime'] 16:32:30.629 [main] DEBUG com.jayway.jsonpath.internal.JsonReader - パスを$ ['expiryDateTime']に設定する2017-09-14T16:37:30.621

誰でもご説明くださいoなぜ私は実際の日付をtestRequestに挿入できないのですか?

ありがとうございます。

答えて

1

これらの日付オブジェクトを文字列に変換すると、問題は解決されると思います。

* def LocalDateTime = Java.type('java.time.LocalDateTime') 
* def createDate = LocalDateTime.now() + '' 
* def expiryDate = LocalDateTime.now().plusMinutes(5) + '' 
* def testRequest = { createDateTime: '#(createDate)', expiryDateTime: '#(expiryDate)' } 
* print karate.pretty(testRequest) 

は、上記の私のために働いているとこれが出力されます:

06:11:47.010 [main] INFO com.intuit.karate - [print] { 
    "createDateTime": "2017-09-15T06:11:46.983", 
    "expiryDateTime": "2017-09-15T06:16:46.990" 
} 
+1

それを行うようです。ありがとうございました! –

関連する問題