英文:
Is it possible to allow numbers, maybe booleans, for systemProperty values, in addition to strings
问题
以下是翻译好的部分:
我们希望在一些karate.property设置中使用一个数字,将来可能使用布尔值,但目前好像不允许,布尔值当前以字符串形式发送。我们使用这个值karate.dsRow来确定我们在每个特性文件的Background中传递的索引,应该在我们的json测试数据文件中使用哪个帐户条目。
背景:认证先决条件
- def dataSourceRow = karate.get('karate.dsRow', 1)
- def dataSourceEnv = karate.get('karate.env', 'dev')
- callonce read('../../../../service-config.js') { dsRow: '#(dataSourceRow)' , env: '#(dataSourceEnv)' }
英文:
We would like to use a number, possibly a boolean in the future, value for some karate.property settings, but this does not appear to be allowed, boolean currently sent as string. We use this value, karate.dsRow, to determine which account entry we should use within our json test data file, based on the index passed in, within the Background of each feature file.
Background: Authentication PreRequisites
* def dataSourceRow = karate.get('karate.dsRow', 1)
* def dataSourceEnv = karate.get('karate.env', 'dev')
* callonce read('../../../../service-config.js') { dsRow: '#(dataSourceRow)' , env: '#(dataSourceEnv)' }
答案1
得分: 1
karate.properties
are strings, delegating to the OS system properties etc. Karate has no control over this.
What I suggest is do the conversions when you unpack the variables (I assume from karate.properties['some.name']
. Refer: link
-
def fooString = karate.properties['some.bool'] || 'false'
-
def foo = fooString === 'true'
-
def barString = karate.properties['some.int'] || '8'
-
def bar = parseInt(barString)
英文:
Behind the scenes, karate.properties
are strings, delegating to the OS system properties etc. Karate has no control over this.
What I suggest is do the conversions when you unpack the variables (I assume from karate.properties['some.name']
. Refer: https://github.com/karatelabs/karate#type-conversion
* def fooString = karate.properties['some.bool'] || 'false'
* def foo = fooString === 'true'
* def barString = karate.properties['some.int'] || '8'
* def bar = parseInt(barString)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论