0
votes

I try to get variable ${var_Master} from a txt file and put it in to into list box and ${ValSub} is working fine, but I got error on var ${var_Master}:

**InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified (Session info: chrome=64.0.3282.167) (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 10.0.14393 x86_64)

With the below code example:

  ${var_sub}    Get File    ../resources/var_sub.txt
 @{list}    Split To Lines  ${var_sub}
 ${var_Master}    Get File    ../resources/var_master.txt
 :FOR       ${line}    IN      @{list}

 \   ${ValSub}=   Get Variable Value  ${line}
 \   sleep      1s
 \  select from list by value       name=merchant_id     ${ValSub}
 \  select from list by value       name=master_marchant_id     ${var_Master}
2

2 Answers

0
votes

In Robot Framework there is no need to create custom import routine to create variables as there is a standard keyword for it: Import Variables (Documentation).

In the below example I'm using a file in the YAML markup language which allows for the creation of specific Python and Robot variable types like lists, dictionaries and scalars in human readable format. It is also possible to import a python file declaring the objects as well.

In this example I've created a mock scalar variable master and a mock list variable list to prove that looping is possible and mocked the Select From List By Value as a custom keyword.

vars.yaml

master: master value

list:
  - item 1
  - item 2
  - item 3

example.robot

*** Test Cases ***
TC1
    Import Variables    ${EXECDIR}/vars.yaml

    :FOR       ${line}    IN      @{list}   
    \   sleep      1s   
    \   select from list by value       name=master_marchant_id     ${master}   
    \   select from list by value       name=merchant_id     ${line}    

*** Keywords *** 
Select From List By Value
    [Arguments]    ${locator}    ${value}
    Log    Selecting "${value}" from "${locator}" element.
0
votes

I use this method to solve my problem

${var_master}    Get File    ../resources/var_master.txt
     @{list}    Split To Lines  ${var_master}
     :FOR       ${lineb}    IN      @{list}
     \   ${ValMas}=   Get Variable Value  ${lineb}
    ${var_sub}    Get File    ../resources/var_sub.txt
     @{list}    Split To Lines  ${var_sub}

     :FOR       ${line}    IN      @{list}
     \   ${ValSub}=   Get Variable Value  ${line}

     \   sleep      1s
     \   select from list by value       name=master_marchant_id     ${ValMas}
     \   select from list by value       name=merchant_id     ${ValSub}