- 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 - 斷言/驗證方法
- 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 IDE - JSON 資料檔案
Selenium IDE 可用於處理 JSON 資料檔案。JavaScript 物件表示法或 JSON 是一種資料交換格式,並且具有輕量級的特性。它具有易於閱讀的模式,並且機器可以快速分析和生成 JSON 資料。
Selenium IDE 的“store json”命令
Selenium IDE 可使用 **store json** 命令來處理 JSON 資料檔案。它是一個訪問器命令,用於將 JSON 資料儲存到變數中。
在 Selenium IDE 中將 JSON 資料儲存到變數
讓我們舉一個例子,我們將使用 Selenium IDE 和訪問器命令 - store json 將 JSON 資料儲存到變數中。
在 Selenium IDE 中儲存 JSON 資料並訪問它們的步驟如下所示:
**步驟 1** - 單擊安裝後在瀏覽器上可見的 Selenium IDE 擴充套件。
**步驟 2** - Selenium IDE 應該會啟動,並顯示一條包含工具版本的歡迎訊息。在下圖中,安裝的版本為 3.17.2。
此外,它還提供了選擇我們希望使用該工具執行的操作的選項,例如在新的專案中錄製新的測試、開啟現有專案、建立新專案和關閉 Selenium IDE。
此外,還提供了一個帶有文字 - **Selenium IDE 專案頁面** 的連結,單擊該連結將跳轉到 Selenium 整合開發環境文件頁面。
https://selenium.programming.tw/selenium-ide/.
**步驟 3** - 單擊“建立新專案”連結,然後在 **請為您的新專案提供一個名稱** 下輸入專案名稱。最後,我們將單擊“確定”。
**步驟 4** - 我們將在 Selenium IDE 中準備好工作區。
**步驟 5** - 在“命令”欄位中輸入 open,並在“目標”欄位中輸入 https://tutorialspoint.tw/selenium/,以啟動應用程式。
**步驟 6** - 在“命令”欄位中輸入 store json,在“目標”欄位中輸入 {"Language":"Java","Name":"Selenium"},在“值”欄位中輸入 val。請注意,{"Language":"Java","Name":"Selenium"} 是我們希望使用變數 val 儲存的 json 資料。
**步驟 7** - 在“命令”欄位中輸入 echo,在“目標”欄位中輸入 ${val}。請注意,這將在 Selenium IDE 的日誌中列印我們在步驟 6 中訪問的 json 物件。
**步驟 8** - 在“命令”欄位中輸入 close 以關閉瀏覽器視窗。
**步驟 9** - 從頂部單擊“執行所有測試”,並等待測試執行完成。在我們的示例中,我們將看到執行:1,失敗:0,以及一個綠色條,表示測試已成功執行,沒有任何失敗。此外,訊息“測試已成功完成”出現在日誌下方。
在上面的示例中,我們在日誌中獲得了 json 資料。此外,我們在測試用例旁邊的頂部看到一個綠色勾號,表示測試已透過。
除此之外,所有測試步驟以及測試用例名稱都變為綠色,反映所有步驟都通過了。日誌選項卡下反映的所有步驟都在綠色中顯示“確定”。
因此,在 Selenium IDE 中,我們將獲得關於測試結果的資訊,包括測試步驟級別以及只有在所有步驟都成功執行後,我們才能在測試用例級別獲得“透過”。
此外,我們將推斷在一個步驟中使用的變數可以使用以下語法在其他步驟中進一步訪問:${<變數名稱>}。在步驟 2 中,我們在測試中使用了這種方法。echo 命令用於在日誌選項卡下獲取 JSON 物件。
測試執行完成後,專案將儲存在具有 .side 副檔名的檔案中。在這裡,我們將專案儲存為 Test13.side。在記事本、Notepad++ 或任何文字檔案格式中開啟此檔案,我們將以 JSON 格式獲取測試的資料和其他資訊。
從測試 .side 檔案接收的完整 JSON 資料:
{
"id": "9da88821-edda-4f81-9e7b-57b89080eadc",
"version": "2.0",
"name": "Test13",
"url": "",
"tests": [{
"id": "a87746b2-6478-47ce-b241-196675f0c91d",
"name": "Untitled",
"commands": [
{
"id": "86c94e67-93ba-44ba-89c5-170d1669f333",
"comment": "",
"command": "open",
"target": "https://tutorialspoint.tw/selenium/practice/register.php",
"targets": [],
"value": ""
}, {
"id": "62ed3587-a53b-4f10-ad98-90fc3223018a",
"comment": "",
"command": "storeJson",
"target": "{\"Language\":\"Java\", \"Name\":\"Selenium\"}",
"targets": [],
"value": "val"
}, {
"id": "d5676067-fb60-46fa-9b02-cd7a0b2ae630",
"comment": "",
"command": "echo",
"target": "${val}",
"targets": [],
"value": ""
}, {
"id": "3ce68f7d-2958-4e66-ad33-d9b9a4e5aa7f",
"comment": "",
"command": "close",
"target": "",
"targets": [],
"value": ""
}
]
}],
"suites": [{
"id": "7f58de7c-b22c-4fd1-bd59-00e4644995a6",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["a87746b2-6478-47ce-b241-196675f0c91d"]
}],
"urls": [],
"plugins": []
}
在上面的示例中,我們有四個測試步驟,命令為 open、store json、echo 和 close。所有這些命令及其目標和值都已捕獲在 JSON 檔案中。測試中傳遞的 JSON 資料 {"Language":"Java", "Name":"Selenium"} 也已捕獲在 json 檔案中。
這總結了我們關於 Selenium IDE - JSON 資料檔案的教程的全面介紹。我們從描述如何在 Selenium IDE 中使用 store json 命令訪問 json 資料開始,並逐步介紹了一個示例來說明如何使用 store json 命令以及具有 side 格式的檔案來儲存 Selenium IDE 測試,然後訪問相同的檔案以獲取 json 格式的測試資訊。
這使您深入瞭解 Selenium IDE 中的 JSON 資料檔案。明智的做法是繼續練習您學到的知識,並探索與 Selenium 相關的其他知識,以加深您的理解並拓寬您的視野。
