我想在一种情况下访问多个URL。
当在Background
中定义了URL并在Scenario
中使用了另一个URL时,该URL就会更改。
如果我使用path
,则不会出现这种情况。
它可以修复url
中的Background
吗?
Feature: examples
Background:
* url 'https://jsonplaceholder.typicode.com'
Scenario: get all users and then get the first user by id
Given path 'users'
When method get
Then status 200
Given url 'https://api.github.com/search/repositories'
And param q = 'intuit/karate'
When method get
Then status 200
# The expected behavior is accessed to 'https://jsonplaceholder.typicode.com/users'.
# But the accual behavior is accessed to 'https://api.github.com/search/repositories/users'.
Given path 'users'
When method get
Then status 200
答案 0 :(得分:1)
否,但是如果将Given url 'https://api.github.com/search/repositories'
移至第二个Scenario:
,它将正常工作。
这是故意设计的。查看hello world example。它进行了2次调用,但是url
仅被提及一次,因为第二次调用只是添加了path
。这是典型的REST模式。
因此,如果您确实需要执行其他API调用,则必须使用完整的url
:
Background:
* def baseUrl = 'https://jsonplaceholder.typicode.com'
Scenario: get all users and then get the first user by id
Given url baseUrl
And path 'users'
When method get
Then status 200
Given url 'https://api.github.com/search/repositories'
And param q = 'intuit/karate'
When method get
Then status 200
Given url baseUrl
And path 'users'
When method get
Then status 200