- Selenium 教程
- Selenium - 首頁
- Selenium - 概述
- Selenium - 元件
- Selenium - 自動化測試
- Selenium - 環境設定
- Selenium - 遠端控制
- Selenium IDE 教程
- Selenium - IDE 簡介
- Selenium - 功能
- Selenium - 限制
- Selenium - 安裝
- Selenium - 建立測試
- Selenium - 建立指令碼
- Selenium - 控制流
- Selenium - 儲存變數
- Selenium - 警報和彈出視窗
- Selenium - Selenese 命令
- Selenium - 操作命令
- Selenium - 獲取器命令
- Selenium - 斷言命令
- Selenium - Assert/Verify 方法
- Selenium - 定位策略
- Selenium - 指令碼除錯
- Selenium - 驗證點
- Selenium - 模式匹配
- Selenium - JSON 資料檔案
- Selenium - 瀏覽器執行
- Selenium - 使用者擴充套件
- Selenium - 程式碼匯出
- Selenium - 程式碼輸出
- Selenium - JavaScript 函式
- Selenium - 外掛
- Selenium WebDriver 教程
- Selenium - 簡介
- Selenium WebDriver vs 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 其他概念
- Selenium - IE 驅動程式
- Selenium - 自動化框架
- Selenium - 基於關鍵字的框架
- Selenium - 資料驅動框架
- Selenium - 混合驅動框架
- Selenium - SSL 證書錯誤
- Selenium - 替代方案
- Selenium 有用資源
- Selenium - 問答
- Selenium - 快速指南
- Selenium - 有用資源
- Selenium - 自動化實踐
- Selenium - 討論
Selenium IDE - 獲取器命令
Selenium IDE 包含三種命令,稱為操作、獲取器和斷言。獲取器命令用於檢查應用程式狀態,然後將結果儲存在變數中。
如何獲取獲取器命令?
我們可以在 Selenium IDE 中透過在命令欄位中輸入 store 來獲取獲取器命令。輸入後,所有與 store 相關的命令都可供選擇。
示例 1
讓我們以以下頁面為例,我們將在名字:標籤旁邊輸入文字Selenium,在姓氏:標籤旁邊輸入Tutorialspoint。此外,我們將使用 Selenium IDE 和獲取器命令獲取文字Selenium - Automation Practice Form。
以下是需要遵循的步驟:
步驟 1 - 重複連結Selenium IDE 儲存變數中描述的步驟 1 到 4。
步驟 2 - Selenium IDE 中的工作區現已準備就緒。
步驟 3 - 在命令欄位中輸入 open,在目標欄位中輸入Selenium 自動化實踐表單,以啟動應用程式。
步驟 4 - 在命令欄位中輸入 store,在目標欄位中輸入 Selenium,在值欄位中輸入 i。請注意,Selenium 是我們想使用變數 i 輸入的值。
步驟 5 - 在命令欄位中輸入 type,在目標欄位中輸入 id=firstname,在值欄位中輸入 ${i}。請注意,id=firstname 是輸入框的定位器值,${i} 用於引用我們想使用變數 i 輸入的變數值。
步驟 6 - 在命令欄位中輸入 store,在目標欄位中輸入 Tutorialspoint,在值欄位中輸入 j。請注意,Tutorialspoint 是我們想使用變數 j 輸入的值。
步驟 7 - 在命令欄位中輸入 type,在目標欄位中輸入 id=lastname,在值欄位中輸入 ${j}。請注意,id=lastname 是輸入框的定位器值,${j} 用於引用我們想使用變數 j 輸入的變數值。
步驟 8 - 在命令欄位中輸入 storeText,在目標欄位中輸入 css=div > h1,在值欄位中輸入 k。請注意,css=div > h1 是我們要獲取的文字的定位器值,k 用於引用我們將儲存獲取到的文字的變數值。
步驟 9 - 在命令欄位中輸入 echo,在目標欄位中輸入 ${k}。請注意,這將在 Selenium IDE 的日誌中列印我們在步驟 10 中訪問的網頁上的文字。
步驟 10 - 在命令欄位中輸入 storeValue,在目標欄位中輸入 id=firstname,在值欄位中輸入 l。請注意,id=firstname 是輸入框的定位器值,l 用於引用我們將用來獲取輸入框中輸入值的變數。
步驟 11 - 在命令欄位中輸入 echo,在目標欄位中輸入 ${l}。請注意,這將在 Selenium IDE 的日誌中列印我們在步驟 7 中輸入的值。
步驟 12 - 在命令欄位中輸入 close 以關閉瀏覽器視窗。
步驟 13 - 點選左側面板中出現的三個點,然後選擇“重新命名”選項。
步驟 14 - 在“重新命名測試用例”欄位下輸入名稱,例如 TestCase2,然後點選“重新命名”。輸入的名稱將出現在 Selenium IDE 的左側。
步驟 15 - 點選頂部的“執行所有測試”,然後等待測試執行完成。在我們的示例中,我們將看到執行:1,失敗:0,以及一個綠色條表示測試成功執行且沒有任何失敗。此外,“TestCase2 成功完成”訊息也會出現在日誌中。
在上面的示例中,我們獲得了出現在網頁上的文字Selenium - Automation Practice Form,還在日誌中檢索了在名字:標籤旁邊的輸入框中輸入的值 - Selenium。此外,我們在測試用例名稱 - TestCase2 的旁邊得到了一個綠色勾號,表示測試透過。
因此,在 Selenium IDE 中,我們將獲得測試結果的測試步驟級別資訊,並且只有在所有步驟都成功執行後,我們才能在測試用例級別獲得 PASS。
此外,我們可以推斷出在一個步驟中使用的變數可以使用語法:${<變數名>} 在其他步驟中訪問。在步驟 6、7、8、9、10、11、12 和 13 中,我們在測試中採用了這種方法。此外,我們使用了 store 和 store 相關的命令,如 storeText、storeValue 等來儲存變數。echo 命令用於在“日誌”選項卡下列印這些值。
示例 2
讓我們再以以下頁面為例,我們將使用獲取器命令捕獲頁面標題 Selenium Practice - Radio Button。
捕獲瀏覽器標題的步驟如下所示:
步驟 1 - 按照前一個示例中的步驟 1 到 4 操作。
步驟 2 - 在命令欄位中輸入 open,在目標欄位中輸入Selenium 自動化實踐表單,以啟動應用程式。
步驟 3 - 在命令欄位中輸入 storeTitle,在值欄位中輸入 pageTitle。請注意,pageTitle 是捕獲已啟動頁面的標題的變數。
步驟 4 - 在命令欄位中輸入 echo,在目標欄位中輸入 ${pageTitle}。請注意,這將在 Selenium IDE 的日誌中列印我們在步驟 3 中獲得的文字。
步驟 5 - 按照前一個示例中的步驟 14 到 17 操作。
在上例中,我們在日誌中獲得了頁面標題Selenium 實踐 - 單選按鈕。此外,我們在測試用例名稱 - Test6 旁邊看到一個綠色勾號,表示測試透過。
此外,我們可以推斷出,在一個步驟中使用的變數可以使用語法:${<變數名>} 在後續步驟中訪問。在步驟 2 和 3 中,我們在測試中使用了這種方法以及 store title 命令來獲取頁面。echo 命令用於在“日誌”選項卡下列印該值。
結論
本教程總結了關於 Selenium IDE 訪問器命令的全面內容。我們首先介紹瞭如何在 Selenium IDE 中訪問訪問器命令,並逐步講解了不同的訪問器命令,例如 store、store text、store title 等,並說明了如何將它們與 Selenium 一起使用。這使您深入瞭解 Selenium IDE 中的訪問器命令。建議您繼續練習所學內容,並探索與 Selenium 相關的其他內容,以加深理解並拓寬視野。
