--- tags: English --- # Robot Framework搭配使用SideeX 預備環境 > * [Robot Framework](https://robotframework.org/)與[python](https://www.python.org/) > * [Selenium Server](https://selenium.dev/downloads/) > * [SideeX Runner](/@sideex/runner-zh)、SideeX Runner設定檔與錄製出的測試案例 ## 步驟1:建立一個SideeX函式庫 建立一個檔案`SideeXLibrary.py`並且填入以下程式碼。`./sideex-runner.js`的路徑可修改為正確位置。 ```python import subprocess from robot.api import logger class SideeXLibrary: def sideex_run_with(self,config): p = subprocess.Popen(['node', './sideex-runner.js' ,'-c', config],text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) while True: line = p.stdout.readline() if not line: break if line[:5]=="ERROR": if line=="ERROR Test case failed": raise Exception(line) else: logger.error(line) elif line[:4]=="INFO": logger.info(line) else: logger.debug(line) ``` ## 步驟2:透過此函式庫呼叫SideeX Runner 於Robot Framework測試案例程式碼中引入`./SideeXLibrary.py`與`./sideex-config.json`,並且新增此行`Sideex Run With ${CONFIG}`用以呼叫SideeX Runner。 ```robot *** Settings *** Documentation A test suite run with sideex. Library ./SideeXLibrary.py *** Variables *** ${CONFIG} ./sideex-config.json *** Test Cases *** Test Run Sideex Run With ${CONFIG} ``` ## 步驟3:執行Robot Framework測試案例 開啟命令列並執行`robot your_Robot_Framework_test_case`,執行過程中`sideex-config.json`檔中指定的SideeX測試案例將會被執行,SideeX測試案例結果亦將被包含於Robot Framework測試報告中。 ![](https://i.imgur.com/hOazElZ.png)