accessing yaml variables once imported in a separate yaml file

2,022 views
Skip to first unread message

Jeffrey Cocozziello

unread,
Mar 20, 2017, 4:34:34 PM3/20/17
to robotframework-users
Hi All,

Trying to solve a problem...

Let's say I have a YAML variables file that contains the following:

netelem2_tgen_port_a: &netelem2_tgen_001 "13" # TGen Port A
netelem2_tgen_port_b: &netelem2_tgen_002 "14" # TGen Port B
netelem2_tgen_port_c: &netelem2_tgen_003 "15" # TGen Port C
netelem2_tgen_port_d: &netelem2_tgen_004 "16" # TGen Port D

Now let's say I have another YAML file that I import after this one that looks like the following:

suite_all_ports:
 - *netelem2_tgen_001
 - *netelem2_tgen_002
 - *netelem2_tgen_003
 - *netelem2_tgen_004

Currently this will not work since the anchors cannot be located. I'm guessing the framework converted these to '${netelem2_tgen_port_a}' notation. I have tried also doing something like this:

suite_all_ports:
 - ${netelem2_tgen_001}
 - ${netelem2_tgen_002}
 - ${netelem2_tgen_003}
 - ${netelem2_tgen_004}

but YAML interprets the values in the list as a string value rather than a reference to the robot variables. Does anyone know of any possible solution for this problem? Maybe there is a syntax I am not aware of that would allow me to call on the robot variables in a YAML file?

Thanks,
Jeffrey

Tatu Aalto

unread,
Mar 21, 2017, 2:02:47 AM3/21/17
to jeffrey.c...@gmail.com, robotframework-users
Ugh

I don't quite understand your problem, would it be possible to demonstrate your problem with a example which we all can run?

-Tatu
Send from my mobile

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Cocozziello

unread,
Mar 21, 2017, 8:39:24 AM3/21/17
to robotframework-users, jeffrey.c...@gmail.com
Thanks for the response Tatu. I have created a quick sample to demonstrate the problem I am trying to solve. It can be found here: https://github.com/jcocozzi/robot_yaml

Thanks again,
Jeff
To post to this group, send email to robotframe...@googlegroups.com.

Jeffrey Cocozziello

unread,
Mar 21, 2017, 11:43:21 AM3/21/17
to Kris Ste, robotframework-users
Thanks for the help Kris, but I still have two problems with your solution that make it not ideal for my goals.

Problem 1: 
When the ${port_list} is printed to console it consists of a list of the strings:

['*id001', '*id002', '*id003']

I want these to actually be the values referenced by the id values: ['port1','port2','port3']. Just as occurs when i log ${porta} to console. 

Problem 2:
It would be nice to not have to use '${port_list}=  get dictionary values  ${port_list}' in every test case I want to use this list.

Once again, thanks for the help though. 

Jeff

On Tue, Mar 21, 2017 at 11:20 AM, Kris Ste <kirolp...@gmail.com> wrote:
Hi Jeffrey, 

I've got a solution based on your Git example, although I'm sure there is a better one. Load variables_2.yaml as 
port_list:
  porta: '*id001'
  portb: '*id002'
  portc: '*id003'

And then run test_1.robot as 

*** Settings ***
Documentation    Suite description
Variables   variables_1.yaml
Variables   variables_2.yaml
Library     Collections

*** Test Cases ***
example_test
    log to console  ${porta}
    log to console  ${portb}
    log to console  ${portc}
    ${port_list}=    get dictionary values       ${port_list}
    log to console  ${port_list}
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsubscrib...@googlegroups.com.

Kris Ste

unread,
Mar 21, 2017, 5:03:46 PM3/21/17
to robotframework-users, jeffrey.c...@gmail.com
Hi Jeffrey, 

I've got a solution based on your Git example, although I'm sure there is a better one. Load variables_2.yaml as 
port_list:
  porta: '*id001'
  portb: '*id002'
  portc: '*id003'

And then run test_1.robot as 

*** Settings ***
Documentation    Suite description
Variables   variables_1.yaml
Variables   variables_2.yaml
Library     Collections

*** Test Cases ***
example_test
    log to console  ${porta}
    log to console  ${portb}
    log to console  ${portc}
    ${port_list}=    get dictionary values       ${port_list}
    log to console  ${port_list}


El martes, 21 de marzo de 2017, 13:39:24 (UTC+1), Jeffrey Cocozziello escribió:
Reply all
Reply to author
Forward
0 new messages