[英]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.