Commit 88cc0dbe authored by Trình Nguyễn's avatar Trình Nguyễn

up2

parent 631656f9
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -24,4 +24,5 @@ public class DriverManager {
}
}
}
......@@ -6,6 +6,8 @@ import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import trinhQC.com.drivers.DriverManager;
import trinhQC.com.reports.AllureReportManager;
import trinhQC.com.reports.ExtentReportTestManager;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
......@@ -15,6 +17,7 @@ import java.time.Duration;
import java.util.List;
public class Key {
private static int EXPLICIT_WAIT_TIMEOUT = 10;
private static int WAIT_PAGE_LEADED_TIMEOUT = 30;
......@@ -44,6 +47,19 @@ public class Key {
}
return getWebElement(by);
}
//ham clear data input
public static void clearInputField(By by) {
try {
WebElement input = DriverManager.getDriver().findElement(by);
input.click(); // focus vào ô
input.sendKeys(Keys.chord(Keys.CONTROL, "a")); // select all
input.sendKeys(Keys.DELETE); // delete
} catch (Exception e) {
System.out.println("❌ Không thể xóa dữ liệu trong ô input: " + e.getMessage());
}
}
public static void clickElementWithJS(By by) {
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
......@@ -206,24 +222,24 @@ public class Key {
}
// public static void verifyElementText(By by, String textValue, String message){
// waitForPageLoaded();
// waitForElementVisible(by);
// sleep(5);
// Log.info("ACTUAL RESULT: Text of the element is: " + getWebElement(by).getText().trim());
// ExtentReportTestManager.logMessage(Status.PASS, "ACTUAL RESULT: Text of the element is: " + getWebElement(by).getText().trim());
// AllureReportManager.saveTextLog("ACTUAL RESULT: Text of the element is: " + getWebElement(by).getText().trim());
// Log.info("EXPECTED RESULT Text is: " + textValue.trim());
// ExtentReportTestManager.logMessage(Status.PASS, "EXPECTED RESULT Text is: " + textValue.trim());
// AllureReportManager.saveTextLog("EXPECTED RESULT Text is: " + textValue.trim());
// boolean expected = getWebElement(by).getText().trim().equals(textValue.trim());
// if(expected){
// ExtentReportTestManager.logMessage(Status.PASS, "ACTUAL RESULT the same as EXPECTED RESULT");
// }else {
// ExtentReportTestManager.logMessage(Status.FAIL, "ACTUAL RESULT not the same as EXPECTED RESULT");
// }
// Assert.assertTrue(expected,message);
// }
public static void verifyElementText(By by, String textValue, String message){
waitForPageLoaded();
waitForElementVisible(by);
sleep(5);
Log.info("ACTUAL RESULT: Text of the element is: " + getWebElement(by).getText().trim());
ExtentReportTestManager.logMessage(Status.PASS, "ACTUAL RESULT: Text of the element is: " + getWebElement(by).getText().trim());
AllureReportManager.saveTextLog("ACTUAL RESULT: Text of the element is: " + getWebElement(by).getText().trim());
Log.info("EXPECTED RESULT Text is: " + textValue.trim());
ExtentReportTestManager.logMessage(Status.PASS, "EXPECTED RESULT Text is: " + textValue.trim());
AllureReportManager.saveTextLog("EXPECTED RESULT Text is: " + textValue.trim());
boolean expected = getWebElement(by).getText().trim().equals(textValue.trim());
if(expected){
ExtentReportTestManager.logMessage(Status.PASS, "ACTUAL RESULT the same as EXPECTED RESULT");
}else {
ExtentReportTestManager.logMessage(Status.FAIL, "ACTUAL RESULT not the same as EXPECTED RESULT");
}
Assert.assertTrue(expected,message);
}
public static boolean verifyElementVisible(By by, int second) {
......@@ -312,7 +328,26 @@ public class Key {
Select dropdown = new Select(dropdownElement);
dropdown.selectByVisibleText(visibleText);
}
//verify trong bảng có giá trị
public void verifyTyGiaLuongColumn(WebDriver driver, List<String> expectedValues) {
// Lấy tất cả hàng trong bảng (bỏ dòng header)
List<WebElement> rows = driver.findElements(By.xpath("//table//tbody//tr"));
// Vị trí cột "Tỷ giá lương" (ví dụ là cột thứ 6 - chỉnh lại nếu sai)
int tyGiaLuongColIndex = 6;
// So sánh từng dòng
for (int i = 0; i < rows.size(); i++) {
WebElement cell = rows.get(i).findElement(By.xpath(".//td[" + tyGiaLuongColIndex + "]"));
String actualValue = cell.getText().trim();
if (!expectedValues.contains(actualValue)) {
throw new AssertionError("Dòng " + (i+1) + " có giá trị 'Tỷ giá lương' sai: " + actualValue);
}
}
System.out.println("✅ Cột 'Tỷ giá lương' đã được verify thành công!");
}
// search 1 text
public static void verifyTextInTable(String expectText) {
// lất tất cả cell trong bảng
......@@ -349,6 +384,39 @@ public class Key {
return false;
}
}
// hàm cuộng thanh kéo ngang trong bảng
public static void scrollToHorizontalPosition(int xPixels) {
WebDriver driver = DriverManager.getDriver();
// Tìm phần tử thanh cuộn ngang (phần chứa scroll)
WebElement scrollableDiv = driver.findElement(By.xpath("//div[contains(@class,'scrollbar') and contains(@class,'overflow-auto')]"));
// Dùng Javascript để scroll ngang
((JavascriptExecutor) driver).executeScript("arguments[0].scrollLeft = arguments[1];", scrollableDiv, xPixels);
}
// check giá trị trong bảng đã thỏa mãn expect chưa
public static void verifyTyGiaLuongUpdated(String expectedValue) {
// 1. Cuộn ngang tới cột "Tỷ giá lương" nếu cần
WebElement scrollBar = DriverManager.getDriver().findElement(By.xpath("//div[contains(@class,'scrollbar') and contains(@class,'overflow-auto')]"));
((JavascriptExecutor) DriverManager.getDriver()).executeScript("arguments[0].scrollLeft = arguments[1];", scrollBar, 3000); // Đảm bảo scroll đủ
// 2. Đợi cột xuất hiện
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(),'Tỷ giá lương')]")));
// 3. Lấy giá trị ô đầu tiên trong cột "Tỷ giá lương"
WebElement firstCell = DriverManager.getDriver().findElement(
By.xpath("//tbody/tr[2]/td[29]")
);
String actualValue = firstCell.getText().trim();
// 4. So sánh với giá trị mong muốn
Assert.assertEquals(actualValue, expectedValue, "❌ Giá trị không khớp ở cột 'Tỷ giá lương'!");
System.out.println("✅ Tỷ giá lương đã được cập nhật đúng.");
}
......
......@@ -18,9 +18,9 @@ public class NgiepVuKhachhangPage {
// Tạo nhom
By clickOnTaoNhomButton = By.xpath("//span[contains(text(),'Tạo nhóm')]");
By inputTennhomBox = By.xpath("//input[@placeholder='Nhập thông tin']");
By clickOnMSTDropdown = By.xpath("//button[@id='_r_71_-form-item']");
By clickOnMSTDropdown = By.xpath("//button[@id='r_ha-form-item' and @type='button']");
By selectMstFirst = By.xpath("//div[@role='option'])[1]");
By clickOnBhxhDropdown = By.xpath("//label[normalize-space()='Mã BHXH']/following-sibling::div//button");
By clickOnBhxhDropdown = By.xpath("//button[@id='_r_hc_-form-item']//span[1]");
By selectOnBhxhFirst = By.xpath("//div[@role='option'])[1]");
By clickOnNhanSuDropdown = By.xpath("//label[normalize-space()='Nhân sự']/following-sibling::div//button");
By clickOnLuuButton = By.xpath("//button[text()='Lưu']");
......@@ -29,13 +29,58 @@ public class NgiepVuKhachhangPage {
By clickOnDenBangLuongOption =
By.xpath("//span[contains(text(),'Đến bảng lương')]");
By clickOnTygia =
By.xpath("//button[@aria-describedby='radix-_r_9p_']");
By.xpath("/html/body/div[1]/div/div/div[2]/div[2]/div[1]/div/div/div[2]/button");
By inputTygia =
By.xpath("//input[@id='_r_9q_.form-item']");
By.xpath("//input[@placeholder='Nhập giá trị']");
By clickOnApDungbtn =
By.xpath("//button[contains(text(),'Áp dụng')]");
// Mở nhóm trong bảng lương
By cliclOpengr =
By.xpath("//div[@class='typography-h4 text-secondary-foreground']");
By scrollTotyGiaCol=
By.xpath("//div[@id='root']//div[4]");
// Tick checkbox nhóm
By tickOnChekcbox = By.xpath("(//tbody//button[@role='checkbox' and @data-slot='checkbox'])[1]");
// Chọn Giấy báo xuất
By clickOnGB= By.xpath("//button[normalize-space(.)='Xuất biểu mẫu GB thanh toán & kê khai']");
By selectGBChinh = By.xpath("//span[contains(text(),'Giấy báo chính')]");
// hàm tìm kiếm từ khóa
//Form tạo Giấy báo chính
By clickOnTiepButton = By.xpath("//button[contains(text(),'Tiếp')]");
By clickOnGuiRqButton = By.xpath("//button[contains(text(),'Gửi yêu cầu chốt')]");
// Danh Sách biê mẫu
By clickOnBieuMauLink= By.xpath("//a[normalize-space(.)='Danh sách GB & biểu mẫu']");
By selectGb1= By.xpath("(//tbody/tr)[1]//button[@aria-haspopup='menu']");
// Verify tạo thành cong gb
By textThanhCong = By.xpath("(//*[contains(normalize-space(.),'Thành công') and contains(normalize-space(.),'Gửi yêu cầu chốt thành công')])[last()]");
// thêm cột động
By clickOnThemCotButton = By.xpath("//span[contains(test(),'Thêm cột')]");
By inputTenColVN = By.xpath("//input[@placeholder='Nhập thông tin']");
By inputTenColEn = By.xpath("//input[@name='EN_NAME']");
By tickCheckboxNhansu = By.xpath("//tbody/tr[1]/td[1]/div[1]/div[1]/button[1]");
By clickOnDropCongthuc = By.xpath("//label[contains(normalize-space(.),'Công thức')]/following::button[@role='combobox'][1]");
By selectonCongthuc = By.xpath("//div[@id='radix-_r_cn_']");
// có tính lương net
By tickCBLuongNet = By.xpath("//label[contains(normalize-space(.),'Tính vào cột “Lương Net”')]/preceding-sibling::input[@type='checkbox']");
By clickOnLuu = By.xpath("//button[contains(text(),'Lưu')]");
// hàm tìm kiếm từ khóa
public void SearchForKeyword (String name){
Key.clickElement(hoverOnNVitem);
Key.clickElement(clickOnKHitem);
......@@ -70,7 +115,8 @@ public class NgiepVuKhachhangPage {
Key.clickElement(clickOnTaoNhomButton);
Key.setText(inputTennhomBox,"nhóm test auto");
Key.clickElement(clickOnMSTDropdown);
Key.sleep(1.5);
Key.waitForElementVisible(clickOnMSTDropdown);
// Key.sleep(1.5);
Key.clickElement(selectMstFirst);
Key.clickElement(clickOnBhxhDropdown);
Key.clickElement(selectOnBhxhFirst);
......@@ -89,14 +135,35 @@ public class NgiepVuKhachhangPage {
public void changeValue (String tygia){
setUpBangLuong();
Key.clickElement(clickOnTygia);
Key.waitForElementVisible(inputTygia);
Key.clickElement(inputTygia);
Key.clearInputField(inputTygia);
Key.setText(inputTygia,tygia);
Key.clickElement(clickOnApDungbtn);
//Verify change tỷ giá
Key.scrollToElementWithJS(scrollToFooter);
Key.sleep(1.5);
Key.clickElement(cliclOpengr);
Key.sleep(1.5);
Key.scrollToElementWithJS(scrollTotyGiaCol);
Key.sleep(1.5);
Key.verifyTyGiaLuongUpdated("25.000");
}
//Verify change tỷ giá
public void taoGbMain (){
setUpBangLuong();
Key.clickElement(tickOnChekcbox);
Key.clickElement(clickOnGB);
Key.waitForElementVisible(selectGBChinh);
Key.clickElement(selectGBChinh);
Key.clickElement(clickOnTiepButton);
Key.clickElement(clickOnGuiRqButton);
Key.clickElement(clickOnBieuMauLink);
public void verifyChangeValuesuccess(){
}
//Verify tạo gbc thanh cong
}
}
......@@ -37,9 +37,6 @@ public class NghiepvuKhachHangTest extends BaseTest {
@Test(priority = 2)
public void createGroupPass(){
//1.login
// loginPage = new LoginPage();
// nghiepVuKhachHang = new NgiepVuKhachhangPage();
loginPage.loginSuccess(
PropertiesHelper.getValue("username"),
PropertiesHelper.getValue("password")
......@@ -58,10 +55,18 @@ public class NghiepvuKhachHangTest extends BaseTest {
nghiepVuKhachHang.changeValue(
PropertiesHelper.getValue("tygia")
);
nghiepVuKhachHang.verifyChangeValuesuccess();
}
@Test(priority = 4)
public void checkCreateGBCSuccess(){
loginPage.loginSuccess(
PropertiesHelper.getValue("username"),
PropertiesHelper.getValue("password")
);
nghiepVuKhachHang.taoGbMain();
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment