繁体   English   中英

从Python中调用Robot Framework文件

[英]Calling Robot Framework files from within Python

周末一直在约束。

我正在尝试创建一个Python应用程序,使用户能够运行.Robot文件(或测试用例)(从Python中)

我试图通过使用'subprocess'模块运行这些文件,但我不断收到以下错误消息:

'FileNotFoundError:[WinError 2]系统找不到指定的文件'

我已经包含'import subprocess'

我还将.Robot测试用例的位置声明为变量:

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

在我的代码中,我尝试使用以下语句调用Robotframework文件:

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

我目前正在使用Python 3.6.1和Robot Framework 3.0.2版

任何帮助,将不胜感激。 如果您知道完成相同任务的更好方法,请告诉我。

我的通用方法从带有stdout输出的python脚本运行外部命令:

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()

我仍然不知道当您尝试运行@Verv命令时会发生什么(可能在命令提示符下无法访问pybot),所以我建议尝试以下操作:

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)

检查可能表明错误的输出(在本地测试)。

假设您在Windows平台上,并且您要运行的机器人文件位于其他目录中

你可以使用子进程模块为你完成任务,如下所述

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')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM