YAML variable type

i am using robot framework version=7.4

i want to access the values in a nested dictionary,
for example it is:
ret = [0, {‘2’: {‘data’: [1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18], ‘min’: 1.18, ‘max’: 1.18}, ‘3’: {‘data’: [1.19, 1.19, 1.19, 1.19, 1.19, 1.19, 1.19, 1.19, 1.19, 1.19, 1.19], ‘min’: 1.19, ‘max’: 1.19}, ‘0’: {‘data’: [1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18], ‘min’: 1.18, ‘max’: 1.18}}]
—————————————————————————————————————

i am using variable.yaml that is imported in ***setting*** :

Variables variable.yaml

the yaml is:

SPK:
  RR_P:
    FI: 0 
    AI: 0
  FR_P:
    FI: 2
    AI: 2
  FL_P:
    FI: 1
    AI: 1
  RL_P:
    FI: 3
    AI: 3

the below code fails:

Log To Console ${ret[1]}[${SPK.FR_P.AI}]

error: Dictionary ‘${ret[1]}’ has no key ‘2’


the below code also fails:

Log To Console ${ret[1]}['${SPK.FR_P.AI}']

Dictionary ‘${ret[1]}’ has no key ‘‘2’’


but the below code pass:

${a}    Convert To String   ${SPK.FR_P.AI}

 Log To Console    ${ret[1]}[${a}]

{‘data’: [1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18], ‘min’: 1.18, ‘max’: 1.18}


but the below code pass:

Log To Console ${ret[1]}[2]

{‘data’: [1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18, 1.18], ‘min’: 1.18, ‘max’: 1.18}


  • what is difference? What is the type of variable from YAML in robot view?

There is not that concept. Variables are Python variables, dictionaries in this case. If it was JSON, they should be Python variables still.

Maybe your YAML data is not correct, try adding more identation:

  SPK:
    RR_P:
        FI: 0 
        AI: 0
    FR_P:
        FI: 2
        AI: 2
    FL_P:
        FI: 1
        AI: 1
    RL_P:
        FI: 3
        AI: 3

Thanks,

the question is what is difference between Convert to String keyword and when we add ‘ ‘ in [‘${SPK.FR_P.AI}’] ?

I created example test suite with your data. At first I noticed that the dictionary ret was using wrong quotes. Maybe you are using a MacOS with quotes decoration.

Here are the data files and test suite:
ret_data.py (338 Bytes)
YAML_Test_data.robot (1.7 KB)

data.yaml

SPK:
  RR_P:
    FI: 0 
    AI: 0
  FR_P:
    FI: 2
    AI: 2
  FL_P:
    FI: 1
    AI: 1
  RL_P:
    FI: 3
    AI: 3

It is really a complicated issue, because sometimes we use dictionary keys and other times indexes.

Maybe @pekkaklarck can clarify this.