Skip to content Skip to sidebar Skip to footer

Calling Robot Framework Files From Within Python

Have been in a bind over the weekend. I am attempting to create a Python Application that will give users the ability to run .Robot files (or Test Cases) (from within Python) I am

Solution 1:

My generic method for running external command from python scripts with stdout output:

import sys
import subprocess

defrun_process(command):
    print("Running command: " + command)
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)

    whileTrue:
        if sys.version_info >= (3, 0):
            nextline = str(p.stdout.readline(),"utf-8")
        else:
            nextline = p.stdout.readline()
        if nextline == ''and p.poll() isnotNone:
            break
        sys.stdout.write(nextline)
        sys.stdout.flush()

I still don't know what happens when you try to run @Verv command (maybe pybot is not accessible in command prompt), so I would suggest try following:

python_path = 'c:/Python36/python.exe -m robot.run'
Location ='C:/Users/verti/PycharmProjects/ChristSax.com/ChristSaxTestSuite/PageSmokeTest.Robot'command=python_path+' '+Location
run_process(command)

Check the output which may indicate what is wrong (tested locally).

Solution 2:

lets assume that you are on windows platform and your robot file which you want t o run is in some other directory

you can use subprocess module to do the task for you like mentioned below

from subprocess import Popen 
from subprocess import Popen, CREATE_NEW_CONSOLE,PIPE,STDOUT
import platform 
classServer:
    def__init__(self):
        passdefrun_robotfiles(self,terminal,command1):
        if platform.system()=='Windows':
            self.terminal=terminal
            self.command1=command1
            self.command_server1=self.terminal+' '+self.command1
            self.server1_start=Popen(self.command_server1,creationflags=CREATE_NEW_CONSOLE)

abc=Server()
#you can give path till the robot file or you can use a batch file#K option tells cmd to run the command and keep the command window from closing. You may use /C instead to close the command window after the command finishes.
abc.run_robotfiles('cmd','/K pybot D:\Users\process.robot')

Post a Comment for "Calling Robot Framework Files From Within Python"