首页 > 解决方案 > 如何将计数传递给动态 json 对象

问题描述

我对 javascript 很陌生。我试图找到一种从 0-5 计数的方法,并将这些数字成对放置,然后调用一个函数来单击与其索引值相关的框。这是我到目前为止所拥有的:

* table deviceValsTable
     | boxLocator    | indexList |
     | brandCheckbox |   [0,1]   |
     | brandCheckbox |   [0,2]   |
     | brandCheckbox |   [0,3]   |
     | brandCheckbox |   [0,4]   |
     | brandCheckbox |   [0,5]   |
     | brandCheckbox |   [1,2]   |
     | brandCheckbox |   [1,3]   |
     | brandCheckbox |   [ect..]   |
 * def indexList = karate.get('indexList')
    * def locator = karate.get('boxLocator')
    * def boxes = locateAll(locator)
    * def clickBox = function(index){ boxes.get(index).click()}
    * karate.map(indexList, clickBox) 

我需要这样做 16 次

标签: javascriptkarate

解决方案


可能最好使用Scenario Outlinehttps ://github.com/intuit/karate#data-driven-tests

Scenario Outline:
* print indexList

Examples:
| indexList! |
| [0, 1]     |
| [2, 0]     |

请注意,Scenario Outline-s 可以采用动态数据源:https ://github.com/intuit/karate#dynamic-scenario-outline

另见循环:https ://github.com/intuit/karate#loops


推荐阅读