Lokman Liton
Lokman Liton

Reputation: 58

Robotframework: Unable to Set Suite variable for the variables of Run Keyword if passes as variable

I have tried to generate unique name for different cases and set that unique name as a Suite variable using minimum keywords, but unable to do this, Can someone help me to get this, Here is my code..

*** Test Cases ***

TC100_Unique Variable Checking
Generate Unique Name for Objects-loop    Product Line
Generate Unique Name for Objects-loop    Models
Generate Unique Name for Objects-loop    Portfolio

*** Keywords ***    
Generate Unique Name for Objects-loop
[Arguments]    ${function}
Set Variable    ${function}
${namePL}=    Run Keyword If    '${function}'=='Product Line'    Run      Keywords    Generate Unique Name    PL-RFT-    ${CURDIR}\\fNameEdit.txt
...    Set Suite Variable    ${namePL}
${nameMOD}=    Run Keyword If    '${function}'=='Models'    Run Keywords    Generate Unique Name    MOD-RFT-    ${CURDIR}\\modNameEdit.txt
...    Set Suite Variable    ${nameMOD}
${namePF}    Run Keyword If    '${function}'=='Portfolio'    Run Keywords    Generate Unique Name    PF-RFT-    ${CURDIR}\\pfNameEdit.txt
...    Set Suite Variable    ${namePF}

Generate Unique Name
[Arguments]    ${suffix}    ${filepath}
${name}=    Get String Plus Number    ${suffix}    ${filepath}
Set Test Variable    ${name}
Write Unique Number    ${filepath}
[Return]    ${name}

Error:

Variable '${namePL}' not found.

Upvotes: 0

Views: 6416

Answers (3)

Lokman Liton
Lokman Liton

Reputation: 58

At-last, I could discovered an solution in a single keyword. Here is the simple code.

 Run Keyword If    '${function}'=='Products'    Run Keywords    Generate  Unique Name    PL-RFT-    ${CURDIR}\\fNameEdit.txt    AND
...    Set Suite Variable    ${namePL}    ${name}

Thanks to all of your opinions.

Upvotes: 2

Bryan Oakley
Bryan Oakley

Reputation: 385830

Consider this block of code:

${namePL}=    Run Keyword If    '${function}'=='Product Line'    Run      Keywords    Generate Unique Name    PL-RFT-    ${CURDIR}\\fNameEdit.txt
...    Set Suite Variable    ${namePL}

This will create a variable named ${namePL} after the other keywords have already run. However, you're trying to call Set Suite Variable as one of these keywords, but it is being called before Run keyword if finishes and thus before ${namePL} has been created.

Upvotes: 0

A. Kootstra
A. Kootstra

Reputation: 6961

The Run If statement does allow for multiple keywords to be executed, however, setting variables based on values also set in the same Run If context is the real problem here. My advice is to split the generation of the ID and the reuse in two different statements.

Upvotes: 0

Related Questions