Returning values to a robotframework test

4,252 views
Skip to first unread message

Andrew Palmer

unread,
Nov 13, 2013, 5:21:30 PM11/13/13
to robotframe...@googlegroups.com
Hi All,
New to the group, but looking for some help. I've been searching for a few days, so if this is by chance a repost, my apologies.

My structure is having keyword tests in a txt file. I have been using SSHLibrary as well as libraries that I have written in Python. My question is, is there any way to return a value from a python library method back to the test as a variable? For example, if I have the following:

My_Test_Name
   Method Name    ${VAL1}   ${VAL2}

Then, in the python library

def method_name(self, val1, val2):
    string = val1 + val2
    return string

So for example, if I wanted to use the return value from method_name(), can I somehow (have tried with no success):

Test_1
    ${VAL3} = Method Name    ${VAL1}    ${VAL2}

Test_2
    New_Method    ${VAL3}


Hopefully this makes sense, but essentially I'm trying to get the return value out of a method back to the test for use in a later test.

Any help would be much appreciated.

Kevin O.

unread,
Nov 13, 2013, 9:37:29 PM11/13/13
to robotframe...@googlegroups.com
The problem you have here is scope. From the User Guide: "Variables created in test cases from the return values of keywords have a test case scope and they are available only in that test case."
To use the test variable ${VAL3} in another test, you must increase its scope.
Test_1
    ${VAL3} = Method Name    ${VAL1}    ${VAL2}
    Set Suite Variable    ${VAL3}    ${VAL3}

FYI, creating  these kinds of inter-dependencies between tests should be avoided when feasible. If possible put the code in a test or suite setup.

Andrew Palmer

unread,
Nov 13, 2013, 11:28:36 PM11/13/13
to robotframe...@googlegroups.com
Kevin, Thanks for the quick response and information.

I think this might make sense to do both method calls in the same test.

Neel Desai

unread,
Aug 15, 2016, 10:32:27 AM8/15/16
to robotframework-users
I have almost same situation just like Andrew Palmer. though I am getting error.

Here's my script.
click at zoom in
${beforezoom} = returnZoom1
Sleep2
And user keyword implementation for this is:
public static long returnZoom1() {
//doing something
return beforezoom;
}

I am getting this error: 
No keyword with name '${beforezoom} = returnZoom1' found.

Can you tell me where I am doing wrong ?

Bharath Kumar

unread,
Aug 15, 2016, 10:35:33 AM8/15/16
to neelde...@gmail.com, robotframework-users
You should have minimum of three spaces between = and returnZoom1

Error indicates RF is treating ${beforezoom} = returnZoom1 as a single KW whereas   returnZoom1is your keyword.

/Bharath

--
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-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Neel Desai

unread,
Aug 15, 2016, 10:37:12 AM8/15/16
to robotframework-users, neelde...@gmail.com
so do you mean like this  ${beforezoom} = returnZoom1 or  ${beforezoom} =   returnZoom1 ?


On Monday, August 15, 2016 at 9:35:33 AM UTC-5, Bharath Kumar wrote:
You should have minimum of three spaces between = and returnZoom1

Error indicates RF is treating ${beforezoom} = returnZoom1 as a single KW whereas   returnZoom1is your keyword.

/Bharath
On 15 Aug 2016, at 16:32, Neel Desai <neelde...@gmail.com> wrote:

I have almost same situation just like Andrew Palmer. though I am getting error.

Here's my script.
click at zoom in
${beforezoom} = returnZoom1
Sleep2
And user keyword implementation for this is:
public static long returnZoom1() {
//doing something
return beforezoom;
}

I am getting this error: 
No keyword with name '${beforezoom} = returnZoom1' found.

Can you tell me where I am doing wrong ?


--
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.

Bharath Kumar

unread,
Aug 15, 2016, 10:38:13 AM8/15/16
to neelde...@gmail.com, robotframework-users
yes
 ${beforezoom}=      returnZoom1



To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

Neel Desai

unread,
Aug 15, 2016, 10:40:58 AM8/15/16
to robotframework-users, neelde...@gmail.com
thanks it is working now


On Monday, August 15, 2016 at 9:35:33 AM UTC-5, Bharath Kumar wrote:
You should have minimum of three spaces between = and returnZoom1

Error indicates RF is treating ${beforezoom} = returnZoom1 as a single KW whereas   returnZoom1is your keyword.

/Bharath
On 15 Aug 2016, at 16:32, Neel Desai <neelde...@gmail.com> wrote:

I have almost same situation just like Andrew Palmer. though I am getting error.

Here's my script.
click at zoom in
${beforezoom} = returnZoom1
Sleep2
And user keyword implementation for this is:
public static long returnZoom1() {
//doing something
return beforezoom;
}

I am getting this error: 
No keyword with name '${beforezoom} = returnZoom1' found.

Can you tell me where I am doing wrong ?


--
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.

Tatu Aalto

unread,
Aug 15, 2016, 11:46:27 AM8/15/16
to neelde...@gmail.com, robotframework-users

Ugh

If you are using space separated format, there must be two or more spaces after the = character.

-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.
Reply all
Reply to author
Forward
0 new messages