Skip to content

Commit ab9505a

Browse files
committed
Update version 1.9.0 released
1 parent e1ccbd9 commit ab9505a

File tree

8 files changed

+112
-43
lines changed

8 files changed

+112
-43
lines changed

README.md

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Automation Framework Selenium Java with TestNG building by Anh Tester
66

7-
**SOME FEATURES IN FRAMEWORK**
7+
🔆 **SOME FEATURES IN FRAMEWORK**
88

99
1. Run the parallel test case
1010
2. Read Config from Properties file
@@ -19,24 +19,26 @@
1919
11. Main Keyword: WebUI (call common function)
2020
12. Sample test all function in WebUI keyword
2121
13. Send message/report to Telegram Bot
22+
14. Run Selenium Grid (remote)
2223

23-
### **SYSTEM REQUIREMENTS**
24+
### ✳️ **SYSTEM REQUIREMENTS**
2425

25-
- **JDK All Version**
26+
- **JDK All Version** (recommend JDK >=11)
2627
- Chrome Browser, Edge Browser, Firefox Browser
27-
- Setup **Allure**:
28+
- Run well on the **Windows** platform
29+
- Setup **Allure ENV**:
2830
https://mvnrepository.com/artifact/io.qameta.allure/allure-java-commons
2931
or
3032
https://anhtester.com/blog/selenium-java/selenium-java-tai-nguyen-cai-dat-moi-truong)
3133
Download jar and setting Variable Environment as Java JDK
3234

