
- Selenium 教程
- Selenium - 首頁
- Selenium - 概述
- Selenium - 元件
- Selenium - 自動化測試
- Selenium - 環境設定
- Selenium - 遠端控制
- Selenium IDE 教程
- Selenium - IDE 簡介
- Selenium - 功能
- Selenium - 限制
- Selenium - 安裝
- Selenium - 建立測試
- Selenium - 建立指令碼
- Selenium - 控制流
- Selenium - 儲存變數
- Selenium - 警報和彈出視窗
- Selenium - Selenese 命令
- Selenium - Actions 命令
- Selenium - Accessors 命令
- Selenium - Assertions 命令
- Selenium - Assert/Verify 方法
- Selenium - 定位策略
- Selenium - 指令碼除錯
- Selenium - 驗證點
- Selenium - 模式匹配
- Selenium - JSON 資料檔案
- Selenium - 瀏覽器執行
- Selenium - 使用者擴充套件
- Selenium - 程式碼匯出
- Selenium - 程式碼輸出
- Selenium - JavaScript 函式
- Selenium - 外掛
- Selenium WebDriver 教程
- Selenium - 簡介
- Selenium WebDriver 與 RC 的區別
- Selenium - 安裝
- Selenium - 第一個測試指令碼
- Selenium - 驅動程式會話
- Selenium - 瀏覽器選項
- Selenium - Chrome 選項
- Selenium - Edge 選項
- Selenium - Firefox 選項
- Selenium - Safari 選項
- Selenium - 雙擊
- Selenium - 右鍵單擊
- Python 中的 HTML 報告
- 處理編輯框
- Selenium - 單個元素
- Selenium - 多個元素
- Selenium Web 元素
- Selenium - 檔案上傳
- Selenium - 定位器策略
- Selenium - 相對定位器
- Selenium - 查詢器
- Selenium - 查詢所有連結
- Selenium - 使用者互動
- Selenium - WebElement 命令
- Selenium - 瀏覽器互動
- Selenium - 瀏覽器命令
- Selenium - 瀏覽器導航
- Selenium - 警報和彈出視窗
- Selenium - 處理表單
- Selenium - 視窗和標籤頁
- Selenium - 處理連結
- Selenium - 輸入框
- Selenium - 單選按鈕
- Selenium - 複選框
- Selenium - 下拉框
- Selenium - 處理 IFrame
- Selenium - 處理 Cookie
- Selenium - 日期時間選擇器
- Selenium - 動態 Web 表格
- Selenium - Actions 類
- Selenium - Action 類
- Selenium - 鍵盤事件
- Selenium - 鍵上/下
- Selenium - 複製和貼上
- Selenium - 處理特殊鍵
- Selenium - 滑鼠事件
- Selenium - 拖放
- Selenium - 筆事件
- Selenium - 滾動操作
- Selenium - 等待策略
- Selenium - 顯式/隱式等待
- Selenium - 支援功能
- Selenium - 多選
- Selenium - 等待支援
- Selenium - 選擇支援
- Selenium - 顏色支援
- Selenium - ThreadGuard
- Selenium - 錯誤和日誌記錄
- Selenium - 異常處理
- Selenium - 其他
- Selenium - 處理 Ajax 呼叫
- Selenium - JSON 資料檔案
- Selenium - CSV 資料檔案
- Selenium - Excel 資料檔案
- Selenium - 跨瀏覽器測試
- Selenium - 多瀏覽器測試
- Selenium - 多視窗測試
- Selenium - JavaScript 執行器
- Selenium - 無頭執行
- Selenium - 捕獲螢幕截圖
- Selenium - 捕獲影片
- Selenium - 頁面物件模型
- Selenium - 頁面工廠
- Selenium - 記錄和回放
- Selenium - 框架
- Selenium - 瀏覽上下文
- Selenium - DevTools
- Selenium Grid 教程
- Selenium - 概述
- Selenium - 架構
- Selenium - 元件
- Selenium - 配置
- Selenium - 建立測試指令碼
- Selenium - 測試執行
- Selenium - 端點
- Selenium - 自定義節點
- Selenium 報告工具
- Selenium - 報告工具
- Selenium - TestNG
- Selenium - JUnit
- Selenium - Allure
- Selenium 與其他技術
- Selenium - Java 教程
- Selenium - Python 教程
- Selenium - C# 教程
- Selenium - Javascript 教程
- Selenium - Kotlin 教程
- Selenium - Ruby 教程
- Selenium - Maven 和 Jenkins
- Selenium - 資料庫測試
- Selenium - LogExpert 日誌記錄
- Selenium - Log4j 日誌記錄
- Selenium - Robot Framework
- Selenium - AutoIT
- Selenium - Flash 測試
- Selenium - Apache Ant
- Selenium - Github 教程
- Selenium - SoapUI
- Selenium - Cucumber
- Selenium - IntelliJ
- Selenium - XPath
Selenium 與 Robot Framework 教程
Selenium 可以與 Robot API 一起使用。Robot Framework 用於建立用於驗收測試驅動開發的自動化框架。這種驗收測試驅動開發方法基於關鍵字驅動測試。Selenium 廣泛用於 Web 自動化測試。Selenium 是一款開源且可移植的自動化軟體測試工具,用於測試 Web 應用程式。
什麼是 Robot Framework?
Robot Framework 包含大量使用 Java、Python 等開發的庫。除了 Robot Framework 中可用的現有關鍵字外,我們還可以使用現有關鍵字的語法在 Robot Framework 中新增新關鍵字以開發新的測試。使用 Robot Framework 只需要基本的程式設計知識。
設定 Robot Framework 的先決條件
步驟 1 - 從以下連結下載並安裝 Python:https://python.club.tw/downloads/。
要詳細瞭解如何設定 Python,請參閱以下連結:Python。
成功安裝 Python 後,我們可以透過執行命令:python –version(在命令提示符下)來確認其安裝。執行的命令輸出將指向機器中安裝的 Python 版本。
步驟 2 - 從以下連結安裝名為 PyCharm 的 Python 程式碼編輯器:https://www.jetbrains.com/pycharm/。
使用此編輯器,我們可以開始處理 Python 專案以啟動我們的測試自動化。要詳細瞭解如何設定 PyCharm,請參閱以下連結:PyCharm。
步驟 3 - 在命令提示符下執行命令:pip install selenium。這樣做是為了安裝 Selenium。要確認機器中安裝的 Selenium 版本,請執行以下命令:
pip show selenium
此命令的輸出將給出以下結果:
Name: selenium Version: 4.19.0 Summary: None Home-page: https://www.selenium.dev Author: None Author-email: None License: Apache 2.0.
步驟 4 - 在命令提示符下執行命令:pip install robotframework。這樣做是為了安裝 Robot Framework。要確認機器中安裝的 Robot Framework 版本,請執行以下命令:
pip show robotframework
此命令的輸出給出了以下結果:
Name: robotframework Version: 7.0 Summary: Generic automation framework for acceptance testing and robotic process automation (RPA) Home-page: https://robotframework.org Author: Pekka Klärck Author-email: peke@eliga.fi License: Apache License 2.0 Location: /Users/opt/anaconda3/lib/python3.8/site-packages Requires: Required-by:
步驟 5 - 在命令提示符下執行命令:pip install requests。這樣做是為了安裝請求庫,這將有助於自動化 Rest API。
步驟 6 - 在命令提示符下執行命令:pip install robotframework-requests。這樣做是為了安裝 Robot Framework 請求庫,這將有助於自動化 Rest API。
步驟 7 - 在命令提示符下執行命令:pip install -U robotframework-jsonlibrary。這樣做是為了驗證 JSON 響應。
步驟 8 - 完成步驟 8 後,重新啟動 PyCharm。
步驟 9 - 開啟 PyCharm 並透過導航到“檔案”選單建立一個新專案。

