Robot Framework - How to use Global Variable for different keywords











up vote
-1
down vote

favorite












I have this problem where I need to make a variable accessible from different keywords



I have Tried to use set global variable Keyword.



***Keywords***

Random Name
${Name}= Full Name
set global variable ${Name}

Keyword Name
Random Name
Log ${Name}

Keyword Name2
Random Name
Log ${Name}


*** Test Cases ***
Run Keywords
Keyword Name
Keyword Name2


Full Name Keyword



Import names

def Full_Name(self):

return (names.get_first_name())


Output



enter image description here



So in Keyword Name The value I am getting is John, but in Keyword Name2 The value is Clair. I need to keep the value as John for all of the keywords.



When i try to use the variable without passing the Keyword into the keyword I am not able to access it all.



I also Tried to use set suite variable but that has the Same Result.



Note: Full Name keyword is a custom library to get random names. also this is only a example code










share|improve this question
























  • This code won't run, it is full of errors. If it did run, it likely still wouldn't reproduce the problem since you call Random Name in every keyword so it stands to reason you would get a random name in every keyword (assuming Random Name actually sets ${name} to a random name).
    – Bryan Oakley
    Nov 8 at 11:54












  • This is a sample code (My code is too large to post it here), I am calling the Random Name keyword in every keyword because the global variable ${Name} is not found otherwise, thats my problem, i need to use the ${Name} without passing in the whole keyword. And Random Name does set ${Name} to a random name
    – Wojtek T
    Nov 8 at 12:02












  • @BryanOakley i have edited my answer
    – Wojtek T
    Nov 8 at 12:09










  • The code you posted still doesn't work. I get No keyword with name 'Full Name' found.. When I fix the obvious error, both of the other keywords log "Full Name" just as I would expect.
    – Bryan Oakley
    Nov 8 at 12:16








  • 1




    @WojtekT You should put into an answer and not as an edit to the question itself. :)
    – Bence Kaulics
    Nov 10 at 20:51















up vote
-1
down vote

favorite












I have this problem where I need to make a variable accessible from different keywords



I have Tried to use set global variable Keyword.



***Keywords***

Random Name
${Name}= Full Name
set global variable ${Name}

Keyword Name
Random Name
Log ${Name}

Keyword Name2
Random Name
Log ${Name}


*** Test Cases ***
Run Keywords
Keyword Name
Keyword Name2


Full Name Keyword



Import names

def Full_Name(self):

return (names.get_first_name())


Output



enter image description here



So in Keyword Name The value I am getting is John, but in Keyword Name2 The value is Clair. I need to keep the value as John for all of the keywords.



When i try to use the variable without passing the Keyword into the keyword I am not able to access it all.



I also Tried to use set suite variable but that has the Same Result.



Note: Full Name keyword is a custom library to get random names. also this is only a example code










share|improve this question
























  • This code won't run, it is full of errors. If it did run, it likely still wouldn't reproduce the problem since you call Random Name in every keyword so it stands to reason you would get a random name in every keyword (assuming Random Name actually sets ${name} to a random name).
    – Bryan Oakley
    Nov 8 at 11:54












  • This is a sample code (My code is too large to post it here), I am calling the Random Name keyword in every keyword because the global variable ${Name} is not found otherwise, thats my problem, i need to use the ${Name} without passing in the whole keyword. And Random Name does set ${Name} to a random name
    – Wojtek T
    Nov 8 at 12:02












  • @BryanOakley i have edited my answer
    – Wojtek T
    Nov 8 at 12:09










  • The code you posted still doesn't work. I get No keyword with name 'Full Name' found.. When I fix the obvious error, both of the other keywords log "Full Name" just as I would expect.
    – Bryan Oakley
    Nov 8 at 12:16








  • 1




    @WojtekT You should put into an answer and not as an edit to the question itself. :)
    – Bence Kaulics
    Nov 10 at 20:51













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have this problem where I need to make a variable accessible from different keywords



I have Tried to use set global variable Keyword.



***Keywords***

Random Name
${Name}= Full Name
set global variable ${Name}

Keyword Name
Random Name
Log ${Name}

