示例下场景大纲中的空值在空手道中被视为字符串
null values in Scenario Outline under Examples is considered as string in Karate
reqres.feature
Feature: Reqres api test cases
Scenario Outline: register user post -data driven test of negative scenarios
Given url 'https://reqres.in/api'
And path 'register'
And def payload =
"""
{
"email": "<email>",
"password": "<password>"
}
"""
And request payload
When method post
Then status 400
* print response
* match response == <errorResponse>
Examples:
| email | password | errorResponse |
| null | null | {"error": "Missing email or username"} |
正因为如此,我收到了回复{
"error": "注意:只有定义的用户注册成功"
} 而不是这个响应 {"error": "Missing email or username"}。如何解决这个问题?
请花一些时间阅读此处的文档:https://github.com/karatelabs/karate#scenario-outline-enhancements
我在下面re-written 你的测试。请注意在 Examples:
列名称中使用 !
后缀。
Feature: reqres api test cases
Scenario Outline: data driven test of negative scenarios
Given url 'https://reqres.in/api'
And path 'register'
And request { email: '#(email)', password: '#(password)' }
When method post
Then status 400
And match response == errorResponse
Examples:
| email! | password! | errorResponse! |
| null | null | { error: 'Missing email or username' } |
reqres.feature
Feature: Reqres api test cases
Scenario Outline: register user post -data driven test of negative scenarios
Given url 'https://reqres.in/api'
And path 'register'
And def payload =
"""
{
"email": "<email>",
"password": "<password>"
}
"""
And request payload
When method post
Then status 400
* print response
* match response == <errorResponse>
Examples:
| email | password | errorResponse |
| null | null | {"error": "Missing email or username"} |
正因为如此,我收到了回复{ "error": "注意:只有定义的用户注册成功" } 而不是这个响应 {"error": "Missing email or username"}。如何解决这个问题?
请花一些时间阅读此处的文档:https://github.com/karatelabs/karate#scenario-outline-enhancements
我在下面re-written 你的测试。请注意在 Examples:
列名称中使用 !
后缀。
Feature: reqres api test cases
Scenario Outline: data driven test of negative scenarios
Given url 'https://reqres.in/api'
And path 'register'
And request { email: '#(email)', password: '#(password)' }
When method post
Then status 400
And match response == errorResponse
Examples:
| email! | password! | errorResponse! |
| null | null | { error: 'Missing email or username' } |