AutomationFrameworkSelenium
Test Automation Framework Selenium Java with TestNG building by Anh Tester
Install / Use
/learn @anhtester/AutomationFrameworkSeleniumREADME
Test Automation Framework using Selenium Java and TestNG building by Anh Tester
💥Important: when clone this repo, you should select 'Recursive' to get all submodules
🔆 SOME FEATURES IN FRAMEWORK
- Run the parallel test case
- Read Config from Properties file
- Extent Report
- Allure Report
- Send Mail after the run test (Report information and HTML file attachment)
- Write Log to file
- Record video and Screenshot test case
- Read data test from Excel file (xlsx, csv, json,...)
- Base function in the package: utils, helpers
- Read data test from Json file
- Main Keyword: WebUI (call common function)
- Sample test all function in WebUI keyword
- Send message/report to Telegram Bot
- Run Selenium Grid (remote)
- Use DataFaker and JavaFaker to generate data
- Retry Failed Test in TestNG with IRetryAnalyzer and IAnnotationTransformer
- Javadoc for this source
✳️ SYSTEM REQUIREMENTS
-
Install Java JDK (recommend JDK >= 17)
-
Install Chrome Browser, Edge Browser, Firefox Browser
-
Run well on the Windows platform
-
Setup Allure ENV: https://mvnrepository.com/artifact/io.qameta.allure/allure-java-commons or https://anhtester.com/blog/selenium-java/selenium-java-tai-nguyen-cai-dat-moi-truong) Download jar and setting Variable Environment as Java JDK

-
Use IntelliJ IDEA is the best choice (easy change the JDK version)

✳️ HOW TO USE
1. Run parallel the test case
-
Run test cases in suite XML (src/test/resources/suites/)
-
Run test cases from Maven with setup in the pom.xml file (mvn clean test)

2. Read Config from Properties file

3. Extent Report
- Insert "FrameworkAnnotation" as sample or None:

- The base value read from Enums (src/main/java/anhtester/com/enums)
- Setup on TestListener and BaseTest

- Pdf Report

4. Allure Report
- Open Terminal:
allure serve target/allure-results - or command:
allure generate --single-file target/allure-results --clean

- Insert @Step("title/message") above @Test or any Method in the project
- (As sample picture above step 3)


5. Send Mail after the run test
- Config true/false in config.properties (src/test/resources/config/config.properties)
- send_email_to_users=true is enable send mail
- Config mail with email and password in src/main/java/anhtester/com/mail/EmailConfig.java
- Note: if Gmail, you use App Password


6. Write Logs to file
- Call class: LogUtils.info(), LogUtils.pass(), LogUtils.error(),... (LogUtils is a custom global class from Log4j2) (import utils.com.anhtester.LogUtils.java)

7. Record video and Screenshot
-
Setup in config.properties file (src/test/resources/config/config.properties)
-
screenshot_passed_steps=yes or no
-
screenshot_failed_steps=yes or no
-
screenshot_skipped_steps=yes or no
-
screenshot_all_steps=yes or no