3335
![image](https://user-images.githubusercontent.com/87883620/161661705-b8706957-5a26-4faf-8ddf-2f9aef78418e.png)
3436

35-
- **IntelliJ IDEA** is the best choice (to change JDK version)
37+
- **IntelliJ IDEA** is the best choice (easy change the JDK version)
3638

3739
![image](https://user-images.githubusercontent.com/87883620/161707184-7ad558f2-0d7d-4851-bfd6-2796d4e46593.png)
3840

39-
### **HOW TO USE**
41+
### ✳️ **HOW TO USE**
4042

4143
**1. Run parallel the test case**
4244

@@ -61,13 +63,12 @@
6163

6264
![image](https://user-images.githubusercontent.com/87883620/161657754-c29b1ee9-f2fb-44b3-bee0-9f425a7cab6f.png)
6365

64-
- Pdf Report
66+
- **Pdf Report**
6567

6668
![image](https://user-images.githubusercontent.com/87883620/194396654-5b01cb68-161a-4caf-824d-b57cd6091586.png)
6769
![image](https://user-images.githubusercontent.com/87883620/194396689-ac5381cc-8689-4ce0-8c7f-d2487047faec.png)
6870
![image](https://user-images.githubusercontent.com/87883620/194396707-ed1308a0-e4bf-4cac-b5b6-0fde44c81091.png)
6971

70-
7172
**4. Allure Report**
7273

7374
- Open Terminal: **_allure serve target/allure-results_**
@@ -113,8 +114,7 @@
113114

114115
**8. Read data test from Excel file**
115116

116-
- Create function with annotaion **DataProvider** on **
117-
src/test/java/anhtester/com/projects/website/crm/dataprovider/DataProviderManager.java**
117+
- Create function with annotaion **DataProvider** on **src/test/java/anhtester/com/projects/website/crm/dataprovider/DataProviderManager.java**
118118
- Read excel with Map and Hashtable
119119

120120
**9. Base function in the package**
@@ -147,7 +147,7 @@
147147

148148
- Setup in src/main/java/anhtester/com/report/TelegramManager.java
149149
- Example: src/test/java/anhtester/com/projects/website/crm/testcases/TestSimpleCode.java
150-
- Call in TestListener at onFinish TelegramManager.sendReportPath();
150+
- Call in TestListener at onFinish TelegramManager.sendReportPath()
151151

152152
======How to get Token and start Bot=======
153153

@@ -170,6 +170,50 @@
170170
}
171171
```
172172

173+
**14. Use Selenium Grid**
174+
175+
### ---------------- Download and Install --------------
176+
177+
1. Download Selenium Grid 4: https://www.selenium.dev/downloads/
178+
179+
(tải bản Latest stable version)
180+
181+
**selenium-server-4.6.0.jar** (updated 04/11/2022)
182+
183+
2. Thiết đặt PATH cho driver của từng Browser:
184+
185+
Xem link làm
186+
theo: https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/#2-the-path-environment-variable
187+
188+
🔆 Đặt file **selenium-server-4.6.0.jar** vào thư mục nào đó và mở CMD tại thư mục đó lên
189+
190+
### ---------------------- Run default -------------------
191+
192+
✅ Mở 1 hub với 1 node mặc định (port 4444)
193+
194+
> java -jar selenium-server-4.6.0.jar standalone
195+
196+
### -------------------- Run multi Node ----------------
197+
198+
✅ Mở 1 hub với 3 node: (chạy 4 lệnh mở 4 CMD nhé)
199+
200+
> java -jar selenium-server-4.6.0.jar hub
201+
202+
> java -jar selenium-server-4.6.0.jar node --port 5556
203+
204+
> java -jar selenium-server-4.6.0.jar node --port 6667
205+
206+
> java -jar selenium-server-4.6.0.jar node --port 7778
207+
208+
209+
**NOTE: Thực thi nhiều lệnh thì mở nhiều CMD**
210+
211+
### ----------- Edit Grid in Config.properties -----------
212+
213+
> REMOTE_URL=192.168.1.13 (url Grid của bạn)
214+
215+
> REMOTE_PORT=4444 (port của Grid)
216+
173217
### Project structure
174218

175219
```

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
<java-compiler.version>11</java-compiler.version>
1717
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
1818
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
19-
<selenium.version>4.5.0</selenium.version>
20-
<testng.version>7.6.1</testng.version>
19+
<selenium.version>4.6.0</selenium.version>
20+
<testng.version>7.4.0</testng.version>
2121
<webdrivermanager.version>5.3.0</webdrivermanager.version>
2222
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>
2323
<ashot.version>1.5.4</ashot.version>
2424
<log4j.version>2.19.0</log4j.version>
25+
<slf4j.version>2.0.3</slf4j.version>
2526
<allure-testng.version>2.19.0</allure-testng.version>
2627
<allure-maven.version>2.10.0</allure-maven.version>
2728
<allure-environment-writer.version>1.0.0</allure-environment-writer.version>

src/main/java/anhtester/com/driver/BrowserFactory.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import anhtester.com.constants.FrameworkConstants;
99
import anhtester.com.exceptions.HeadlessNotSupportedException;
10-
import io.github.bonigarcia.wdm.WebDriverManager;
11-
import io.github.bonigarcia.wdm.config.DriverManagerType;
1210
import org.openqa.selenium.MutableCapabilities;
1311
import org.openqa.selenium.WebDriver;
1412
import org.openqa.selenium.chrome.ChromeDriver;
@@ -27,7 +25,7 @@ public enum BrowserFactory {
2725
CHROME {
2826
@Override
2927
public WebDriver createDriver() {
30-
WebDriverManager.getInstance(DriverManagerType.CHROME).setup();
28+
//WebDriverManager.getInstance(DriverManagerType.CHROME).setup();
3129

3230
return new ChromeDriver(getOptions());
3331
}
@@ -44,8 +42,8 @@ public ChromeOptions getOptions() {
4442
}, FIREFOX {
4543
@Override
4644
public WebDriver createDriver() {
47-
WebDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
48-
45+
//WebDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
46+
4947
return new FirefoxDriver(getOptions());
5048
}
5149

@@ -59,7 +57,7 @@ public FirefoxOptions getOptions() {
5957
}, EDGE {
6058
@Override
6159
public WebDriver createDriver() {
62-
WebDriverManager.getInstance(DriverManagerType.EDGE).setup();
60+
//WebDriverManager.getInstance(DriverManagerType.EDGE).setup();
6361

6462
return new EdgeDriver(getOptions());
6563
}
@@ -74,7 +72,7 @@ public EdgeOptions getOptions() {
7472
}, SAFARI {
7573
@Override
7674
public WebDriver createDriver() {
77-
WebDriverManager.getInstance(DriverManagerType.SAFARI).setup();
75+
//WebDriverManager.getInstance(DriverManagerType.SAFARI).setup();
7876

7977
return new SafariDriver(getOptions());
8078
}

src/main/java/anhtester/com/keyword/WebUI.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,10 @@ public static ChromeOptions notificationsBlock() {
478478
* @param by là element thuộc kiểu By
479479
* @param filePath đường dẫn tuyệt đối đến file trên máy tính của bạn
480480
*/
481-
public static void uploadFileForm(By by, String filePath) {
482-
if (ACTIVE_PAGE_LOADED.trim().toLowerCase().equals("true")) {
483-
waitForPageLoaded();
484-
}
485-
sleep(WAIT_SLEEP_STEP);
481+
@Step("Upload File With Local Form")
482+
public static void uploadFileWithLocalForm(By by, String filePath) {
483+
smartWait();
484+
486485
Actions action = new Actions(DriverManager.getDriver());
487486
//Click để mở form upload
488487
action.moveToElement(getWebElement(by)).click().perform();
@@ -543,6 +542,13 @@ public static void uploadFileForm(By by, String filePath) {
543542
robot.keyPress(KeyEvent.VK_ENTER);
544543
robot.keyRelease(KeyEvent.VK_ENTER);
545544
}
545+
546+
Log.info("Upload File With Local Form: " + filePath);
547+
if (ExtentTestManager.getExtentTest() != null) {
548+
ExtentReportManager.info("Upload File With Local Form: " + filePath);
549+
}
550+
AllureManager.saveTextLog("Upload File With Local Form: " + filePath);
551+
546552
}
547553

548554
/**
@@ -551,21 +557,40 @@ public static void uploadFileForm(By by, String filePath) {
551557
* @param by truyền vào element dạng đối tượng By
552558
* @param filePath đường dẫn tuyệt đối đến file
553559
*/
554-
public static void uploadFileSendkeys(By by, String filePath) {
560+
@Step("Upload File with SendKeys")
561+
public static void uploadFileWithSendKeys(By by, String filePath) {
555562
smartWait();
556-
waitForElementPresent(by).sendKeys(filePath);
563+
564+
waitForElementVisible(by).sendKeys(filePath);
565+
566+
Log.info("Upload File with SendKeys");
567+
if (ExtentTestManager.getExtentTest() != null) {
568+
ExtentReportManager.info("Upload File with SendKeys");
569+
}
570+
AllureManager.saveTextLog("Upload File with SendKeys");
571+
557572
}
558573

574+
@Step("Get Current URL")
559575
public static String getCurrentUrl() {
560576
smartWait();
561577
Log.info("Current Page Url: " + DriverManager.getDriver().getCurrentUrl());
578+
if (ExtentTestManager.getExtentTest() != null) {
579+
ExtentReportManager.info("Current Page Url: " + DriverManager.getDriver().getCurrentUrl());
580+
}
581+
AllureManager.saveTextLog("Current Page Url: " + DriverManager.getDriver().getCurrentUrl());
562582
return DriverManager.getDriver().getCurrentUrl();
563583
}
564584

585+
@Step("Get Page Title")
565586
public static String getPageTitle() {
566587
smartWait();
567588
String title = DriverManager.getDriver().getTitle();
568589
Log.info("Current Page Title: " + DriverManager.getDriver().getTitle());
590+
if (ExtentTestManager.getExtentTest() != null) {
591+
ExtentReportManager.info("Get Current Page Title: " + DriverManager.getDriver().getTitle());
592+
}
593+
AllureManager.saveTextLog("Get Current Page Title: " + DriverManager.getDriver().getTitle());
569594
return title;
570595
}
571596

src/main/java/anhtester/com/report/AllureManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public static void setAllureEnvironmentInformation() {
2727
put("Test URL", FrameworkConstants.URL_CRM).
2828
put("Target Execution", FrameworkConstants.TARGET).
2929
put("Global Timeout", String.valueOf(FrameworkConstants.WAIT_DEFAULT)).
30-
put("Headless Dode", FrameworkConstants.HEADLESS).
30+
put("Page Load Timeout", String.valueOf(FrameworkConstants.WAIT_PAGE_LOADED)).
31+
put("Headless Mode", FrameworkConstants.HEADLESS).
3132
put("Local Browser", String.valueOf(Browser.CHROME)).
3233
put("Remote URL", FrameworkConstants.REMOTE_URL).
3334
put("Remote Port", FrameworkConstants.REMOTE_PORT).
3435
build());
35-
3636

3737
}
3838

src/test/java/anhtester/com/listeners/TestListener.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public void onStart(ISuite iSuite) {
7070
AllureManager.setAllureEnvironmentInformation();
7171
ExtentReportManager.initReports();
7272
System.out.println("========= INSTALLED CONFIGURATION DATA =========");
73-
System.out.println(" ");
74-
Log.info("Start suite: " + iSuite.getName());
75-
iSuite.setAttribute("WebDriver", DriverManager.getDriver());
73+
System.out.println("");
74+
Log.info("Starting Suite: " + iSuite.getName());
75+
7676
// //Gọi hàm startRecord video trong CaptureHelpers class
7777
// if (VIDEO_RECORD.toLowerCase().trim().equals(YES)) {
7878
// CaptureHelpers.startRecord(iSuite.getName());
@@ -81,7 +81,7 @@ public void onStart(ISuite iSuite) {
8181

8282
@Override
8383
public void onFinish(ISuite iSuite) {
84-
Log.info("End suite testing " + iSuite.getName());
84+
Log.info("End Suite: " + iSuite.getName());
8585
WebUI.stopSoftAssertAll();
8686
//Kết thúc Suite và thực thi Extents Report, đóng gói Folder report và send mail
8787
ExtentReportManager.flushReports();
@@ -117,7 +117,7 @@ public CategoryType[] getCategoryType(ITestResult iTestResult) {
117117

118118
@Override
119119
public void onTestStart(ITestResult iTestResult) {
120-
Log.info("Test case: " + getTestName(iTestResult) + " test is starting...");
120+
Log.info("Test case: " + getTestName(iTestResult) + " is starting...");
121121
count_totalTCs = count_totalTCs + 1;
122122

123123
ExtentReportManager.createTest(iTestResult.getName());
@@ -165,11 +165,11 @@ public void onTestFailure(ITestResult iTestResult) {
165165
Log.error(iTestResult.getThrowable());
166166

167167
AllureManager.takeScreenshotToAttachOnAllureReport();
168+
AllureManager.saveTextLog(iTestResult.getThrowable().toString());
168169

169170
//Extent report screenshot file and log
170171
ExtentReportManager.addScreenShot(Status.FAIL, getTestName(iTestResult));
171-
ExtentReportManager.logMessage(Status.FAIL, "Test case: " + getTestName(iTestResult) + " is failed.");
172-
ExtentReportManager.logMessage(Status.FAIL, iTestResult.getThrowable());
172+
ExtentReportManager.logMessage(Status.FAIL, iTestResult.getThrowable().toString());
173173

174174
if (VIDEO_RECORD.toLowerCase().trim().equals(YES)) {
175175
screenRecorder.stopRecording(true);

src/test/java/anhtester/com/projects/website/crm/testcases/TestHandle.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void testUploadFileSendKeys() {
160160

161161
String filePath = Helpers.getCurrentDir() + "src\\test\\resources\\testdata\\TxtFileData.txt";
162162

163-
WebUI.uploadFileSendkeys(inputFileUpload, filePath);
163+
WebUI.uploadFileWithSendKeys(inputFileUpload, filePath);
164164

165165
WebUI.sleep(4);
166166
}
@@ -176,7 +176,7 @@ public void testUploadFileFormDialog() {
176176

177177
String filePath = Helpers.getCurrentDir() + "src\\test\\resources\\testdata\\TxtFileData.txt";
178178

179-
WebUI.uploadFileForm(divFileUpload, filePath);
179+
WebUI.uploadFileWithLocalForm(divFileUpload, filePath);
180180

181181
WebUI.sleep(4);
182182
}
@@ -337,15 +337,15 @@ public void handleUploadFile() {
337337
final String path2 = Helpers.getCurrentDir() + "src\\test\\resources\\testdata\\LoginCSV.csv";
338338

339339
//Cách 1 sendKeys link từ source
340-
WebUI.uploadFileSendkeys(By.xpath("//input[@id='uploadFile']"), path1);
340+
WebUI.uploadFileWithSendKeys(By.xpath("//input[@id='uploadFile']"), path1);
341341
WebUI.verifyElementTextContains(By.xpath("//p[@id='uploadedFilePath']"), "DOCX_File_01ABC.docx");
342342
WebUI.sleep(1);
343343
WebUI.reloadPage();
344344
WebUI.waitForPageLoaded();
345345
WebUI.sleep(1);
346346

347347
//Cách 2 mở form local máy nên file là trong ổ đĩa máy tính
348-
WebUI.uploadFileForm(By.xpath("//input[@id='uploadFile']"), path2);
348+
WebUI.uploadFileWithLocalForm(By.xpath("//input[@id='uploadFile']"), path2);
349349
WebUI.verifyElementTextContains(By.xpath("//p[@id='uploadedFilePath']"), "LoginCSV.csv");
350350
WebUI.sleep(3);
351351
}

src/test/resources/config/config.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ ACTIVE_PAGE_LOADED=true
1515
WAIT_SLEEP_STEP=0
1616
# Browser default chrome, edge, firefox, safari
1717
BROWSER=chrome
18-
# target execution: local or remote
19-
TARGET=local
2018
# headless mode only for chrome or firefox and local execution
2119
HEADLESS=false
2220
URL_CRM=https://rise.fairsketch.com/signin
21+
22+
# target execution: local or remote
23+
TARGET=local
2324
# grid url and port
24-
REMOTE_URL=localhost
25+
REMOTE_URL=192.168.1.13
2526
REMOTE_PORT=4444
2627
# Report information
2728
PROJECT_NAME=Automation Framework Selenium | Anh Tester

0 commit comments

Comments
 (0)