Skip to content

Commit 942460b

Browse files
committed
Update version 1.2
1 parent e00fdcd commit 942460b

40 files changed

+726
-443
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Automation Framework Selenium Java with TestNG building by Anh Tester (VERSION 1.0)
1+
# Automation Framework Selenium Java with TestNG building by Anh Tester (VERSION 1.2)
22

3-
**SOME FEATURES IN VERSION 1.0**
3+
**SOME FEATURES IN VERSION 1.2**
44
1. Run the parallel test case
55
2. Read Object web element from a properties file
66
3. Extent Report
@@ -9,8 +9,8 @@
99
6. Logfile
1010
7. Record video and Screenshot test case for failed
1111
8. Read data test form Excel file (xlsx, csv, json,...) with class define fields (param: Client client)
12-
9. Base function in the library (WebUI, Utils,...)
13-
...etc.. (wait, dynamic xpath,...)
12+
9. Base function in the library (WebUI, Utils,...) ...etc.. (wait, dynamic xpath,...)
13+
10. Read data from Json file
1414

1515

1616
## **SYSTEM REQUIREMENTS**
@@ -124,6 +124,10 @@ Note: enabled Allow less secure apps
124124
- And ..etc.. on ***src/main/java/anhtester/com***
125125
(It is static method)
126126

127+
**10. Read data from JSON file**
128+
129+
- **JsonUtils** class select the json file path and call **"get"** method with **key**
130+
127131

128132
# Copyright 2022 Anh Tester
129133

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<data.supplier.version>1.9.7</data.supplier.version>
4242
<javax.mail.version>1.6.2</javax.mail.version>
4343
<zip.version>1.14</zip.version>
44+
<jackson.version>2.13.2</jackson.version>
4445

4546
<!-- Suite XML path -->
4647
<suite.signin.simple>src/test/resources/suites/SignIn-simple.xml</suite.signin.simple>
@@ -64,6 +65,21 @@
6465
<version>${testng.version}</version>
6566
</dependency>
6667

68+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
69+
<dependency>
70+
<groupId>com.fasterxml.jackson.core</groupId>
71+
<artifactId>jackson-databind</artifactId>
72+
<version>${jackson.version}</version>
73+
</dependency>
74+
75+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
76+
<dependency>
77+
<groupId>com.fasterxml.jackson.core</groupId>
78+
<artifactId>jackson-core</artifactId>
79+
<version>${jackson.version}</version>
80+
</dependency>
81+
82+
6783
<!-- https://mvnrepository.com/artifact/io.github.sskorol/test-data-supplier -->
6884
<dependency>
6985
<groupId>io.github.sskorol</groupId>

src/main/java/anhtester/com/config/Configuration.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,4 @@ public interface Configuration extends Config {
3131
@Key("remote_port")
3232
String gridPort();
3333

34-
@Key("faker.locale")
35-
String faker();
36-
3734
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2022.
3-
* Automation Framework Selenium - Anh Tester
2+
* Copyright (c) 2022 Anh Tester
3+
* Automation Framework Selenium
44
*/
55

66
package anhtester.com.constants;
@@ -19,6 +19,7 @@ private FrameworkConstants() {
1919
public static final String PROJECT_PATH = Helpers.getCurrentDir();
2020
public static final String EXCEL_DATA_PATH = PropertiesHelpers.getValue("excelDataFilePath");
2121
public static final String EXCEL_DATA_PATH_FULL = PropertiesHelpers.getValue("excelDataFilePathFull");
22+
public static final String JSON_CONFIG_FILE_PATH = Helpers.getCurrentDir() + "src/test/resources/config/config.json";
2223

2324
public static final String BROWSER = PropertiesHelpers.getValue("browser");
2425
public static final String BASE_URL = PropertiesHelpers.getValue("base_url");

src/main/java/anhtester/com/data/DataProviderManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import anhtester.com.helpers.Helpers;
1111
import anhtester.com.models.Client;
1212
import anhtester.com.models.SignIn;
13+
import anhtester.com.utils.WebUI;
1314
import io.github.sskorol.core.DataSupplier;
1415
import io.github.sskorol.data.TestDataReader;
1516
import io.github.sskorol.data.XlsxReader;
@@ -51,8 +52,9 @@ public void testAddClient(Client clientData) {
5152
//@DataSupplier //--> It can read any file (CSV, xlsx, JSON, YAMLDataSupplierTest)
5253
//@DataSupplier(runInParallel = true)
5354
@DataSupplier(runInParallel = true, name = "getDataSignInSupplierFromExcel")
54-
public StreamEx<SignIn> getDataSignInSupplierFromExcel(Method method) {
55+
public static StreamEx<SignIn> getDataSignInSupplierFromExcel(Method method) {
5556
String methodName = method.getName().trim();
57+
WebUI.logConsole(methodName);
5658
System.out.println(methodName);
5759
return TestDataReader.use(XlsxReader.class)
5860
.withTarget(SignIn.class)
@@ -64,7 +66,7 @@ public StreamEx<SignIn> getDataSignInSupplierFromExcel(Method method) {
6466
}
6567

6668
@DataSupplier(runInParallel = true, name = "getDataClientSupplierFromExcel")
67-
public StreamEx<Client> getDataClientSupplierFromExcel(Method method) {
69+
public static StreamEx<Client> getDataClientSupplierFromExcel(Method method) {
6870
String methodName = method.getName().trim();
6971
System.out.println(methodName);
7072
return TestDataReader.use(XlsxReader.class)
@@ -82,15 +84,15 @@ public static StreamEx getDataSignInFromExampleData() {
8284
);
8385
}
8486

85-
@DataProvider(name = "SignInDataHashTable")
86-
public Object[][] getSignInData() {
87-
Object[][] data = ExcelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_PATH_FULL, "SignIn", 2, 4);
87+
@DataProvider(name = "getSignInDataHashTable")
88+
public static Object[][] getSignInData() {
89+
Object[][] data = ExcelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_PATH_FULL, "SignIn", 1, 2);
8890
System.out.println(data);
8991
return data;
9092
}
9193

92-
@DataProvider(name = "ClientDataHashTable")
93-
public Object[][] getClientData() {
94+
@DataProvider(name = "getClientDataHashTable")
95+
public static Object[][] getClientData() {
9496
Object[][] data = ExcelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_PATH_FULL, "Client", 1, 2);
9597
System.out.println(data);
9698
return data;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2022 Anh Tester
3+
* Automation Framework Selenium
4+
*/
5+
6+
package anhtester.com.enums;
7+
8+
public enum FailureHandling {
9+
STOP_ON_FAILURE, CONTINUE_ON_FAILURE, OPTIONAL
10+
}

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,18 @@ public static Object[][] getDataHashTable(String ExcelPath, String SheetName, in
155155

156156
int rows = getRowCount();
157157
int columns = getColumnCount();
158-
System.out.println("Row: " + rows + " - Column: " + columns);
158+
//System.out.println("Row: " + rows + " - Column: " + columns);
159159
data = new Object[endRow - startRow][1];
160160
Hashtable<String, String> table = null;
161161
for (int rowNums = startRow; rowNums < endRow; rowNums++) {
162-
table = new Hashtable<String, String>();
162+
table = new Hashtable<>();
163163
for (int colNum = 0; colNum < columns; colNum++) {
164164
// data[rowNums-2][colNum] = excel.getCellData(sheetName, colNum, rowNums);
165165
table.put(getCellData(0, colNum), getCellData(rowNums, colNum));
166166
data[rowNums - startRow][0] = table;
167167
}
168168
}
169169

170-
System.out.println(data);
171170
} catch (FileNotFoundException e) {
172171
e.printStackTrace();
173172
} catch (IOException e) {
@@ -350,16 +349,50 @@ public static int getColumnCount() {
350349
}
351350

352351
// Write data to excel sheet
353-
public static void setCellData(String text, int rowNum, int colnum) {
352+
public static void setCellData(String text, int rowNumber, int colNumber) {
353+
try {
354+
row = sh.getRow(rowNumber);
355+
if (row == null) {
356+
row = sh.createRow(rowNumber);
357+
}
358+
cell = row.getCell(colNumber);
359+
360+
if (cell == null) {
361+
cell = row.createCell(colNumber);
362+
}
363+
cell.setCellValue(text);
364+
365+
XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle();
366+
if (text == "pass" || text == "passed" || text == "Pass" || text == "Passed") {
367+
style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
368+
} else {
369+
style.setFillForegroundColor(IndexedColors.RED.getIndex());
370+
}
371+
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
372+
style.setAlignment(HorizontalAlignment.CENTER);
373+
style.setVerticalAlignment(VerticalAlignment.CENTER);
374+
375+
cell.setCellStyle(style);
376+
377+
fileOut = new FileOutputStream(excelFilePath);
378+
wb.write(fileOut);
379+
fileOut.flush();
380+
fileOut.close();
381+
} catch (Exception e) {
382+
System.out.println(e.getMessage());
383+
}
384+
}
385+
386+
public static void setCellData(String text, int rowNum, String columnName) {
354387
try {
355388
row = sh.getRow(rowNum);
356389
if (row == null) {
357390
row = sh.createRow(rowNum);
358391
}
359-
cell = row.getCell(colnum);
392+
cell = row.getCell(columns.get(columnName));
360393

361394
if (cell == null) {
362-
cell = row.createCell(colnum);
395+
cell = row.createCell(columns.get(columnName));
363396
}
364397
cell.setCellValue(text);
365398

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,29 @@
1111
import javax.crypto.Cipher;
1212
import javax.crypto.SecretKey;
1313
import javax.crypto.spec.SecretKeySpec;
14-
import java.io.File;
14+
import java.io.*;
15+
import java.nio.charset.Charset;
1516
import java.util.ArrayList;
1617

1718
public final class Helpers {
1819

20+
public static String readFile(String file) throws IOException {
21+
Charset cs = Charset.forName("UTF-8");
22+
FileInputStream stream = new FileInputStream(file);
23+
try {
24+
Reader reader = new BufferedReader(new InputStreamReader(stream, cs));
25+
StringBuilder builder = new StringBuilder();
26+
char[] buffer = new char[8192];
27+
int read;
28+
while ((read = ((BufferedReader) reader).read(buffer, 0, buffer.length)) > 0) {
29+
builder.append(buffer, 0, read);
30+
}
31+
return builder.toString();
32+
} finally {
33+
stream.close();
34+
}
35+
}
36+
1937
/**
2038
* @return lấy đường dẫn đến thư mục nguồn source mình có thêm dấu / ở cuối luôn
2139
*/
@@ -61,13 +79,4 @@ public static ArrayList<String> splitString(String str, String valueSplit) {
6179
return arrayListString;
6280
}
6381

64-
/**
65-
* In ra câu message trong Console log
66-
*
67-
* @param object truyền vào object bất kỳ
68-
*/
69-
public static void logConsole(@Nullable Object object) {
70-
System.out.println(object);
71-
}
72-
7382
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package anhtester.com.report;
22

3-
import anhtester.com.config.ConfigFactory;
43
import anhtester.com.constants.FrameworkConstants;
54
import anhtester.com.driver.DriverManager;
65
import anhtester.com.enums.Browser;
7-
import anhtester.com.utils.Log;
8-
import anhtester.com.utils.OSInfoUtils;
6+
import anhtester.com.utils.BrowserInfoUtils;
97
import com.github.automatedowl.tools.AllureEnvironmentWriter;
108
import com.google.common.collect.ImmutableMap;
119
import io.qameta.allure.Attachment;
12-
import org.openqa.selenium.OutputType;
1310
import org.openqa.selenium.TakesScreenshot;
1411

1512
import static org.openqa.selenium.OutputType.BYTES;
@@ -44,7 +41,7 @@ public static byte[] takeScreenshotToAttachOnAllureReport() {
4441

4542
@Attachment(value = "Browser Information", type = "text/plain")
4643
public static String addBrowserInformationOnAllureReport() {
47-
return OSInfoUtils.getOSInfo();
44+
return BrowserInfoUtils.getOSInfo();
4845
}
4946

5047
//Text attachments for Allure

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void initReports() {
2828
ExtentSparkReporter spark = new ExtentSparkReporter(FrameworkConstants.EXTENT_REPORT_FILE_PATH);
2929
extentReports.attachReporter(spark);
3030
spark.config().setTheme(Theme.STANDARD);
31-
spark.config().setDocumentTitle("AT Report");
31+
spark.config().setDocumentTitle(FrameworkConstants.REPORT_TITLE);
3232
spark.config().setReportName(FrameworkConstants.REPORT_TITLE);
3333
extentReports.setSystemInfo("Framework Name", FrameworkConstants.REPORT_TITLE);
3434
extentReports.setSystemInfo("Author", FrameworkConstants.AUTHOR);

0 commit comments

Comments
 (0)