可以允许在systemProperty值中使用数字和布尔值吗?

huangapple go评论58阅读模式
英文:

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)' }
    可以允许在systemProperty值中使用数字和布尔值吗?
英文:

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)' }

可以允许在systemProperty值中使用数字和布尔值吗?

答案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)

huangapple
  • 本文由 发表于 2023年3月31日 23:56:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900524.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定