Keyword Name2
Random Name
Log ${Name}


*** Test Cases ***
Run Keywords
Keyword Name
Keyword Name2


Full Name Keyword



Import names

def Full_Name(self):

return (names.get_first_name())


Output



enter image description here



So in Keyword Name The value I am getting is John, but in Keyword Name2 The value is Clair. I need to keep the value as John for all of the keywords.



When i try to use the variable without passing the Keyword into the keyword I am not able to access it all.



I also Tried to use set suite variable but that has the Same Result.



Note: Full Name keyword is a custom library to get random names. also this is only a example code










share|improve this question















I have this problem where I need to make a variable accessible from different keywords



I have Tried to use set global variable Keyword.



***Keywords***

Random Name
${Name}= Full Name
set global variable ${Name}

Keyword Name
Random Name
Log ${Name}

Keyword Name2
Random Name
Log ${Name}


*** Test Cases ***
Run Keywords
Keyword Name
Keyword Name2


Full Name Keyword



Import names

def Full_Name(self):

return (names.get_first_name())


Output



enter image description here



So in Keyword Name The value I am getting is John, but in Keyword Name2 The value is Clair. I need to keep the value as John for all of the keywords.



When i try to use the variable without passing the Keyword into the keyword I am not able to access it all.



I also Tried to use set suite variable but that has the Same Result.



Note: Full Name keyword is a custom library to get random names. also this is only a example code







variables robotframework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:53









Modus Tollens

4,11632337




4,11632337










asked Nov 8 at 11:27









Wojtek T

971422




971422












  • This code won't run, it is full of errors. If it did run, it likely still wouldn't reproduce the problem since you call Random Name in every keyword so it stands to reason you would get a random name in every keyword (assuming Random Name actually sets ${name} to a random name).
    – Bryan Oakley
    Nov 8 at 11:54












  • This is a sample code (My code is too large to post it here), I am calling the Random Name keyword in every keyword because the global variable ${Name} is not found otherwise, thats my problem, i need to use the ${Name} without passing in the whole keyword. And Random Name does set ${Name} to a random name
    – Wojtek T
    Nov 8 at 12:02












  • @BryanOakley i have edited my answer
    – Wojtek T
    Nov 8 at 12:09










  • The code you posted still doesn't work. I get No keyword with name 'Full Name' found.. When I fix the obvious error, both of the other keywords log "Full Name" just as I would expect.
    – Bryan Oakley
    Nov 8 at 12:16








  • 1




    @WojtekT You should put into an answer and not as an edit to the question itself. :)
    – Bence Kaulics
    Nov 10 at 20:51


















  • This code won't run, it is full of errors. If it did run, it likely still wouldn't reproduce the problem since you call Random Name in every keyword so it stands to reason you would get a random name in every keyword (assuming Random Name actually sets ${name} to a random name).
    – Bryan Oakley
    Nov 8 at 11:54












  • This is a sample code (My code is too large to post it here), I am calling the Random Name keyword in every keyword because the global variable ${Name} is not found otherwise, thats my problem, i need to use the ${Name} without passing in the whole keyword. And Random Name does set ${Name} to a random name
    – Wojtek T
    Nov 8 at 12:02












  • @BryanOakley i have edited my answer
    – Wojtek T
    Nov 8 at 12:09










  • The code you posted still doesn't work. I get No keyword with name 'Full Name' found.. When I fix the obvious error, both of the other keywords log "Full Name" just as I would expect.
    – Bryan Oakley
    Nov 8 at 12:16








  • 1




    @WojtekT You should put into an answer and not as an edit to the question itself. :)
    – Bence Kaulics
    Nov 10 at 20:51
















This code won't run, it is full of errors. If it did run, it likely still wouldn't reproduce the problem since you call Random Name in every keyword so it stands to reason you would get a random name in every keyword (assuming Random Name actually sets ${name} to a random name).
– Bryan Oakley
Nov 8 at 11:54






This code won't run, it is full of errors. If it did run, it likely still wouldn't reproduce the problem since you call Random Name in every keyword so it stands to reason you would get a random name in every keyword (assuming Random Name actually sets ${name} to a random name).
– Bryan Oakley
Nov 8 at 11:54














