Skip to content

Commit

Permalink
Update version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
anhtester committed May 18, 2022
1 parent 0d76d98 commit 80d9ba5
Show file tree
Hide file tree
Showing 24 changed files with 920 additions and 296 deletions.
99 changes: 42 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Automation Framework Selenium Java with TestNG building by Anh Tester (VERSION 1.3)
# Automation Framework Selenium Java with TestNG building by Anh Tester

**SOME FEATURES IN FRAMEWORK**

**SOME FEATURES IN VERSION 1.3**
1. Run the parallel test case
2. Read Object web element from a properties file
3. Extent Report
Expand All @@ -12,44 +13,40 @@
9. Base function in the package: utils, helpers
10. Read data from Json file
11. Main Keyword: WebUI (call common function)
12. Sample test function

## **SYSTEM REQUIREMENTS**

- **JDK 11, 15, 16** (not run with 8, 17, 18)
- Chrome Browser, Edge 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
![image](https://user-images.githubusercontent.com/87883620/161661705-b8706957-5a26-4faf-8ddf-2f9aef78418e.png)
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

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

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

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



## **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**)

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


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

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

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



**3. Extent Report**

- Insert Framework Annotation as sample:

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

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



**4. Allure Report**

- Open Terminal: ***allure serve target/allure-results***
- Open Terminal: **_allure serve target/allure-results_**

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


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

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

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



**5. Send Mail after the run test**

- Config **true/false** in config.properties
(***src/test/resources/config/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
- Config mail with email and password in **_src/main/java/anhtester/com/mail/EmailConfig.java_**
Note: enabled Allow less secure apps

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

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

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



**6. Log to file**

- Call class: Log.info , Log.pass, Log.error,... (**Log** is a custom global class from Log4j)
(***import anhtester.com.utils.Log.java***)

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

- Call class: Log.info , Log.pass, Log.error,... (**Log** is a custom global class from Log4j2)
(**_import anhtester.com.utils.Log.java_**)

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

**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

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

- 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

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

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

- Create function with annotaion **DataSupplier** on ***src/main/java/anhtester/com/utils/DataProviderUtils.java***
- Create function with annotaion **DataSupplier** on **_src/main/java/anhtester/com/utils/DataProviderUtils.java_**
- Call the name of **DataSupplier** above in the test cases as DataProvider of TestNG
- 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 from JSON file**
- **_src/main/java/anhtester/com/utils_**
- **_src/main/java/anhtester/com/helpers_**

**10. Read data from JSON file**

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

Expand All @@ -136,19 +123,20 @@ Note: enabled Allow less secure apps
- 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
```


## Project structure

```
AutomationFrameworkSelenium
📦AutomationFrameworkSelenium
┣ 📂src
┃ ┣ 📂main
┃ ┃ ┣ 📂java
Expand Down Expand Up @@ -208,23 +196,23 @@ AutomationFrameworkSelenium
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜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
┃ ┃ ┃ ┣ 📜extent.properties
┃ ┃ ┃ ┣ 📜jquery_load_helper.js
┃ ┃ ┃ ┗ 📜log4j2.properties
┃ ┗ 📂test
┃ ┃ ┣ 📂java
┃ ┃ ┃ ┗ 📂anhtester
┃ ┃ ┃ ┃ ┗ 📂com
┃ ┃ ┃ ┃ ┃ ┣ 📂common
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜BaseTest.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜CommonTest.java
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜BaseTest.java
┃ ┃ ┃ ┃ ┃ ┣ 📂listeners
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜TestListener.java
┃ ┃ ┃ ┃ ┃ ┗ 📂projects
Expand All @@ -237,9 +225,8 @@ AutomationFrameworkSelenium
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DashboardPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂Projects
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ProjectPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ 📂SignIn
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ 📂SignIn
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜SignInPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜CommonPage.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂testcases
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜ClientTest.java
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜SignInTest.java
Expand All @@ -265,10 +252,8 @@ AutomationFrameworkSelenium
┗ 📜README.md
```


## I shall write document for my Framework. Coming soon...


# Copyright 2022 Anh Tester

> Anh Tester Blog: https://anhtester.com/
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>anhtester.com</groupId>
<artifactId>AutomationFrameworkSelenium</artifactId>
<version>1.3</version>
<version>1.4</version>
<name>AutomationFrameworkSelenium</name>
<url>https://github.com/anhtester/AutomationFrameworkSelenium</url>

Expand All @@ -15,12 +15,12 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java-compiler.version>11</java-compiler.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>

<selenium.version>4.1.4</selenium.version>
<testng.version>7.4.0</testng.version>
<testng.version>7.5</testng.version>
<webdrivermanager.version>5.1.1</webdrivermanager.version>
<aspectjweaver.version>1.9.7</aspectjweaver.version>
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>
<ashot.version>1.5.4</ashot.version>
<log4j.version>2.17.2</log4j.version>
<allure-testng.version>2.17.3</allure-testng.version>
Expand All @@ -36,14 +36,14 @@
<assertj.version>3.22.0</assertj.version>
<javafaker.version>1.0.2</javafaker.version>
<monte-screen-recorder.version>0.7.7.0</monte-screen-recorder.version>
<mysql-connector-java.version>8.0.28</mysql-connector-java.version>
<google.zxing.version>3.4.1</google.zxing.version>
<mysql-connector-java.version>8.0.29</mysql-connector-java.version>
<google.zxing.version>3.5.0</google.zxing.version>
<lombok.version>1.18.24</lombok.version>
<google.guava.version>31.1-jre</google.guava.version>
<data.supplier.version>1.9.7</data.supplier.version>
<javax.mail.version>1.6.2</javax.mail.version>
<zip.version>1.15</zip.version>
<jackson.version>2.13.2</jackson.version>
<jackson.version>2.13.3</jackson.version>

<!-- Suite XML path -->
<suite.signin.simple>src/test/resources/suites/SignIn-simple.xml</suite.signin.simple>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/anhtester/com/constants/FrameworkConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ private FrameworkConstants() {
public static final String screenshot_passed_steps = PropertiesHelpers.getValue("screenshot_passed_steps");
public static final String screenshot_failed_steps = PropertiesHelpers.getValue("screenshot_failed_steps");
public static final String screenshot_skipped_steps = PropertiesHelpers.getValue("screenshot_skipped_steps");
public static final String screenshot_all_steps = PropertiesHelpers.getValue("screenshot_all_steps");

public static final int WAIT_DEFAULT = Integer.parseInt(PropertiesHelpers.getValue("WAIT_DEFAULT"));
public static final int WAIT_IMPLICIT = Integer.parseInt(PropertiesHelpers.getValue("WAIT_IMPLICIT"));
public static final int WAIT_EXPLICIT = Integer.parseInt(PropertiesHelpers.getValue("WAIT_EXPLICIT"));
public static final int WAIT_PAGE_LOADED = Integer.parseInt(PropertiesHelpers.getValue("WAIT_PAGE_LOADED"));
public static final int WAIT_SLEEP_STEP = Integer.parseInt(PropertiesHelpers.getValue("WAIT_SLEEP_STEP"));
public static final String ACTIVE_PAGE_LOADED = PropertiesHelpers.getValue("ACTIVE_PAGE_LOADED");

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

public static final String TEST_DATA_XLSX_FILE = "src/test/resources/testdatafile/ClientsDataExcel.xlsx";

public static final String YES = "yes";
public static final String NO = "no";

Expand Down
18 changes: 17 additions & 1 deletion src/main/java/anhtester/com/helpers/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@

import java.io.*;
import java.nio.charset.Charset;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Locale;
import java.util.regex.Pattern;

public final class Helpers {

private static final Pattern NONLATIN = Pattern.compile("[^\\w-]");
private static final Pattern WHITESPACE = Pattern.compile("[\\s]");

public static String makeSlug(String input) {
if (input == null)
throw new IllegalArgumentException();

String noWhiteSpace = WHITESPACE.matcher(input).replaceAll("_");
String normalized = Normalizer.normalize(noWhiteSpace, Normalizer.Form.NFD);
String slug = NONLATIN.matcher(normalized).replaceAll("");
return slug.toLowerCase(Locale.ENGLISH);
}

public static String readFile(String file) throws IOException {
Charset cs = Charset.forName("UTF-8");
FileInputStream stream = new FileInputStream(file);
Expand Down Expand Up @@ -59,7 +75,7 @@ public static void CreateFolder(String path) {
System.out.println("Folder already created");
}
}

/**
* @param str chuỗi string cần tách ra theo điều kiện
* @param valueSplit ký tự cần tách chuỗi thành mảng giá trị
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/anhtester/com/helpers/PropertiesHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

package anhtester.com.helpers;

import anhtester.com.utils.LanguageUtils;
import anhtester.com.utils.Log;
import io.qameta.allure.Step;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.Properties;

Expand Down Expand Up @@ -83,6 +87,7 @@ public static String getValue(String key) {
}
// Lấy giá trị từ file đã Set
keyval = properties.getProperty(key);
return LanguageUtils.convertCharset_ISO_8859_1_To_UTF8(keyval);
} catch (Exception e) {
System.out.println(e.getMessage());
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/anhtester/com/report/AllureManager.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2022 Anh Tester
* Automation Framework Selenium
*/

package anhtester.com.report;

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

@Attachment(value = "Take step screenshot", type = "image/png")
public static byte[] takeScreenshotStep() {
try {
return ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(BYTES);
} catch (Exception ex) {
ex.getMessage();
}
return new byte[0];
}

@Attachment(value = "Browser Information", type = "text/plain")
public static String addBrowserInformationOnAllureReport() {
return BrowserInfoUtils.getOSInfo();
Expand Down
Loading

0 comments on commit 80d9ba5

Please sign in to comment.