从 Python 中调用 Robot Framework 文件 [英] Calling Robot Framework files from within Python
问题描述
周末忙得不可开交.
我正在尝试创建一个 Python 应用程序,该应用程序将使用户能够运行 .Robot 文件(或测试用例)(从 Python 中)
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] 系统找不到文件指定'
'FileNotFoundError: [WinError 2] The system cannot find the file specified'
我已经包含了导入子流程"
I have included 'import subprocess'
我也将 .Robot 测试用例的位置声明为一个变量:
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'
在我的代码中,我尝试使用以下语句调用 Robotframework 文件:
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])
我目前使用的是 Python 3.6.1 和 Robot Framework 3.0.2 版
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.
推荐答案
让我们假设您在 windows 平台上,并且您要运行的机器人文件在其他目录中
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')
这篇关于从 Python 中调用 Robot Framework 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!