This is a sample code (My code is too large to post it here), I am calling the Random Name keyword in every keyword because the global variable ${Name} is not found otherwise, thats my problem, i need to use the ${Name} without passing in the whole keyword. And Random Name does set ${Name} to a random name
– Wojtek T
Nov 8 at 12:02






This is a sample code (My code is too large to post it here), I am calling the Random Name keyword in every keyword because the global variable ${Name} is not found otherwise, thats my problem, i need to use the ${Name} without passing in the whole keyword. And Random Name does set ${Name} to a random name
– Wojtek T
Nov 8 at 12:02














@BryanOakley i have edited my answer
– Wojtek T
Nov 8 at 12:09




@BryanOakley i have edited my answer
– Wojtek T
Nov 8 at 12:09












The code you posted still doesn't work. I get No keyword with name 'Full Name' found.. When I fix the obvious error, both of the other keywords log "Full Name" just as I would expect.
– Bryan Oakley
Nov 8 at 12:16






The code you posted still doesn't work. I get No keyword with name 'Full Name' found.. When I fix the obvious error, both of the other keywords log "Full Name" just as I would expect.
– Bryan Oakley
Nov 8 at 12:16






1




1




@WojtekT You should put into an answer and not as an edit to the question itself. :)
– Bence Kaulics
Nov 10 at 20:51




@WojtekT You should put into an answer and not as an edit to the question itself. :)
– Bence Kaulics
Nov 10 at 20:51












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I have found a solution. I wasn't calling the Random Name Keyword in my Test case, and also i created a empty variable in the Variable section



 *** Variables ***
${Name}

***Keywords***

Random Name
${Name}= Full Name
set global variable ${Name}

Keyword Name
Log ${Name}

Keyword Name2
Log ${Name}


*** Test Cases ***
Run Keywords
Random Name
Keyword Name
Keyword Name2


Now I am getting the Desired output






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206818%2frobot-framework-how-to-use-global-variable-for-different-keywords%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    I have found a solution. I wasn't calling the Random Name Keyword in my Test case, and also i created a empty variable in the Variable section



     *** Variables ***
    ${Name}

    ***Keywords***

    Random Name
    ${Name}= Full Name
    set global variable ${Name}

    Keyword Name
    Log ${Name}

    Keyword Name2
    Log ${Name}


    *** Test Cases ***
    Run Keywords
    Random Name
    Keyword Name
    Keyword Name2


    Now I am getting the Desired output






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      I have found a solution. I wasn't calling the Random Name Keyword in my Test case, and also i created a empty variable in the Variable section



       *** Variables ***
      ${Name}

      ***Keywords***

      Random Name
      ${Name}= Full Name
      set global variable ${Name}

      Keyword Name
      Log ${Name}

      Keyword Name2
      Log ${Name}


      *** Test Cases ***
      Run Keywords
      Random Name
      Keyword Name
      Keyword Name2


      Now I am getting the Desired output






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        I have found a solution. I wasn't calling the Random Name Keyword in my Test case, and also i created a empty variable in the Variable section



         *** Variables ***
        ${Name}

        ***Keywords***

        Random Name
        ${Name}= Full Name
        set global variable ${Name}

        Keyword Name
        Log ${Name}

        Keyword Name2
        Log ${Name}


        *** Test Cases ***
        Run Keywords
        Random Name
        Keyword Name
        Keyword Name2


        Now I am getting the Desired output






        share|improve this answer












        I have found a solution. I wasn't calling the Random Name Keyword in my Test case, and also i created a empty variable in the Variable section



         *** Variables ***
        ${Name}

        ***Keywords***

        Random Name
        ${Name}= Full Name
        set global variable ${Name}

        Keyword Name
        Log ${Name}

        Keyword Name2
        Log ${Name}


        *** Test Cases ***
        Run Keywords
        Random Name
        Keyword Name
        Keyword Name2


        Now I am getting the Desired output







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 9:55









        Wojtek T

        971422




        971422






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206818%2frobot-framework-how-to-use-global-variable-for-different-keywords%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation