- 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
IntelliJ 用於 Selenium
我們需要使用編輯器配置 Selenium 才能執行自動化測試。有多個可用的編輯器,例如:Eclipse、IntelliJ、Atom、Sublime 等。使用這些編輯器,我們可以開始使用 Java 專案來啟動測試自動化。
設定 IntelliJ for Selenium 的先決條件
使用以下連結下載並安裝 Java(版本高於 17),並使用以下命令驗證它是否可用:
java –version
https://www.oracle.com/java/technologies/downloads/.
有關 Java 配置的更多資訊,請參考以下連結:
https://www.youtube.com/watch?v=bxIZ1GVWYkQ.
使用以下連結下載並安裝 Maven,並使用以下命令驗證它是否可用:
mvn -version
https://maven.apache.org/download.cgi.
有關 Maven 配置的更多資訊,請參考連結 Maven 環境設定
為 Selenium 設定 IntelliJ
步驟 1 - 使用以下連結導航到 IntelliJ(Jetbrains 的產品)的官方網站,然後點選下載:
https://www.jetbrains.com/idea/.
步驟 2 - 導航到下一頁後,我們將獲得在各種作業系統(如 Windows、macOS 和 Linux)中下載 IntelliJ 的選項。根據當前作業系統點選相應的選項卡。
IntelliJ 有兩個版本,付費版和社群版(免費)。
步驟 3 - 我們將下載社群版。為此,我們將向下移動到 IntelliJ IDEA 社群版部分,然後點選下載。
步驟 4 - IntelliJ 的 logo 應該會顯示幾秒鐘,然後會出現 JETBRAINS COMMUNITY EDITION TERMS。選中複選框以接受條款和條件,然後點選繼續。
步驟 5 - 歡迎使用 IntelliJ IDEA 應該會顯示。點選新建專案按鈕。
步驟 6 - 在名稱:欄位下輸入名稱。將語言選擇為 Java,構建系統選擇為 Maven,並選擇 JDK 版本,然後點選建立。
步驟 7 - 輸入 ArtifactId,然後點選建立。
步驟 8 - IntelliJ 編輯器設定應該已成功完成。
步驟 9 - 從連結 Selenium Java 將 Selenium Maven 依賴項新增到 pom.xml 檔案中。
步驟 10 - 在中央選項卡下選擇並點選版本連結。我們導航到 Selenium Java >>
依賴項示例:
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.11.0</version> </dependency>
步驟 11 - 將步驟 9 中複製的依賴項貼上到 pom.xml 檔案中(位於 IntelliJ 工作區中建立的 Maven 專案下)。
步驟 12 - 在 Main.java 檔案中新增以下程式碼。
程式碼實現
package org.example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
System.out.println("Browser title: " + driver.getTitle());
}
}
新增到 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>
</dependencies>
</project>
步驟 13 - 右鍵點選並選擇執行“Main.main()”選項。等待執行完成。
步驟 14 - Chrome 瀏覽器啟動,我們在控制檯中獲得了輸出 - 瀏覽器標題:Google,以及訊息“程序已完成,退出程式碼為 0”,表示程式碼已成功執行。
此外,Chrome 瀏覽器啟動時顯示訊息Chrome 正在由自動化測試軟體控制。
結論
本教程全面介紹了 Intellij Selenium 教程,到此結束。我們首先介紹了設定 IntelliJ for Selenium 的先決條件,並逐步介紹瞭如何設定 IntelliJ 以及 Selenium。這使您能夠深入瞭解 Intellij Selenium。明智的做法是不斷練習您學到的知識,並探索與 Selenium 相關的其他知識,以加深您的理解並擴充套件您的視野。
