Skip to content

Commit 80d9ba5

Browse files
committed
Update version 1.4
1 parent 0d76d98 commit 80d9ba5

File tree

24 files changed

+920
-296
lines changed

24 files changed

+920
-296
lines changed

README.md

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Automation Framework Selenium Java with TestNG building by Anh Tester (VERSION 1.3)
1+
# Automation Framework Selenium Java with TestNG building by Anh Tester
2+
3+
**SOME FEATURES IN FRAMEWORK**
24

3-
**SOME FEATURES IN VERSION 1.3**
45
1. Run the parallel test case
56
2. Read Object web element from a properties file
67
3. Extent Report
@@ -12,44 +13,40 @@
1213
9. Base function in the package: utils, helpers
1314
10. Read data from Json file
1415
11. Main Keyword: WebUI (call common function)
15-
16-
16+
12. Sample test function
17+
1718
## **SYSTEM REQUIREMENTS**
19+
1820
- **JDK 11, 15, 16** (not run with 8, 17, 18)
1921
- Chrome Browser, Edge Browser
2022
- Setup **Allure**:
21-
https://mvnrepository.com/artifact/io.qameta.allure/allure-java-commons
22-
or
23-
https://anhtester.com/blog/selenium-java/selenium-java-tai-nguyen-cai-dat-moi-truong)
24-
Download jar and setting Variable Environment as Java JDK
25-
26-
![image](https://user-images.githubusercontent.com/87883620/161661705-b8706957-5a26-4faf-8ddf-2f9aef78418e.png)
23+
https://mvnrepository.com/artifact/io.qameta.allure/allure-java-commons
24+
or
25+
https://anhtester.com/blog/selenium-java/selenium-java-tai-nguyen-cai-dat-moi-truong)
26+
Download jar and setting Variable Environment as Java JDK
27+
28+
![image](https://user-images.githubusercontent.com/87883620/161661705-b8706957-5a26-4faf-8ddf-2f9aef78418e.png)
2729

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

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

32-
33-
3434
## **HOW TO USE**
3535

36-
3736
**1. Run parallel the test case**
37+
3838
- Run test case in suite XML (**src/test/resources/suites/**)
3939
- Run test case from Maven pom.xml file
4040
(**mvn clean test**)
41-
42-
![image](https://user-images.githubusercontent.com/87883620/161658761-5040e527-b410-46b3-8697-3298523e201d.png)
43-
4441

42+
![image](https://user-images.githubusercontent.com/87883620/161658761-5040e527-b410-46b3-8697-3298523e201d.png)
4543

4644
**2. Read Object web element from a properties file**
4745

4846
![image](https://user-images.githubusercontent.com/87883620/161658681-58f3a183-cbfd-433d-853a-927e4373f51c.png)
4947

50-
51-
5248
**3. Extent Report**
49+
5350
- Insert Framework Annotation as sample:
5451

5552
![image](https://user-images.githubusercontent.com/87883620/161657646-3dd652c6-a310-4006-a0cb-de63e2e87e36.png)
@@ -59,73 +56,63 @@
5956

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

62-
63-
6459
**4. Allure Report**
6560

66-
- Open Terminal: ***allure serve target/allure-results***
61+
- Open Terminal: **_allure serve target/allure-results_**
6762

6863
![image](https://user-images.githubusercontent.com/87883620/161662507-9e4dc698-e452-4b43-a4f5-9808c81419a2.png)
6964

70-
71-
- Insert **@Step("title/message")** above ***@Test*** or any ***Method*** in the project
65+
- Insert **@Step("title/message")** above **_@Test_** or any **_Method_** in the project
7266
- (As sample picture above step 3)
7367

7468
![image](https://user-images.githubusercontent.com/87883620/161657680-af29973d-4e52-451f-b1d6-40b12d182845.png)
7569

7670
![image](https://user-images.githubusercontent.com/87883620/161657689-10365747-ed8f-4ca8-9d84-8060514f216b.png)
7771

78-
79-
8072
**5. Send Mail after the run test**
8173

8274
- Config **true/false** in config.properties
83-
(***src/test/resources/config/config.properties***)
75+
(**_src/test/resources/config/config.properties_**)
8476
- send_email_to_users=**true** is enable send mail
85-
- Config mail with email and password in ***src/main/java/anhtester/com/mail/EmailConfig.java***
86-
Note: enabled Allow less secure apps
77+
- Config mail with email and password in **_src/main/java/anhtester/com/mail/EmailConfig.java_**
78+
Note: enabled Allow less secure apps
8779

8880
![image](https://user-images.githubusercontent.com/87883620/161658851-2aa41091-ac99-45d9-a79f-aaa828052efb.png)
8981

9082
![image](https://user-images.githubusercontent.com/87883620/161659238-88337f69-b742-4cd7-87f2-76670519c8dd.png)
9183

9284
![image](https://user-images.githubusercontent.com/87883620/161710836-8f3eee7c-19ba-410d-8498-5f314e6289a5.png)
9385

94-
95-
9686
**6. Log to file**
9787

98-
- Call class: Log.info , Log.pass, Log.error,... (**Log** is a custom global class from Log4j)
99-
(***import anhtester.com.utils.Log.java***)
100-
101-
![image](https://user-images.githubusercontent.com/87883620/161657858-d333ac1d-9e7b-4c1b-baac-151a237a1fa0.png)
102-
88+
- Call class: Log.info , Log.pass, Log.error,... (**Log** is a custom global class from Log4j2)
89+
(**_import anhtester.com.utils.Log.java_**)
10390

91+
![image](https://user-images.githubusercontent.com/87883620/161657858-d333ac1d-9e7b-4c1b-baac-151a237a1fa0.png)
10492

10593
**7. Record video and Screenshot**
10694

107-
- Setup in ***config.properties*** file
108-
(***src/test/resources/config/config.properties***)
109-
screenshot_passed_steps=yes or no
110-
screenshot_failed_steps=yes or no
111-
screenshot_skipped_steps=yes or no
112-
113-
![image](https://user-images.githubusercontent.com/87883620/161657881-5235139a-9982-43c0-ac37-09f22fff1206.png)
114-
95+
- Setup in **_config.properties_** file
96+
(**_src/test/resources/config/config.properties_**)
97+
- screenshot_passed_steps=yes or no
98+
- screenshot_failed_steps=yes or no
99+
- screenshot_skipped_steps=yes or no
100+
- screenshot_all_steps=yes or no
115101

102+
![image](https://user-images.githubusercontent.com/87883620/161657881-5235139a-9982-43c0-ac37-09f22fff1206.png)
116103

117104
**8. Read data test from Excel file**
118105

119-
- Create function with annotaion **DataSupplier** on ***src/main/java/anhtester/com/utils/DataProviderUtils.java***
106+
- Create function with annotaion **DataSupplier** on **_src/main/java/anhtester/com/utils/DataProviderUtils.java_**
120107
- Call the name of **DataSupplier** above in the test cases as DataProvider of TestNG
108+
- Read excel with Map and Hashtable
121109

122110
**9. Base function in the package**
123111

124-
- ***src/main/java/anhtester/com/utils***
125-
- ***src/main/java/anhtester/com/helpers***
126-
127-
**10. Read data from JSON file**
112+
- **_src/main/java/anhtester/com/utils_**
113+
- **_src/main/java/anhtester/com/helpers_**
128114

115+
**10. Read data from JSON file**
129116

130117
- **JsonUtils** class select the json file path and call **"get"** method with **key**
131118

@@ -136,19 +123,20 @@ Note: enabled Allow less secure apps
136123
- Example: WebUI.setWindowSize(1024, 768), WebUI.screenshotElement(By by, String elementName),...
137124

138125
**12. Call function to using sample**
126+
139127
- All in one package: src/test/java/anhtester/com/projects/website/crm/testcases
128+
140129
```
141130
+ ClientTest
142131
+ SignInTest
143132
+ TestHandle
144133
+ TestSimpleCode
145134
```
146135

147-
148136
## Project structure
149137

150138
```
151-
AutomationFrameworkSelenium
139+
📦AutomationFrameworkSelenium
152140
┣ 📂src
153141
┃ ┣ 📂main
154142
┃ ┃ ┣ 📂java
@@ -208,23 +196,23 @@ AutomationFrameworkSelenium
208196
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜EmailSendUtils.java
209197
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜IconUtils.java
210198
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜JsonUtils.java
199+
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜LanguageUtils.java
200+
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜LocalStorageUtils.java
211201
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜Log.java
212202
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ObjectUtils.java
213203
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ReportUtils.java
214204
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜WebUI.java
215205
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ZipUtils.java
216206
┃ ┃ ┗ 📂resources
217207
┃ ┃ ┃ ┣ 📜drag_and_drop_helper.js
218-
┃ ┃ ┃ ┣ 📜extent.properties
219208
┃ ┃ ┃ ┣ 📜jquery_load_helper.js
220209
┃ ┃ ┃ ┗ 📜log4j2.properties
221210
┃ ┗ 📂test
222211
┃ ┃ ┣ 📂java
223212
┃ ┃ ┃ ┗ 📂anhtester
224213
┃ ┃ ┃ ┃ ┗ 📂com
225214
┃ ┃ ┃ ┃ ┃ ┣ 📂common
226-
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜BaseTest.java
227-
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜CommonTest.java
215+
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜BaseTest.java
228216
┃ ┃ ┃ ┃ ┃ ┣ 📂listeners
229217
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TestListener.java
230218
┃ ┃ ┃ ┃ ┃ ┗ 📂projects
@@ -237,9 +225,8 @@ AutomationFrameworkSelenium
237225
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DashboardPage.java
238226
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂Projects
239227
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ProjectPage.java
240-
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ 📂SignIn
228+
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ 📂SignIn
241229
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜SignInPage.java
242-
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜CommonPage.java
243230
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂testcases
244231
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ClientTest.java
245232
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜SignInTest.java
@@ -265,10 +252,8 @@ AutomationFrameworkSelenium
265252
┗ 📜README.md
266253
```
267254

268-
269255
## I shall write document for my Framework. Coming soon...
270256

271-
272257
# Copyright 2022 Anh Tester
273258

274259
> Anh Tester Blog: https://anhtester.com/

pom.xml

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

77
<groupId>anhtester.com</groupId>
88
<artifactId>AutomationFrameworkSelenium</artifactId>
9-
<version>1.3</version>
9+
<version>1.4</version>
1010
<name>AutomationFrameworkSelenium</name>
1111
<url>https://github.com/anhtester/AutomationFrameworkSelenium</url>
1212

@@ -15,12 +15,12 @@
1515
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1616
<java-compiler.version>11</java-compiler.version>
1717
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
18-
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
18+
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
1919

2020
<selenium.version>4.1.4</selenium.version>
21-
<testng.version>7.4.0</testng.version>
21+
<testng.version>7.5</testng.version>
2222
<webdrivermanager.version>5.1.1</webdrivermanager.version>
23-
<aspectjweaver.version>1.9.7</aspectjweaver.version>
23+
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>
2424
<ashot.version>1.5.4</ashot.version>
2525
<log4j.version>2.17.2</log4j.version>
2626
<allure-testng.version>2.17.3</allure-testng.version>
@@ -36,14 +36,14 @@
3636
<assertj.version>3.22.0</assertj.version>
3737
<javafaker.version>1.0.2</javafaker.version>
3838
<monte-screen-recorder.version>0.7.7.0</monte-screen-recorder.version>
39-
<mysql-connector-java.version>8.0.28</mysql-connector-java.version>
40-
<google.zxing.version>3.4.1</google.zxing.version>
39+
<mysql-connector-java.version>8.0.29</mysql-connector-java.version>
40+
<google.zxing.version>3.5.0</google.zxing.version>
4141
<lombok.version>1.18.24</lombok.version>
4242
<google.guava.version>31.1-jre</google.guava.version>
4343
<data.supplier.version>1.9.7</data.supplier.version>
4444
<javax.mail.version>1.6.2</javax.mail.version>
4545
<zip.version>1.15</zip.version>
46-
<jackson.version>2.13.2</jackson.version>
46+
<jackson.version>2.13.3</jackson.version>
4747

4848
<!-- Suite XML path -->
4949
<suite.signin.simple>src/test/resources/suites/SignIn-simple.xml</suite.signin.simple>

src/main/java/anhtester/com/constants/FrameworkConstants.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ private FrameworkConstants() {
4040
public static final String screenshot_passed_steps = PropertiesHelpers.getValue("screenshot_passed_steps");
4141
public static final String screenshot_failed_steps = PropertiesHelpers.getValue("screenshot_failed_steps");
4242
public static final String screenshot_skipped_steps = PropertiesHelpers.getValue("screenshot_skipped_steps");
43+
public static final String screenshot_all_steps = PropertiesHelpers.getValue("screenshot_all_steps");
4344

4445
public static final int WAIT_DEFAULT = Integer.parseInt(PropertiesHelpers.getValue("WAIT_DEFAULT"));
4546
public static final int WAIT_IMPLICIT = Integer.parseInt(PropertiesHelpers.getValue("WAIT_IMPLICIT"));
4647
public static final int WAIT_EXPLICIT = Integer.parseInt(PropertiesHelpers.getValue("WAIT_EXPLICIT"));
4748
public static final int WAIT_PAGE_LOADED = Integer.parseInt(PropertiesHelpers.getValue("WAIT_PAGE_LOADED"));
49+
public static final int WAIT_SLEEP_STEP = Integer.parseInt(PropertiesHelpers.getValue("WAIT_SLEEP_STEP"));
50+
public static final String ACTIVE_PAGE_LOADED = PropertiesHelpers.getValue("ACTIVE_PAGE_LOADED");
4851

4952
public static final String EXTENT_REPORT_FOLDER_PATH = PROJECT_PATH + EXTENT_REPORT_FOLDER;
5053
public static final String EXTENT_REPORT_FILE_NAME = EXTENT_REPORT_NAME + ".html";
@@ -53,8 +56,6 @@ private FrameworkConstants() {
5356
//Zip file for Report folder
5457
public static final String Zipped_ExtentReports_Folder_Name = EXTENT_REPORT_FOLDER + ".zip";
5558

56-
public static final String TEST_DATA_XLSX_FILE = "src/test/resources/testdatafile/ClientsDataExcel.xlsx";
57-
5859
public static final String YES = "yes";
5960
public static final String NO = "no";
6061

src/main/java/anhtester/com/helpers/Helpers.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,26 @@
77

88
import java.io.*;
99
import java.nio.charset.Charset;
10+
import java.text.Normalizer;
1011
import java.util.ArrayList;
12+
import java.util.Locale;
13+
import java.util.regex.Pattern;
1114

1215
public final class Helpers {
1316

17+
private static final Pattern NONLATIN = Pattern.compile("[^\\w-]");
18+
private static final Pattern WHITESPACE = Pattern.compile("[\\s]");
19+
20+
public static String makeSlug(String input) {
21+
if (input == null)
22+
throw new IllegalArgumentException();
23+
24+
String noWhiteSpace = WHITESPACE.matcher(input).replaceAll("_");
25+
String normalized = Normalizer.normalize(noWhiteSpace, Normalizer.Form.NFD);
26+
String slug = NONLATIN.matcher(normalized).replaceAll("");
27+
return slug.toLowerCase(Locale.ENGLISH);
28+
}
29+
1430
public static String readFile(String file) throws IOException {
1531
Charset cs = Charset.forName("UTF-8");
1632
FileInputStream stream = new FileInputStream(file);
@@ -59,7 +75,7 @@ public static void CreateFolder(String path) {
5975
System.out.println("Folder already created");
6076
}
6177
}
62-
78+
6379
/**
6480
* @param str chuỗi string cần tách ra theo điều kiện
6581
* @param valueSplit ký tự cần tách chuỗi thành mảng giá trị

src/main/java/anhtester/com/helpers/PropertiesHelpers.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
package anhtester.com.helpers;
77

8+
import anhtester.com.utils.LanguageUtils;
89
import anhtester.com.utils.Log;
910
import io.qameta.allure.Step;
1011

1112
import java.io.FileInputStream;
1213
import java.io.FileOutputStream;
1314
import java.io.IOException;
15+
import java.io.InputStreamReader;
16+
import java.nio.charset.Charset;
17+
import java.nio.charset.StandardCharsets;
1418
import java.util.LinkedList;
1519
import java.util.Properties;
1620

@@ -83,6 +87,7 @@ public static String getValue(String key) {
8387
}
8488
// Lấy giá trị từ file đã Set
8589
keyval = properties.getProperty(key);
90+
return LanguageUtils.convertCharset_ISO_8859_1_To_UTF8(keyval);
8691
} catch (Exception e) {
8792
System.out.println(e.getMessage());
8893
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2022 Anh Tester
3+
* Automation Framework Selenium
4+
*/
5+
16
package anhtester.com.report;
27

38
import anhtester.com.constants.FrameworkConstants;
@@ -39,6 +44,16 @@ public static byte[] takeScreenshotToAttachOnAllureReport() {
3944
return new byte[0];
4045
}
4146

47+
@Attachment(value = "Take step screenshot", type = "image/png")
48+
public static byte[] takeScreenshotStep() {
49+
try {
50+
return ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(BYTES);
51+
} catch (Exception ex) {
52+
ex.getMessage();
53+
}
54+
return new byte[0];
55+
}
56+
4257
@Attachment(value = "Browser Information", type = "text/plain")
4358
public static String addBrowserInformationOnAllureReport() {
4459
return BrowserInfoUtils.getOSInfo();

0 commit comments

Comments
 (0)