在“位置”欄位中輸入專案名稱和位置,然後單擊“建立”按鈕。

步驟 10 - 從 PyCharm 編輯器的右下角,選擇“直譯器設定”選項。

從左側選擇“Python 直譯器”選項,然後單擊“+”。

步驟 11 - 在“可用包”彈出視窗內的包搜尋框中輸入 selenium,然後搜尋結果將與右側的“描述”一起顯示。“描述”包含有關將安裝的 Selenium 包版本的資訊。
在“指定版本”欄位旁邊還有一個安裝特定版本 Selenium 包的選項。然後單擊“安裝包”按鈕。安裝成功後,應顯示訊息“包‘selenium’安裝成功”。

步驟 12 - 在“可用包”彈出視窗內的包搜尋框中輸入 robotframework,並以相同的方式安裝它。
步驟 13 - 在“可用包”彈出視窗內的包搜尋框中輸入 requests,並以相同的方式安裝它。
步驟 14 - 在“可用包”彈出視窗內的包搜尋框中輸入 robotframework-jsonlibrary,並以相同的方式安裝它。
步驟 15 - 在“可用包”彈出視窗內的包搜尋框中輸入 robotframework-seleniumlibrary,並以相同的方式安裝它。
退出“可用包”彈出視窗。
步驟 16 - 步驟 11、12、13、14 和 15 中安裝的所有包都應反映在“包”下。單擊“確定”按鈕。重新啟動 PyCharm。

步驟 17 - 透過右鍵單擊專案資料夾建立第一個測試用例。在這裡,我們已將專案名稱命名為 SeleniumPython。然後右鍵單擊新建立的專案,單擊“新建”選項,最後選擇“目錄”。

步驟 18 - 輸入目錄名稱(例如 Robot),然後單擊 Enter。專案 Robot 應顯示在左側的 SeleniumPython 專案資料夾下。

步驟 19 - 導航到 PyCharm 設定,然後單擊“外掛”選項卡。

步驟 20 - 在搜尋框中輸入 IntelliBotSelenium,然後單擊“安裝”按鈕。安裝此外掛後,重新啟動 PyCharm。這樣做是為了使 PyCharm 編輯器能夠識別所有副檔名為 .robot 的與機器人相關的測試用例。

步驟 21 - 右鍵單擊目錄 Robot,然後建立一個檔案(例如 GetRequest.robot)。

步驟 22 - 新增以下程式碼以觸發 Get 請求
*** Settings *** Library RequestsLibrary *** Variables *** ${baseUrl} https://api.restful-api.dev/objects ${object} 7 *** Test Cases *** Get_Object create session firstSession ${baseUrl} ${response} = get request firstSession ${object} log to console ${response.status_code} log to console ${response.content} log to console ${response.header}
至此,我們對 Selenium - Robot API 教程的全面介紹就結束了。我們從描述什麼是 Robot Framework 以及如何使用 Python 和 Selenium 設定 Robot Framework 開始。
這使您掌握了 Selenium - Robot API 的深入知識。明智的做法是不斷練習您學到的知識,並探索與 Selenium 相關的其他內容,以加深您的理解並擴充套件您的視野。