1

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 attempting to run these files through the use of the 'subprocess' module, but I continually receive the following error message :

'FileNotFoundError: [WinError 2] The system cannot find the file specified'

I have included 'import subprocess'

I have also declared the location of the .Robot Test Case as a variable:

Location = r'C:/Users/verti/PycharmProjects/ChristSax.com/ChristSaxTestSuite/PageSmokeTest.Robot'

Within my code, I've attempted to call the Robotframework file with the following statement :

def AutomatedSmokePage():
    print("Automated Page Smoke Tests now running...")
    subprocess.call(['pybot',Location])

I am currently using Python 3.6.1 and Robot Framework version 3.0.2

Any help would be appreciated. If you know of a better means to accomplish the same task, please let me know.

5
  • 1
    I would start by calling Robot not by pybot but rather as "python -m robot.run" command, than try to concatenate robot call with Location as one string. Commented Nov 20, 2017 at 14:46
  • Thanks for the example, if it's not too much trouble, can you provide a brief example of how this can be done? Commented Nov 20, 2017 at 18:13
  • what happens if you just open a shell/cmd and enter pybot C:/Users/verti/PycharmProjects/ChristSax.com/ChristSaxTestSuite/PageSmokeTest.Robot Commented Nov 20, 2017 at 21:51
  • @Verv: When I type the location into Command Prompt and click 'Enter', the .Robot Test Case begins to run. If I copy the location into Command Prompt, spaces will be displayed within Suite & Robot (i.e. ChristSaxTestSu ite, PageSmokeTest.Ro bot) Commented Nov 23, 2017 at 3:51
  • I'm still a little confused as to why the same location variable works with certain commands and not others. I've found the following also works for me: os.chdir("C:/Users//verti/PycharmProjects/ChristSax.com/Chr‌​istSaxTestSuite/") os.system('pybot -N PageSmokeTest -r ' 'AutomatedSmokeTest.html -l AutomatedSmokeTest.html -o ' 'AutomatedSmokeTest.xml AutomatedSmokeTest.robot') Commented Nov 23, 2017 at 4:42

2 Answers 2

2

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

import sys
import subprocess

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

    while True:
        if sys.version_info >= (3, 0):
            nextline = str(p.stdout.readline(),"utf-8")
        else:
            nextline = p.stdout.readline()
        if nextline == '' and p.poll() is not None:
            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).

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately, when I use the above code, here is the error message I receive : The system cannot find the path specified.
try to limit "command" part to debug why system cannot find specified path - start with command=' c:/Python36/python.exe --version' , later on command=' c:/Python36/python.exe -m robot.libdoc --help'. There must be some small,silly issue which is hidden in plain sight.
1

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 
class Server:
    def __init__(self):
        pass
    def run_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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.