
- 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 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 Grid - 測試執行
最新版本的 Selenium Grid 與舊版本的 Selenium Grid 有很多區別。舊版本的 Selenium Grid 只有 Hub 和 Node 兩種模式,而最新版本的 Selenium Grid 支援三種模式:獨立模式、Hub 和 Node 模式以及分散式模式。
以前的 Selenium Grid 版本僅包含 Hub 和 Node 兩種模式,而最新版本的 Selenium Grid 有六個元件,如路由器、分發器、節點、會話佇列、會話對映和事件匯流排。
Selenium Grid 是一種工具,可以將測試分佈到多個物理或虛擬機器上,以便我們可以並行(同時)執行指令碼。它極大地加快了測試過程,並在多個瀏覽器和平臺上執行測試,併為我們提供關於產品的快速準確的反饋。
Selenium Grid 允許我們執行多個 WebDriver 或 Selenium Remote Control 例項,允許並行執行使用相同程式碼庫的測試,因此程式碼不需要存在於它們執行的系統上。selenium-server-standalone 包含 Hub、WebDriver 和 Selenium RC,用於在網格中執行指令碼。
Selenium Grid 中測試執行的先決條件
步驟 1 - 在系統中安裝 Java(版本高於 8),並使用命令檢查它是否存在:java -version。如果安裝已成功完成,則將顯示已安裝的 Java 版本。
步驟 2 - 透過開啟瀏覽器並輸入以下內容來檢查網格狀態
對於 UI 版本,鍵入https://:4444。
對於非 UI 版本,鍵入https://:4444/status。
在這兩種情況下,我們都會收到錯誤 - 無法訪問此網站。因為 Selenium Grid 尚未啟動。

Selenium Grid 中的測試執行
在 Hub 和 Node 模式下在 Selenium Grid 中設定測試執行的步驟如下所示:
步驟 1 - 從以下連結下載 Selenium Standalone Jar 並將其儲存到資料夾中:https://github.com/SeleniumHQ/selenium/releases。
步驟 2 - 從儲存 Selenium Standalone Jar 的資料夾位置,從終端執行以下命令:
java -jar selenium-server-<version>.jar hub.
請注意 - 命令列日誌中顯示的 Hub IP 地址在註冊 Hub 時收到。
在下圖中,它顯示了 Hub 的成功觸發。

步驟 3 - 透過開啟瀏覽器並輸入以下內容來檢查網格狀態:https://:4444。
錯誤 - 無法訪問此網站將不再存在,並且我們將獲得顯示訊息的網格狀態 - 網格尚無註冊節點。這是因為節點尚未註冊。

在同一臺機器上執行節點
按照上述步驟 1、2 和 3 配置 Hub 後,導航到儲存 Selenium Standalone Jar 的資料夾位置,並透過開啟另一個新終端視窗執行以下命令:
java -jar selenium-server-<version>.jar node.
這將有助於在同一臺機器上啟動節點。
在不同的機器上執行節點
步驟 1 - 在另一臺機器上從以下連結下載 Selenium Standalone Jar 並將其儲存到資料夾中:https://github.com/SeleniumHQ/selenium/releases。
步驟 2 - 導航到儲存 Selenium Standalone Jar 的資料夾位置,並透過開啟終端視窗執行以下命令:
java -jar selenium-server-<version>.jar node --detect-drivers true --publish-events tcp://{hub IP Address}:4442 --subscribe-events tcp://{hub IP Address}:4443.
請注意 - Hub IP 地址將在步驟 3 中獲得的註冊 Hub 時收到的命令列日誌中提供。
這將有助於在不同的機器上啟動節點。
在下圖中,它顯示了從同一臺機器成功註冊節點。

步驟 3 - 透過開啟瀏覽器並輸入以下內容再次檢查網格狀態:https://:4444。
顯示的訊息 - 網格尚無註冊節點將不存在,取而代之的是,節點將反映出來。

步驟 4 -
Base.java中的程式碼實現
package BaseClass; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class Base { public WebDriver setBrowser(String browserName) throws MalformedURLException { WebDriver driver = null; DesiredCapabilities dc = new DesiredCapabilities(); if(browserName.equalsIgnoreCase("chrome")) { dc.setBrowserName("chrome"); } else if(browserName.equalsIgnoreCase("edge")) { dc.setBrowserName("MicrosoftEdge"); } // Initiate RemoteWebDriver driver = new RemoteWebDriver(new URL("https://:4444"),dc); return driver; } }
TestOne.java中的程式碼實現
package Grid; import BaseClass.Base; import org.openqa.selenium.WebDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.net.MalformedURLException; public class TestOne extends Base { public WebDriver driver = null; @Test public void testOne() { // launch application driver.get("https://tutorialspoint.tw/selenium/practice/links.php"); // get page title System.out.println("Page title is: " + driver.getTitle() + " obtained from testOne"); } @BeforeMethod public void setup() throws MalformedURLException { driver = setBrowser("chrome"); } @AfterMethod public void tearDown() { // quitting browser driver.quit(); } }
TestTwo.java中的程式碼實現
package Grid; import BaseClass.Base; import org.openqa.selenium.WebDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.net.MalformedURLException; public class TestTwo extends Base { public WebDriver driver = null; @Test public void testTwo() { // launch application driver.get("https://tutorialspoint.tw/selenium/practice/links.php"); // get page title System.out.println("Page title is: " + driver.getTitle() + " obtained from testTwo"); } @BeforeMethod public void setup() throws MalformedURLException { driver = setBrowser("edge"); } @AfterMethod public void tearDown() { // quitting browser driver.quit(); } }
testng.xml 檔案中的配置。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name = "Grid Test"> <test thread-count = "5" name="Test"> <classes> <class name="Grid.TestOne" /> <class name="Grid.TestTwo"/> </classes> </test> </suite>
步驟 5 - 從 testng.xml 檔案執行測試。
它將顯示以下輸出:
Page title is: Selenium Practice - Links obtained from testOne Page title is: Selenium Practice - Links obtained from testTwo =============================================== Grid Test Total tests run: 2, Passes: 2, Failures: 0, Skips: 0 =============================================== Process finished with exit code 0
在上面的示例中,我們使用 Selenium Grid 的 Hub 和 Node 模式執行了測試執行。
這總結了我們關於 Selenium Grid - 測試執行教程的全面內容。我們從描述在 Selenium Grid 中執行測試執行的先決條件開始,以及如何在 Selenium Grid 中實際執行測試執行。
這使您能夠深入瞭解 Selenium Grid - 測試執行。明智的做法是不斷練習您學到的知識,並探索與 Selenium 相關的其他知識,以加深您的理解並擴充套件您的視野。