How to execute python script(.py) in Robot framework

15,111 views
Skip to first unread message

Ellendula Sainath

unread,
Apr 18, 2016, 6:35:56 AM4/18/16
to robotframework-users
Hi,

Automated few scripts in python(.py) and i would like to execute the same test case in Robot framework.

for example:

i have .py script:

a,b = 20,20
if (a <> b):
    print "true"
else:
    print "false"

Can anyone please guide me the process to execute the above testcase in Robot framework.

Regards,
Sainath

Tatu Aalto

unread,
Apr 19, 2016, 1:37:19 AM4/19/16
to ellendul...@gmail.com, robotframework-users

Ugh

If you are going to only use that script from Robot Framework, then perhaps it would be best to format that script as a library [1]. If you are going to run the script also somewhere else than in the Robot Framework, you could use Process [2] library to run it. It is also combine the two options, by example using the hybrid or dynamic library[1] API.

There is many ways to what you want and which way to go depends on your needs.

-Tatu
[1] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries
[2] http://robotframework.org/robotframework/latest/libraries/Process.html

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

Ellendula Sainath

unread,
Apr 19, 2016, 6:18:45 AM4/19/16
to robotframework-users, ellendul...@gmail.com
Hi,

Thanks for your response!

I have .py script in library file. i.e. C:\Python27\Lib\Hello.py and file consist of print "Hello python!"

The same file we are executing from robot framewok for that created a .txt file as :

*** Settings ***
Library           Process

*** Variables ***
${stdout}

*** Test Cases ***
test2

Run Process python -c E:\Python_practice\Hello.py alias=myproc
${result} = Get Process Result myproc
Should Be Equal ${result.stdout} Hello python!

But test case is failing with 
test2
!= Hello python!

Here test result should match with the output result of E:\Python_practice\Hello.py and given "Should Be Equal ${result.stdout} Hello python!"

Please guide me if i am wrong.

Regards,
Sainath

On Tuesday, April 19, 2016 at 11:07:19 AM UTC+5:30, Tatu Aalto wrote:

Ugh

If you are going to only use that script from Robot Framework, then perhaps it would be best to format that script as a library [1]. If you are going to run the script also somewhere else than in the Robot Framework, you could use Process [2] library to run it. It is also combine the two options, by example using the hybrid or dynamic library[1] API.

There is many ways to what you want and which way to go depends on your needs.

-Tatu
[1] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries
[2] http://robotframework.org/robotframework/latest/libraries/Process.html

On 18 Apr 2016 13:35, "Ellendula Sainath" <ellendul...@gmail.com> wrote:
Hi,

Automated few scripts in python(.py) and i would like to execute the same test case in Robot framework.

for example:

i have .py script:

a,b = 20,20
if (a <> b):
    print "true"
else:
    print "false"

Can anyone please guide me the process to execute the above testcase in Robot framework.

Regards,
Sainath

--
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,
Apr 20, 2016, 1:34:46 AM4/20/16
to Ellendula Sainath, robotframework-users

Ugh

If you write it like this:
| ${result} = | Run Process | python | -c E:\Python_practice\Hello.py |


| Should Be Equal | ${result.stdout} | Hello python! |

does it then work?

-Tatu

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.

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

Ellendula Sainath

unread,
Apr 20, 2016, 3:29:43 AM4/20/16
to robotframework-users, ellendul...@gmail.com
Followed as suggested.

Getting error as in log file:

Starting test: Test1 A.Sample test case

20160420 12:48:28.603 :  INFO : 

Starting process:

['python', '-c', 'C:Python27LibHello.py']

20160420 12:48:28.634 :  INFO : Waiting for process to complete.

20160420 12:48:28.946 :  INFO : Process completed.

20160420 12:48:28.946 :  INFO : ${result} = <result object with rc 1>

20160420 12:48:28.962 :  INFO : 

Argument types are:

<type 'unicode'>

<type 'unicode'>

20160420 12:48:28.962 :  FAIL :  != Hello, world!

Ending test:   test1 A.Sample test case

As per my understanding, here E:\Python_practice\Hello.py is taking as an argument. So it won't execute script from given path and store results in ${result}

Please suggest any other alternative.

Regards,
Sainath
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 robotframe...@googlegroups.com.

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

Pekka Klärck

unread,
Apr 20, 2016, 7:14:55 AM4/20/16
to ellendul...@gmail.com, robotframework-users
2016-04-20 10:29 GMT+03:00 Ellendula Sainath <ellendul...@gmail.com>:
> Starting process:
> ['python', '-c', 'C:Python27LibHello.py']

You shouldn't be using `-c` option. Another problem is that `\` is an
escape character in Robot Framework test data so you should write the
path like `C:\\Python27\\Lib\\Hello.py`.

Notice also that placing normal Python scripts under the `Lib`
directory is not a good idea. `Lib\site-packages` is the right place
for installed third party modules, but normal scripts generally don't
belong under the Python installation directory.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Ellendula Sainath

unread,
Apr 22, 2016, 12:17:06 AM4/22/16
to robotframework-users, ellendul...@gmail.com
Hi Peke,

Thank you so much. The suggested method is working fine.

Regards,
Sainath

Tamali Basu

unread,
Jun 15, 2017, 5:27:32 AM6/15/17
to robotframework-users
Hi,
I have a python file random.py as below:
 import random


class RandomNum(object):
def random_number(self):
num = random.randrange(1, 100000, 1)
num = str(num)
print num
firstname = "Test" + num + ""
lastname = "Automation" + num + ""
email = "" + firstname + "." + lastname + "@xyz.com"

I want to use the firstname, lastname and email generated here, in one of my robot test case file. How can I achieve that?

Thanks!

Hélio Guilherme

unread,
Jun 15, 2017, 12:32:17 PM6/15/17
to robotframework-users
Hi Tamali,

Just to tell you that thread hijacking is not nice. Your question is different from the initial question.

You should ask in a new email, and I would ask you how would you use those firstname, lastname and email from a normal Python program. Then just use those variables from an imported variable file.


My Favorite Open Source Projects
awsome-lists gretl robotframework
(sponsored/patrocinado) Recomendo servidores e alojamento Web em:
http://www.proalojamento.pt/

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

Shiva Prasad Adirala

unread,
Apr 28, 2018, 9:58:23 AM4/28/18
to robotframework-users
Execution of python functions in robot test case: Link
Reply all
Reply to author
Forward
0 new messages