
- 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 - Allure
Allure 可用於建立詳細的自動化測試報告。它是一個開源框架,可以與 Selenium 測試整合並用於報告目的。
建立 Allure 報告的先決條件
在系統中安裝 Java(版本高於 8)並使用命令檢查它是否存在:java -version。如果安裝成功完成,則將顯示已安裝的 Java 版本。可以使用連結 Java 下載 下載和安裝 Java。
要了解更多關於 Java 設定的知識,請參閱以下連結 -
https://www.youtube.com/watch?v=bxIZ1GVWYkQ.
在系統中安裝 Maven 並使用命令檢查它是否存在:mvn -version。如果安裝成功完成,則將顯示已安裝的 Maven 版本。可以使用連結 Apache Maven 下載和安裝 Maven。
要了解更多關於 Maven 設定的知識,請參閱連結 Maven 環境搭建。
安裝 IntelliJ。要了解更多關於 IntelliJ 設定的知識,請參閱連結 Selenium IntelliJ。
建立 Allure 報告的步驟
步驟 1 - 建立一個 Maven 專案,並將以下專案的依賴項新增到 pom.xml 檔案中 -
從連結 TestNG 新增 TestNG 依賴項。
從連結 Selenium Java 新增 Selenium Java 依賴項
從連結 Allure TestNG 新增 Allure TestNG 依賴項
儲存包含所有依賴項的 pom.xml 並更新 Maven 專案。
步驟 2 - 在系統中下載 Allure。對於 Mac 和 Linux,執行命令:brew install allure。如果系統中安裝了 Homebrew,則此命令應該可以工作。對於 Windows,執行命令:scoop install allure。如果系統中安裝了 Scoop,則此命令應該可以工作。使用命令檢查 Allure 是否存在:allure –version。如果安裝成功完成,則將顯示已安裝的 Allure 版本。
步驟 3 - 建立一個 TestNG 測試類,並注意以下示例。在歡迎頁面上點選新建使用者按鈕。

點選新建使用者後,我們將進入註冊頁面,頁面上顯示歡迎,註冊文字,如下面的圖片所示。

程式碼實現
package Report; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.*; import java.util.concurrent.TimeUnit; import static org.testng.Assert.assertEquals; public class AllureTest { WebDriver driver; @BeforeTest public void setup(@Optional String browser) throws Exception{ // Initiate browser driver driver = new ChromeDriver(); // adding implicit wait of 12 secs driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Opening the webpage driver.get("https://tutorialspoint.tw/selenium/practice/login.php"); } @Test(priority = 1) public void verifyWelcomePageHeading() { // identify header then get text WebElement header = driver.findElement (By.xpath("//*[@id='signInForm']/h1")); String text = header.getText(); // assertion to verify login page header assertEquals("Welcome, Login In", text); } @Test(priority = 2) public void moveToRegisterPage() { // identify button then click WebElement btn = driver.findElement (By.xpath("//*[@id='signInForm']/div[3]/a")); btn.click(); } @Test(priority = 3) public void verifyRegisterPageHeading() { // identify header then get text WebElement heder = driver.findElement (By.xpath("//*[@id='signupForm']/h1")); String text = heder.getText(); // assertion to verify register page header assertEquals("Welcome,Register", text); } @AfterTest 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="All Test Suite"> <test verbose="2" preserve-order="true" name="AllureTest.java"> <classes> <class name="Report.AllureTest"> <methods> <include name="verifyWelcomePageHeading"/> <include name="moveToRegisterPage"/> <include name="verifyRegisterPageHeading"/> </methods> </class> </classes> </test> </suite>
pom.xml 檔案中的依賴項。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>SeleniumJava</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>16</maven.compiler.source> <maven.compiler.target>16</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.11.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.9.0</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng --> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-testng</artifactId> <version>2.25.0</version> </dependency> </dependencies> </project>
以上實現的專案結構如下圖所示 -

步驟 4 - 使用 testng.xml 執行測試。
它將顯示以下輸出 -
=============================================== All Test Suite Total tests run: 3, Passes: 3, Failures: 0, Skips: 0 =============================================== Process finished with exit code 0
我們使用了 TestNG 框架來設計測試並獲取頁面標題,最後對其進行驗證。
控制檯中的結果顯示總共執行的測試:3,因為有三個帶有 @Test 註解的方法 - verifyWelcomePageHeading()、moveToRegisterPage() 和 verifyRegisterPageHeading()。
最後,收到訊息透過:3和程序已完成,退出程式碼為 0,表示程式碼執行成功。
步驟 5 - 重新整理專案資料夾,一個名為allure-results的新資料夾應該會生成。

步驟 6 - 從專案資料夾位置執行命令:allure serve。這裡,專案資料夾名稱為 Selenium Java。執行命令後,伺服器啟動,同時 Allure 報告將在瀏覽器中開啟,總測試方法(或用例)數為 3,透過率為 100%。

點選左側的套件選項卡,我們將獲得有關測試方法 moveToRegisterPage()、verifyPageHeading() 和 verifyWelcomePageHeading() 的執行持續時間及其結果的資訊。

切換到左側的圖表選項卡,我們將獲得有關狀態、嚴重性、持續時間等的所有資訊。

結論
這總結了我們對 Selenium Allure 教程的全面介紹。我們從描述 Allure 報告、設定 Allure 報告的先決條件開始,並逐步演示瞭如何使用示例建立 Allure 報告,說明了如何將其與 Selenium 一起使用。這使您能夠深入瞭解 Allure。明智的做法是不斷練習您所學到的知識,並探索與 Selenium 相關的其他內容,以加深您的理解並擴充套件您的視野。