8. Read data test from Excel file
- Create function with annotation DataProvider on src/test/java/anhtester/com/projects/website/crm/dataprovider/DataProviderManager.java
- Read Excel file with Map and Hashtable
9. Base function in the package
- src/main/java/anhtester/com/utils
- src/main/java/anhtester/com/helpers
10. Read data test from JSON file
- JsonUtils class selects the JSON file path and calls "get" method with key
11. Main Keyword: WebUI
- WebUI class is the main keyword in Framework. It contains common functions
- How to use: WebUI.function_name
- Example: WebUI.setWindowSize(1024, 768), WebUI.screenshotElement(By by, String elementName),...
12. Call function to using sample
- All in one package: src/test/java/anhtester/com/projects/website/crm/testcases
+ ClientTest
+ SignInTest
+ TestHandle
+ TestSimpleCode
13. Send message/report to Telegram Bot
- Setup in src/main/java/anhtester/com/report/TelegramManager.java
- Example: src/test/java/anhtester/com/projects/website/crm/testcases/TestSimpleCode.java
- Call in TestListener at onFinish TelegramManager.sendReportPath()
===How to get Token and start Bot===
- Read blog: https://blog.devgenius.io/automation-of-reporting-2abe7f101801
- Copy Token of your Bot ⇒ Paste to TelegramManager class
- Click your Bot ⇒ input /start to start your Bot
===How to get ChatID===
- After starting your Bot, you use Postman tools and using your Token: Get: https://api.telegram.org/bot{token}/getUpdates ⇒ chat.id
- Example: https://api.telegram.org/bot19468772:AAHtlc_BH8zlJAGDHuTJy3J72XumY5LxWcE/getUpdates
"chat": {
"id": 123456789,
"first_name": "Anh Tester",
"username": "anhtester",
"type": "private"
}
14. Use Selenium Grid
Download and Install
- Download Selenium Grid 4: https://www.selenium.dev/downloads/
(tải bản Latest stable version)
selenium-server-4.22.0.jar (updated 24/06/2024)
- Set PATH for driver in Environment variables:
Follow with link: https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/#2-the-path-environment-variable
🔆 Đặt file selenium-server-4.22.0.jar vào thư mục nào đó và mở CMD tại thư mục đó lên
Run default 1 node
✅ Mở 1 Hub với 1 Node mặc định (port 4444)
java -jar selenium-server-4.22.0.jar standalone
Run multi Node
✅ Mở 1 Hub với 3 Node: (chạy 4 lệnh mở 4 CMD nhé)
java -jar selenium-server-4.22.0.jar hub
java -jar selenium-server-4.22.0.jar node --port 5556
java -jar selenium-server-4.22.0.jar node --port 6667
java -jar selenium-server-4.22.0.jar node --port 7778
📝 NOTE: Thực thi nhiều lệnh thì mở nhiều CMD
Edit Grid in Config.properties
TARGET=remote
REMOTE_URL=192.168.1.13 (url Grid của bạn)
REMOTE_PORT=4444 (port của Grid)



15. Use DataFaker and JavaFaker to generate data
Document DataFaker: https://www.datafaker.net/documentation/getting-started/ or of Anh Tester blog: https://anhtester.com/blog/selenium-java/tao-du-lieu-gia-voi-datafaker
🔆 Project structure
📦AutomationFrameworkSelenium
┣ 📂.github
┃ ┗ 📂workflows
┃ ┃ ┗ 📜maven.yml
┣ 📂src
┃ ┣ 📂main
┃ ┃ ┣ 📂java
┃ ┃ ┃ ┗ 📂anhtester
┃ ┃ ┃ ┃ ┗ 📂com
┃ ┃ ┃ ┃ ┃ ┣ 📂annotations
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜FrameworkAnnotation.java
┃ ┃ ┃ ┃ ┃ ┣ 📂config
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ConfigFactory.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜Configuration.java
┃ ┃ ┃ ┃ ┃ ┣ 📂constants
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜FrameworkConstants.java
┃ ┃ ┃ ┃ ┃ ┣ 📂driver
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜BrowserFactory.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜DriverManager.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TargetFactory.java
┃ ┃ ┃ ┃ ┃ ┣ 📂enums
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜AuthorType.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Browser.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜CategoryType.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜FailureHandling.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Platform.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Project.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜Target.java
┃ ┃ ┃ ┃ ┃ ┣ 📂exceptions
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜FrameworkException.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜HeadlessNotSupportedException.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜InvalidPathForExcelException.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜InvalidPathForExtentReportFileException.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜InvalidPathForFilesException.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜InvalidRemoteWebDriverURLException.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TargetNotValidException.java
┃ ┃ ┃ ┃ ┃ ┣ 📂helpers
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜CaptureHelpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜DatabaseHelpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ExcelHelpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜FileHelpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Helpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜PropertiesHelpers.java
┃ ┃ ┃ ┃ ┃ ┃
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
