質問

2次元配列変数を定義する必要があります。
リスト変数を使用することができましたが、現在取り組んでいるプロジェクトには配列が必要です。

これはどうやって行われますか?
2次元アレイを介して「ループ」する方法は?

役に立ちましたか?

解決

リストのリストを使ってみてください。拡張変数構文の項目にアクセスする内部リスト

*** Settings ***
Library           Collections

*** Variables ***
@{colors}         red    green    blue
@{animals}        cow    pig    dog
@{things}         ${animals}    ${colors}

*** Test Cases ***
2-Dimensional List
    Log List    ${things}
    Log    The ${things[0][1]} is ${things[1][1]}
.

リストの長さは2で、以下の項目が含まれています。 0:[u'cow '、u'pig'、u'dog '] 1:[U'RED '、U'Green'、u'Blue ']

ブタは緑色

他のヒント

Lists

を使って

配列変数のロボットの用語は「リスト」です。 @{...}を使用して、リストとして変数を指定できます。これは、変数テーブル内のリストを作成する方法、およびリストの作成キーワード:

*** Variables ***
| # create a list in a variable table
| @{Colors} | red | orange | green | blue

*** Test Cases ***
| Example of using lists

| | # create an array inside a test
| | @{Names}= | Create list | homer | marge | bart

| | # Verify that the elements are arrays
| | Length should be | ${Colors} | 4
| | Length should be | ${Names} | 3
.

2次元リストを作成するには、リストのリストを作成できます。

| | ${array}= | Create list | ${Names} | ${Colors}
.

拡張変数構文個々の要素にアクセスできるようにします。

| | log | element 1,1: ${array[1][1]}
.

詳細については、リスト変数を参照してください。 ロボットフレームワークユーザガイド

辞書の使用

辞書を使用して多次元配列をシミュレートすることができます。例えば:

*** Settings ***
| Library | Collections

*** Test Cases ***
| Example of using a dictionary to simulate a two dimensional array
| | ${array}= | Create dictionary 
| | ... | 0,0 | zero, zero
| | ... | 0,1 | zero, one
| | ... | 1,0 | one, zero
| | ... | 1,1 | one, one
| | Should be equal | ${array["1,0"]} | one, zero
.

リストのリストをループする方法を見つけました:

*** Settings ***
Library           Collections

*** Variables ***
@{colors}         red    green    blue
@{animals}        cow    pig    dog
@{things}         ${animals}    ${colors}

*** Test Cases ***
Nested for loop example
    : FOR    ${x}    IN    @{animals}
    \    Keyword with for loop    ${x}

*** Keywords ***
Keyword with for loop
    [Arguments]    ${x}
    :FOR    ${y}    IN    @{colors}
    \    Log  The ${x} is ${y}
.

クレジットは OMBRE42 に行きます。ありがとう!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top