AutomationFrameworkSelenium
AutomationFrameworkSelenium copied to clipboard
Test Automation Framework Selenium Java with TestNG building by Anh Tester
Automation Framework Selenium Java with TestNG building by Anh Tester
SOME FEATURES IN FRAMEWORK
- Run the parallel test case
- Read Object web element 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 for failed
- Read data test from Excel file (xlsx, csv, json,...) with class define fields (param: Client client)
- 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
SYSTEM REQUIREMENTS
-
JDK All Version
-
Chrome Browser, Edge Browser, Firefox Browser
-
Setup Allure: 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

-
IntelliJ is the best choice (to change JDK version)

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

2. Read Object web element 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

4. Allure Report
- Open Terminal: allure serve target/allure-results

- 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: enabled Allow less secure apps


6. Write Log to file
- Call class: Log.info , Log.pass, Log.error,... (Log is a custom global class from Log4j2) (import anhtester.com.utils.Log.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 annotaion DataProvider on ** src/test/java/anhtester/com/projects/website/crm/dataprovider/DataProviderManager.java**
- Read excel 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 select the json file path and call "get" method with key
11. Main Keyword: WebUI
- WebUI class is 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, your use Postman 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"
}
Project structure
📦AutomationFrameworkSelenium
┣ 📂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
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Helpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜PropertiesHelpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ScreenRecoderHelpers.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TxtFileHelpers.java
┃ ┃ ┃ ┃ ┃ ┣ 📂mail
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜EmailAttachmentsSender.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜EmailConfig.java
┃ ┃ ┃ ┃ ┃ ┣ 📂report
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜AllureManager.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ExtentReportManager.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ExtentTestManager.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TelegramManager.java
┃ ┃ ┃ ┃ ┃ ┗ 📂utils
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜BrowserInfoUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜DataGenerateUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜DateUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜DecodeUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜EmailSendUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜IconUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜JsonUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜LanguageUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜LocalStorageUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Log.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ObjectUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ReportUtils.java
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜WebUI.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ZipUtils.java
┃ ┃ ┗ 📂resources
┃ ┃ ┃ ┣ 📜drag_and_drop_helper.js
┃ ┃ ┃ ┣ 📜jquery_load_helper.js
┃ ┃ ┃ ┗ 📜log4j2.properties
┃ ┗ 📂test
┃ ┃ ┣ 📂java
┃ ┃ ┃ ┗ 📂anhtester
┃ ┃ ┃ ┃ ┗ 📂com
┃ ┃ ┃ ┃ ┃ ┣ 📂common
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜BaseTest.java
┃ ┃ ┃ ┃ ┃ ┣ 📂dataprovider
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DataProviderManager.java
┃ ┃ ┃ ┃ ┃ ┣ 📂listeners
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TestListener.java
┃ ┃ ┃ ┃ ┃ ┗ 📂projects
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂website
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂crm
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂models
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ClientModel.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜SignInModel.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂pages
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂Clients
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ClientPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂Dashboard
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DashboardPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂Projects
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ProjectPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂SignIn
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜SignInPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂Tasks
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TaskPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜CommonPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂testcases
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ClientTest.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜SignInTest.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜TestHandle.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TestSimpleCode.java
┃ ┃ ┗ 📂resources
┃ ┃ ┃ ┣ 📂config
┃ ┃ ┃ ┃ ┣ 📜config.json
┃ ┃ ┃ ┃ ┣ 📜config.properties
┃ ┃ ┃ ┃ ┗ 📜datatest.properties
┃ ┃ ┃ ┣ 📂objects
┃ ┃ ┃ ┃ ┗ 📜crm_locators.properties
┃ ┃ ┃ ┣ 📂suites
┃ ┃ ┃ ┃ ┣ 📜Clients-parallel.xml
┃ ┃ ┃ ┃ ┣ 📜Clients-simple.xml
┃ ┃ ┃ ┃ ┣ 📜Clients-testAddClient.xml
┃ ┃ ┃ ┃ ┣ 📜Clients-testSearch.xml
┃ ┃ ┃ ┃ ┣ 📜SignIn-parallel-methods.xml
┃ ┃ ┃ ┃ ┣ 📜SignIn-simple.xml
┃ ┃ ┃ ┃ ┗ 📜SuiteAll.xml
┃ ┃ ┃ ┗ 📂testdata
┃ ┃ ┃ ┃ ┣ 📜ClientsDataExcel.xlsx
┃ ┃ ┃ ┃ ┣ 📜DOCX_File_01.docx
┃ ┃ ┃ ┃ ┣ 📜LoginCSV.csv
┃ ┃ ┃ ┃ ┗ 📜TxtFileData.txt
┣ 📜pom.xml
┗ 📜README.md
I shall write document for my Framework. Coming soon...
Copyright 2022 Anh Tester
Anh Tester Blog: https://anhtester.com/
