Skip to content

Commit e38c1ff

Browse files
committed
Update version 1.6.0 PREVIEW
1 parent 3b8c6d4 commit e38c1ff

7 files changed

Lines changed: 44 additions & 24 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static String readFile(String file) throws IOException {
4848
* @return lấy đường dẫn đến thư mục nguồn source mình có thêm dấu / ở cuối luôn
4949
*/
5050
public static String getCurrentDir() {
51-
String current = System.getProperty("user.dir") + "\\";
51+
String current = System.getProperty("user.dir") + File.separator;
5252
return current;
5353
}
5454

@@ -57,7 +57,7 @@ public static String getCurrentDir() {
5757
*
5858
* @param path đường dẫn cần tạo folder
5959
*/
60-
public static void CreateFolder(String path) {
60+
public static void createFolder(String path) {
6161
// File is a class inside java.io package
6262
File file = new File(path);
6363

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,13 @@ public static void scrollToElement(By element) {
10611061
js.executeScript("arguments[0].scrollIntoView(true);", getWebElement(element));
10621062
}
10631063

1064+
public static void scrollToElement(WebElement element) {
1065+
smartWait();
1066+
1067+
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
1068+
js.executeScript("arguments[0].scrollIntoView(true);", element);
1069+
}
1070+
10641071
public static void scrollToPosition(int X, int Y) {
10651072
smartWait();
10661073

@@ -1463,7 +1470,34 @@ public static String getTagNameElement(By by) {
14631470
//Handle Table
14641471

14651472
/**
1466-
* Kiểm tra giá trị từng cột của table khi tìm kiếm theo điều kiện CHỨA
1473+
* Kiểm tra giá trị từng cột của table khi tìm kiếm theo điều kiện BẰNG (equals)
1474+
*
1475+
* @param column vị trí cột
1476+
* @param value giá trị cần so sánh
1477+
*/
1478+
@Step("Check data by EQUALS type after searching on the Table by Column.")
1479+
public static void checkEqualsSearchTableByColumn(int column, String value) {
1480+
smartWait();
1481+
sleep(1);
1482+
List<WebElement> totalRows = getWebElements(By.xpath("//tbody/tr"));
1483+
Log.info("Number of results for keyword (" + value + "): " + totalRows.size());
1484+
1485+
if (totalRows.size() < 1) {
1486+
Log.info("Not found value: " + value);
1487+
} else {
1488+
for (int i = 1; i <= totalRows.size(); i++) {
1489+
boolean res = false;
1490+
WebElement title = waitForElementPresent(By.xpath("//tbody/tr[" + i + "]/td[" + column + "]"));
1491+
WebUI.scrollToElement(title);
1492+
res = title.getText().toUpperCase().equals(value.toUpperCase());
1493+
Log.info("Row " + i + ": " + res + " - " + title.getText());
1494+
Assert.assertTrue(res, "Row " + i + " (" + title.getText() + ")" + " equals no value: " + value);
1495+
}
1496+
}
1497+
}
1498+
1499+
/**
1500+
* Kiểm tra giá trị từng cột của table khi tìm kiếm theo điều kiện CHỨA (contains)
14671501
*
14681502
* @param column vị trí cột
14691503
* @param value giá trị cần so sánh
@@ -1472,7 +1506,6 @@ public static String getTagNameElement(By by) {
14721506
public static void checkContainsSearchTableByColumn(int column, String value) {
14731507
smartWait();
14741508
sleep(1);
1475-
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
14761509
List<WebElement> totalRows = getWebElements(By.xpath("//tbody/tr"));
14771510
Log.info("Number of results for keyword (" + value + "): " + totalRows.size());
14781511

@@ -1482,7 +1515,7 @@ public static void checkContainsSearchTableByColumn(int column, String value) {
14821515
for (int i = 1; i <= totalRows.size(); i++) {
14831516
boolean res = false;
14841517
WebElement title = waitForElementPresent(By.xpath("//tbody/tr[" + i + "]/td[" + column + "]"));
1485-
js.executeScript("arguments[0].scrollIntoView(true);", title);
1518+
WebUI.scrollToElement(title);
14861519
res = title.getText().toUpperCase().contains(value.toUpperCase());
14871520
Log.info("Row " + i + ": " + res + " - " + title.getText());
14881521
Assert.assertTrue(res, "Row " + i + " (" + title.getText() + ")" + " contains no value: " + value);
@@ -1502,7 +1535,6 @@ public static void checkContainsSearchTableByColumn(int column, String value, St
15021535
smartWait();
15031536

15041537
//xpathToTRtagname is locator from table to "tr" tagname of data section: //tbody/tr, //div[@id='example_wrapper']//tbody/tr, ...
1505-
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
15061538
List<WebElement> totalRows = DriverManager.getDriver().findElements(By.xpath(xpathToTRtagname));
15071539
sleep(1);
15081540
Log.info("Number of results for keyword (" + value + "): " + totalRows.size());
@@ -1513,7 +1545,7 @@ public static void checkContainsSearchTableByColumn(int column, String value, St
15131545
for (int i = 1; i <= totalRows.size(); i++) {
15141546
boolean res = false;
15151547
WebElement title = DriverManager.getDriver().findElement(By.xpath(xpathToTRtagname + "[" + i + "]/td[" + column + "]"));
1516-
js.executeScript("arguments[0].scrollIntoView(true);", title);
1548+
WebUI.scrollToElement(title);
15171549
res = title.getText().toUpperCase().contains(value.toUpperCase());
15181550
Log.info("Row " + i + ": " + res + " - " + title.getText());
15191551
Assert.assertTrue(res, "Row " + i + " (" + title.getText() + ")" + " contains no value " + value);
@@ -1588,8 +1620,8 @@ public static WebElement waitForElementVisible(By by, long timeOut) {
15881620
*/
15891621
public static WebElement waitForElementVisible(By by) {
15901622
smartWait();
1591-
15921623
waitForElementPresent(by);
1624+
15931625
try {
15941626
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(WAIT_EXPLICIT), Duration.ofMillis(500));
15951627
boolean check = verifyElementVisible(by);

src/test/java/anhtester/com/projects/website/crm/pages/Clients/ClientPage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public ClientPage() {
1818
public void openClientTabPage() {
1919
//Muốn chạy tiếp thì chọn FailureHandling.CONTINUE_ON_FAILURE
2020
WebUI.verifyElementTextEquals(ObjectUtils.getObject("labelOnClientPage"), pageText, FailureHandling.CONTINUE_ON_FAILURE);
21-
//WebUI.verifyPageUrl(pageUrl);
2221
WebUI.sleep(1);
2322
WebUI.clickElement(ObjectUtils.getObject("tabClient"));
2423
}

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

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

88
import anhtester.com.constants.FrameworkConstants;
99
import anhtester.com.helpers.*;
10-
import anhtester.com.helpers.PropertiesHelpers;
1110
import anhtester.com.utils.*;
1211
import org.testng.annotations.Test;
1312

@@ -74,7 +73,6 @@ public void testSplitString() {
7473
@Test
7574
public void testEncryptDecryptData() {
7675
String pass = "123456";
77-
7876
//Encrypt password
7977
WebUI.logConsole(DecodeUtils.encrypt(pass));
8078
//Decrypt password
@@ -83,7 +81,7 @@ public void testEncryptDecryptData() {
8381

8482
@Test
8583
public void testCreateFolder() {
86-
Helpers.CreateFolder("src/test/resources/TestCreateNewFolder");
84+
Helpers.createFolder("src/test/resources/TestCreateNewFolder");
8785
}
8886

8987
@Test
@@ -101,7 +99,6 @@ public void testPropertiesFile() {
10199
@Test
102100
public void testGetCurrentDateTime() {
103101
WebUI.logConsole(DateUtils.getCurrentDateTime());
104-
//Log.info(Helpers.CurrentDateTime());
105102
}
106103

107104
@Test
@@ -116,10 +113,10 @@ public void testReadAndWriteTxtFile() {
116113
@Test
117114
public void testExcelFile1() {
118115
PropertiesHelpers.loadAllFiles();
119-
WebUI.logConsole(Helpers.getCurrentDir() + PropertiesHelpers.getValue("excelClients"));
116+
WebUI.logConsole(Helpers.getCurrentDir() + PropertiesHelpers.getValue("excelDataFilePath"));
120117
// Handle Excel file
121118
ExcelHelpers excelHelpers = new ExcelHelpers();
122-
excelHelpers.setExcelFile(Helpers.getCurrentDir() + PropertiesHelpers.getValue("excelClients"), "SignInModel");
119+
excelHelpers.setExcelFile(Helpers.getCurrentDir() + PropertiesHelpers.getValue("excelDataFilePath"), "SignIn");
123120
WebUI.logConsole(excelHelpers.getCellData(1, "EMAIL"));
124121
WebUI.logConsole(excelHelpers.getCellData(1, "PASSWORD"));
125122
excelHelpers.setCellData("pass", 1, "EXPECTED_TITLE");
@@ -130,8 +127,6 @@ public void testExcelFile2() throws Exception {
130127
PropertiesHelpers.loadAllFiles();
131128
ExcelHelpers excelHelpers = new ExcelHelpers();
132129
WebUI.logConsole(excelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_PATH, "SignInModel", 1, 2));
133-
//WebUI.logConsole(ExcelHelpers.getDataReflection(Helpers.getCurrentDir() + "src/test/resources/testdatafile/ClientsDataExcel.xlsx", "SignInModel", 1, 2));
134-
135130
}
136131

137132
@Test

src/test/resources/config/config.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Copyright (c) 2022 Anh Tester
33
# Automation Framework Selenium
44
#
5-
# Data Test
6-
excelDataFilePath=src/test/resources/testdatafile/ClientsDataExcel.xlsx
75
# Config system
86
author=AnhTester
97
projectName=Automation Framework Selenium | Anh Tester

src/test/resources/config/datatest.properties

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# Copyright (c) 2022 Anh Tester
33
# Automation Framework Selenium
44
#
5-
6-
emailAdmin=admin02@mailinator.com
7-
emailTeamMember=tmb01@mailinator.com
8-
emailTeamLead=tld01@mailinator.com
95
password=T+wyT5u9cOelDJbBWNgxLw
106
txtFilePath=src/test/resources/testdatafile/TxtFileData.txt
11-
excelClients=src/test/resources/testdatafile/ClientsDataExcel.xlsx
7+
excelDataFilePath=src/test/resources/testdatafile/ClientsDataExcel.xlsx
-2.46 KB
Binary file not shown.

0 commit comments

Comments
 (0)