1
嘗試使用PATCH方法將POST方案的響應引用傳遞給另一個方案,並更改其中一個屬性並獲取錯誤。搗毀源代碼我發現當爲一個場景調用Scripts.assign時,變量作用域不會傳遞給另一個場景。通過不同的方案傳遞已定義的變量不起作用
- 空手道版本:0.5.0
- Java版本:1.8
測試的全部功能:
Feature: Products CRUD Test
Background:
* url demoBaseUrl
Scenario: fetch some products
Given path 'products'
When method get
Then status 200
And assert response.size() === 6
Scenario: add a product
Given path 'products'
And request {name: 'Iphone 7 Plus 128GB', description: 'Iphone 7 Plus Space Gray 128GB' }
When method post
Then status 200
And match response contains { id: '#number', name: 'Iphone 7 Plus 128GB', description: 'Iphone 7 Plus Space Gray 128GB'}
And def newProduct = response
Scenario: update a product
Given path 'products'
And def payload = {name: '#(newProduct.name)', description: '#(newProduct.description)'}
And set payload $.id = #(newProduct.id)
And match payload.id == (newProduct.id)
And request payload
When method patch
Then status 200
And match response contains {name: 'New Product Iphone 7'}
我嘗試將def var移動到背景,但分配發生兩次。我嘗試在後臺定義一個範圍變量,但是在每個場景評估中,範圍var都重新定義。在def scope var中調用一次這個問題就可以解決了嗎? –
如何在後臺聲明一個帶有callonce的變量? –
@ViniciusSouza你可以看看空手道演示 - 其中一個例子是callonce:https://github.com/intuit/karate/tree/master/karate-demo –