Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Robot Framework file from python script

from subprocess import call
import os

call(['robot '+os.getcwd()+'\\aaa.robot'])

file_dir: D:/aaa/test/aaa.robot

script for now in same dir

Output:
Traceback (most recent call last):
  File "__init.py", line 7, in <module>
    call(['robot '+os.getcwd()+'\\aaa.robot'])
  File "C:\Python27\lib\subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 710, in __init_
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 958, in _execut
    startupinfo)
WindowsError: [Error 2] Nie mo┐na odnalečŠ okreťlonego pliku

I just cant handle it. I dont get why in python tunning anything is so complicated :(

I want same result as this line (written directly to cmd):

/>robot aaa.robot
like image 606
user2678074 Avatar asked Dec 05 '22 01:12

user2678074


2 Answers

Here is another way

import robot

logFile = open('mylog.txt', 'w') 
robot.run("tmp.robot",stdout=logFile)
like image 148
Vinaykumar Patel Avatar answered Dec 22 '22 00:12

Vinaykumar Patel


subprocess expects a list but you're inputting a string ('robot '+os.getcwd()+'\\aaa.robot').

Try:

call(['C:/Python27/python.exe', '-m', 'robot', 'D:/aaa/test/aaa.robot'])

or

call(['C:/Python27/Scripts/robot.bat', 'D:/aaa/test/aaa.robot'])
like image 20
jDo Avatar answered Dec 22 '22 01:12

jDo