嗨,我正在进行空手道测试,我正在尝试迭代 url 列表并进行 http 调用。以下是我的脚本。但是当我运行脚本时出现错误
Feature: test
Background:
* configure ssl = true
* configure httpVersion = 'http2'
* def baseUrls = ['http://localhost:28090', 'https://localhost:28091', 'http://localhost:28092', 'https://localhost:28093', 'http://localhost:28081']
Scenario: Test7
* def retryEndpoint = '/service/v1/id'
* def serviceEndpoint = ''
# Loop through service endpoints
* table baseUrls
| <serviceBaseUrl>
Given url serviceBaseUrl
And path retryEndpoint
When method get
Then status 200
And print response
收到错误
javascript evaluation failed: serviceBaseUrl, ReferenceError: "serviceBaseUrl" is not defined in <eval> at line number 1
知道发生了什么以及如何修复上面的代码吗?
我认为
table
语法使用错误,并且与 Scenario Outline
混淆。请参阅https://stackoverflow.com/a/76618739/143475
这应该会让你继续前进:
Feature:
@setup
Scenario:
* def urls = ['http://localhost:28090', 'https://localhost:28091']
* def data = urls.map(x => ({ baseUrl: x}))
Scenario Outline:
* print 'baseUrl is:', baseUrl
Examples:
| karate.setup().data |