- 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 與 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 - 使用Excel進行資料驅動
在設計測試時,引數化測試是不可避免的。我們將使用 Apache POI - Excel JAR 來實現這一點。它可以幫助我們讀取和寫入 Excel。
下載 JAR
步驟 1 - 導航到 URL - https://poi.apache.org/download.html 並下載 ZIP 格式。
步驟 2 - 單擊映象連結下載 JAR。
步驟 3 - 將內容解壓縮到資料夾中。
步驟 4 - 解壓縮後的內容將如下所示。
步驟 5 - 現在建立一個新專案,並在“poi-3.10.FINAL”資料夾下新增所有“外部 JAR”。
步驟 6 - 現在在“ooxml-lib”資料夾下新增所有“外部 JAR”。
步驟 7 - 現在在“lib”資料夾下新增所有“外部 JAR”。
步驟 8 - 新增的 JAR 如下所示。
步驟 9 - 包資源管理器如下所示。除此之外,還要新增與“WebDriver”相關的 JAR。
引數化
為了演示,我們將對百分比計算器測試進行引數化。
步驟 1 - 我們將使用 Excel 引數化百分比計算器所需的所有輸入。設計的 Excel 如下所示。
步驟 2 - 為所有指定的引數執行所有百分比計算器功能。
步驟 3 - 讓我們建立通用方法以使用匯入的 JAR 訪問 Excel 檔案。這些方法可以幫助我們獲取特定單元格資料或設定特定單元格資料等。
import java.io.*;
import org.apache.poi.xssf.usermodel.*;
public class ExcelUtils {
private XSSFSheet ExcelWSheet;
private XSSFWorkbook ExcelWBook;
//Constructor to connect to the Excel with sheetname and Path
public Excelutils(String Path, String SheetName) throws Exception {
try {
// Open the Excel file
FileInputStream ExcelFile = new FileInputStream(Path);
// Access the required test data sheet
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
} catch (Exception e) {
throw (e);
}
}
//This method is to set the rowcount of the excel.
public int excel_get_rows() throws Exception {
try {
return ExcelWSheet.getPhysicalNumberOfRows();
} catch (Exception e) {
throw (e);
}
}
//This method to get the data and get the value as strings.
public String getCellDataasstring(int RowNum, int ColNum) throws Exception {
try {
String CellData =
ExcelWSheet.getRow(RowNum).getCell(ColNum).getStringCellValue();
System.out.println("The value of CellData " + CellData);
return CellData;
} catch (Exception e) {
return "Errors in Getting Cell Data";
}
}
//This method to get the data and get the value as number.
public double getCellDataasnumber(int RowNum, int ColNum) throws Exception {
try {
double CellData =
ExcelWSheet.getRow(RowNum).getCell(ColNum).getNumericCellValue();
System.out.println("The value of CellData " + CellData);
return CellData;
} catch (Exception e) {
return 000.00;
}
}
}
步驟 4 - 現在新增一個主方法,該方法將訪問我們開發的 Excel 方法。
public class xldemo {
public static void main(String[] args) throws Exception {
ExcelUtils dd = new ExcelUtils ("C:\\Book1.xlsx","Sheet1");
System.out.println("The Row count is " + dd.excel_get_rows());
dd.getCellDataasnumber(1, 1);
dd.getCellDataasnumber(1, 2);
dd.getCellDataasnumber(1, 3);
dd.getCellDataasnumber(2, 1);
dd.getCellDataasnumber(2, 2);
dd.getCellDataasnumber(2, 3);
dd.getCellDataasnumber(3, 1);
dd.getCellDataasnumber(3, 2);
dd.getCellDataasnumber(3, 3);
}
}
輸出
執行指令碼後,輸出將如下所示顯示在控制檯中。
selenium_test_design_techniques.htm
廣告
