From 97a3e299560eab58ccff6df7f35a88c26ca911a9 Mon Sep 17 00:00:00 2001 From: Anh Tester Date: Mon, 24 Jun 2024 22:48:12 +0700 Subject: [PATCH] =?UTF-8?q?B=C3=A0i=2024=20-=20Parameter=20-=20Multi=20Bro?= =?UTF-8?q?wser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../testcases/CustomerTest.java | 6 +- .../DemoParameter.java | 28 +++++ .../DemoParameter2.java | 16 +++ .../pages/CommonPage.java | 43 +++++++ .../pages/CustomerPage.java | 119 ++++++++++++++++++ .../pages/DashboardPage.java | 59 +++++++++ .../pages/LoginPage.java | 68 ++++++++++ .../pages/ProjectPage.java | 37 ++++++ .../testcases/CustomerTest.java | 42 +++++++ .../testcases/DashboardTest.java | 34 +++++ .../testcases/LoginTest.java | 51 ++++++++ .../java/com/anhtester/common/BaseTest.java | 44 ++++++- suites/SuiteMultiBrowser.xml | 18 +++ suites/SuiteParameter.xml | 24 ++++ 14 files changed, 585 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter2.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CommonPage.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CustomerPage.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/DashboardPage.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/LoginPage.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/ProjectPage.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/CustomerTest.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/DashboardTest.java create mode 100644 src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/LoginTest.java create mode 100644 suites/SuiteMultiBrowser.xml create mode 100644 suites/SuiteParameter.xml diff --git a/src/test/java/com/anhtester/Bai22_23_VietHamChungWebUI/testcases/CustomerTest.java b/src/test/java/com/anhtester/Bai22_23_VietHamChungWebUI/testcases/CustomerTest.java index 716ffc7..ccf7709 100644 --- a/src/test/java/com/anhtester/Bai22_23_VietHamChungWebUI/testcases/CustomerTest.java +++ b/src/test/java/com/anhtester/Bai22_23_VietHamChungWebUI/testcases/CustomerTest.java @@ -6,6 +6,7 @@ import com.anhtester.Bai22_23_VietHamChungWebUI.pages.ProjectPage; import com.anhtester.common.BaseTest; import org.testng.Assert; +import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class CustomerTest extends BaseTest { @@ -16,9 +17,10 @@ public class CustomerTest extends BaseTest { ProjectPage projectPage; @Test - public void testAddNewCustomer() { + @Parameters({"customerName"}) + public void testAddNewCustomer(String customerName) { - String CUSTOMER_NAME = "Anh Tester 21062024A1"; + String CUSTOMER_NAME = customerName; loginPage = new LoginPage(driver); dashboardPage = loginPage.loginCRM("admin@example.com", "123456"); diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter.java new file mode 100644 index 0000000..8af98d2 --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter.java @@ -0,0 +1,28 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser; + +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class DemoParameter { + + @Test + @Parameters({"val1", "val2"}) + public void Sum(@Optional("20") int v1, @Optional("30") int v2) { + int finalSum = v1 + v2; + System.out.println("Kết quả là: " + finalSum); + } + + @Test + @Parameters({"url", "email", "password"}) + public void login(String v1, String v2, int v3) { + System.out.println("URL: " + v1); + System.out.println("Email: " + v2); + System.out.println("Password: " + v3); + } + +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter2.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter2.java new file mode 100644 index 0000000..22904a5 --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter2.java @@ -0,0 +1,16 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser; + +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class DemoParameter2 { + + @Test + @Parameters({"val1", "val2"}) + public void Sum(@Optional("20") int v1, @Optional("30") int v2) { + int finalSum = v1 - v2; + System.out.println("Kết quả là: " + finalSum); + } + +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CommonPage.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CommonPage.java new file mode 100644 index 0000000..4d91dfe --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CommonPage.java @@ -0,0 +1,43 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.pages; + +import com.anhtester.keywords.WebUI; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class CommonPage { + + private WebDriver driver; + + public CommonPage(WebDriver driver){ + this.driver = driver; + new WebUI(driver); + } + + public By menuDashboard = By.xpath("//span[normalize-space()='Dashboard']"); + public By menuCustomers = By.xpath("//span[normalize-space()='Customers']"); + public By menuSales = By.xpath("//li[@class='menu-item-sales']"); + public By menuProjects = By.xpath("//span[normalize-space()='Projects']"); + public By itemNotifications = By.xpath("//a[contains(@class,'notifications-icon')]"); + + public DashboardPage clickMenuDashboard(){ + WebUI.waitForPageLoaded(driver); + WebUI.clickElement(menuDashboard); + + return new DashboardPage(driver); + } + + public CustomerPage clickMenuCustomer(){ + WebUI.waitForPageLoaded(driver); + WebUI.clickElement(menuCustomers); + + return new CustomerPage(driver); + } + + public ProjectPage clickMenuProjects(){ + WebUI.waitForPageLoaded(driver); + WebUI.clickElement(menuProjects); + + return new ProjectPage(driver); + } + +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CustomerPage.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CustomerPage.java new file mode 100644 index 0000000..a3cb759 --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CustomerPage.java @@ -0,0 +1,119 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.pages; + +import com.anhtester.keywords.WebUI; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.testng.Assert; + +import static com.anhtester.keywords.WebUI.*; + +public class CustomerPage extends CommonPage { + private WebDriver driver; + + public CustomerPage(WebDriver driver) { + super(driver); + this.driver = driver; + new WebUI(driver); + } + + //Elements + private By buttonAddNewCustomer = By.xpath("//a[normalize-space()='New Customer']"); + private By headerPage = By.xpath("//span[normalize-space()='Customers Summary']"); + private By inputSearchCustomer = By.xpath("//div[@id='clients_filter']//input[@placeholder='Search...']"); + private By firstItemCustomerName = By.xpath("//tbody/tr[1]/td[3]/a"); + private By inputCompany = By.xpath("//input[@id='company']"); + private By inputVat = By.xpath("//input[@id='vat']"); + private By inputPhone = By.xpath("//input[@id='phonenumber']"); + private By inputWebsite = By.xpath("//input[@id='website']"); + private By selectGroups = By.xpath("//button[@data-id='groups_in[]']"); + private By inputGroups = By.xpath("//button[@data-id='groups_in[]']/following-sibling::div//input"); + private By selectLanguage = By.xpath("//button[@data-id='default_language']"); + private By itemVietnam = By.xpath("//span[normalize-space()='Vietnamese']"); + private By inputAddress = By.xpath("//textarea[@id='address']"); + private By inputCity = By.xpath("//input[@id='city']"); + private By inputState = By.xpath("//input[@id='state']"); + private By inputZip = By.xpath("//input[@id='zip']"); + private By selectCountry = By.xpath("//button[@data-id='country']"); + private By inputCountry = By.xpath("//button[@data-id='country']/following-sibling::div//input"); + private By buttonSave = By.xpath("//div[@id='profile-save-section']//button[normalize-space()='Save']"); + private By alertMessage = By.xpath("//span[@class='alert-title']"); + private By totalCustomers = By.xpath("//span[text()='Total Customers']/preceding-sibling::span"); + + //Hàm xử lý cho trang Customer + public void clickAddNewButton() { + clickElement(buttonAddNewCustomer); + } + + public String getTotalCustomers() { + waitForPageLoaded(driver); + return driver.findElement(totalCustomers).getText(); + } + + public void selectLanguage(String languageName) { + clickElement(selectLanguage); + clickElement(By.xpath("//span[normalize-space()='" + languageName + "']")); + } + + public void enterDataAddNewCustomer(String customerName) { + setText(inputCompany, customerName); + setText(inputVat, "10"); + setText(inputPhone, "123456"); + setText(inputWebsite, "https://anhtester.com"); + clickElement(selectGroups); + sleep(1); + setText(inputGroups, "VIP"); + sleep(1); + setKey(inputGroups, Keys.ENTER); + sleep(1); + clickElement(selectGroups); + selectLanguage("Vietnamese"); + sleep(1); + + setText(inputAddress, "Can Tho"); + setText(inputCity, "Can Tho"); + setText(inputState, "Can Tho"); + setText(inputZip, "12345"); + + clickElement(selectCountry); + sleep(1); + setText(inputCountry, "Vietnam"); + sleep(1); + setKey(selectCountry, Keys.ENTER); + sleep(1); + clickElement(buttonSave); + sleep(2); + Assert.assertTrue(checkElementExist(driver, alertMessage), "\uD83D\uDC1E FAIL!! The alert message success not display."); + Assert.assertEquals(driver.findElement(alertMessage).getText().trim(), "Customer added successfully.", "\uD83D\uDC1E FAIL!! The content of alert message not match."); + } + + public void checkCustomerInTableList(String customerName) { + waitForPageLoaded(driver); + clickElement(menuCustomers); + waitForPageLoaded(driver); + setText(inputSearchCustomer, customerName); + waitForPageLoaded(driver); + sleep(2); + + //Check customer name display in table + Assert.assertTrue(checkElementExist(driver, firstItemCustomerName), "\uD83D\uDC1E FAIL!! The customer name not display in table."); + //Assert.assertEquals(driver.findElement(firstItemCustomerName).getText(), customerName, "\uD83D\uDC1E FAILL!! The customer name not match."); + + assertEquals(getElementText(firstItemCustomerName), customerName, "\uD83D\uDC1E FAIL!! The customer name not match."); + + } + + public void checkCustomerDetail(String customerName) { + //Check cutsomer detail in Customer Detail page + waitForPageLoaded(driver); + clickElement(firstItemCustomerName); + waitForPageLoaded(driver); + assertEquals(getElementAttribute(inputCompany, "value"), customerName, "FAIL!! The Company name not match."); + assertEquals(getElementAttribute(inputVat, "value"), "10", "FAIL!! The VAT value not match."); + assertEquals(getElementAttribute(inputPhone, "value"), "123456", "FAIL!! The Phone value not match."); + assertEquals(getElementAttribute(inputWebsite, "value"), "https://anhtester.com", "FAIL!! The Website value not match."); + assertEquals(getElementAttribute(selectGroups, "title"), "VIP", "FAIL!! The Group of customer not match."); + assertEquals(getElementAttribute(selectLanguage, "title"), "Vietnamese", "FAIL!! The Language value not match."); + assertEquals(getElementAttribute(inputAddress, "value"), "Can Tho", "FAIL!! The Address value not match."); + } +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/DashboardPage.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/DashboardPage.java new file mode 100644 index 0000000..efa4e3c --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/DashboardPage.java @@ -0,0 +1,59 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.pages; + +import com.anhtester.keywords.WebUI; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.testng.Assert; + +public class DashboardPage extends CommonPage { + private WebDriver driver; + + public DashboardPage(WebDriver driver) { + super(driver); + this.driver = driver; + } + + private By buttonDashboardOptions = By.xpath("//div[normalize-space()='Dashboard Options']"); + private By totalInvoicesAwaitingPayment = By.xpath("(//span[normalize-space()='Invoices Awaiting Payment']/parent::div)/following-sibling::span"); + private By totalConvertedLeads = By.xpath("(//span[normalize-space()='Converted Leads']/parent::div)/following-sibling::span"); + private By totalProjectsInProgress = By.xpath("(//span[normalize-space()='Projects In Progress']/parent::div)/following-sibling::span"); + private By totalTasksNotFinished = By.xpath("(//span[normalize-space()='Tasks Not Finished']/parent::div)/following-sibling::span"); + private By checkboxQuickStatistics = By.xpath("//input[@id='widget_option_top_stats']"); + private By sectionQuickStatistics = By.xpath("//div[@id='widget-top_stats']"); + + public void clickButtonDashboardOptions(){ + WebUI.waitForPageLoaded(driver); + System.out.println(WebUI.checkElementExist(driver, buttonDashboardOptions)); + driver.findElement(buttonDashboardOptions).click(); + } + + public void verifyCheckboxQuickStatistics(){ + WebUI.sleep(1); + Assert.assertTrue(driver.findElement(checkboxQuickStatistics).isSelected(), "FAIL!! The value of checkbox Quick Statistics not match."); + Assert.assertTrue(driver.findElement(sectionQuickStatistics).isDisplayed(), "FAI!! The section Quick Statistics not display."); + } + + public void checkTotalInvoicesAwaitingPayment(String value) { + WebUI.waitForPageLoaded(driver); + Assert.assertTrue(WebUI.checkElementExist(driver, totalInvoicesAwaitingPayment), "The section Invoices Awaiting Payment not display."); + Assert.assertEquals(driver.findElement(totalInvoicesAwaitingPayment).getText(), value, "FAIL!! Invoices Awaiting Payment total not match."); + } + + public void checkTotalConvertedLeads() { + WebUI.waitForPageLoaded(driver); + Assert.assertTrue(WebUI.checkElementExist(driver, totalConvertedLeads), "The section Converted Leads not display."); + Assert.assertEquals(driver.findElement(totalConvertedLeads).getText(), "1 / 5", "FAIL!! Converted Leads total not match."); + } + + public void checkTotalProjectsInProgress() { + WebUI.waitForPageLoaded(driver); + Assert.assertTrue(WebUI.checkElementExist(driver, totalProjectsInProgress), "The section Projects In Progress not display."); + Assert.assertEquals(driver.findElement(totalProjectsInProgress).getText(), "4 / 4", "FAIL!! Projects In Progress total not match."); + } + + public void checkTotalTasksNotFinished() { + WebUI.waitForPageLoaded(driver); + Assert.assertTrue(WebUI.checkElementExist(driver, totalTasksNotFinished), "The section Tasks Not Finished not display."); + Assert.assertEquals(driver.findElement(totalTasksNotFinished).getText(), "8 / 8", "FAIL!! Tasks Not Finished total not match."); + } +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/LoginPage.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/LoginPage.java new file mode 100644 index 0000000..8286aa4 --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/LoginPage.java @@ -0,0 +1,68 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.pages; + +import com.anhtester.constants.ConfigData; +import com.anhtester.keywords.WebUI; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.testng.Assert; + +public class LoginPage extends CommonPage { + //Khai báo driver cục bộ + private WebDriver driver; + private String URL = "https://crm.anhtester.com/admin/authentication"; + + //Hàm xây dựng cho từng class Page + public LoginPage(WebDriver driver) { + super(driver); + this.driver = driver; + new WebUI(driver); //Khởi tạo class WebUI để truyền giá trị driver + } + + //Khai báo các element dạng đối tượng By + private By headerPage = By.xpath("//h1[normalize-space()='Login']"); + private By inputEmail = By.xpath("//input[@id='email']"); + private By inputPassword = By.xpath("//input[@id='password']"); + private By buttonLogin = By.xpath("//button[normalize-space()='Login']"); + private By errorMessage = By.xpath("//div[contains(@class,'alert alert-danger')]"); + + private By menuDashboard = By.xpath("//span[normalize-space()='Dashboard']"); + + //Khai báo các hàm xử lý thuộc trang Login + public void enterEmail(String email){ + //driver.findElement(inputEmail).sendKeys(email); + WebUI.setText(inputEmail, email); + } + + public void enterPassword(String password){ + //driver.findElement(inputPassword).sendKeys(password); + WebUI.setText(inputPassword, password); + } + + public void clickLoginButton(){ + //driver.findElement(buttonLogin).click(); + WebUI.clickElement(buttonLogin); + } + + public DashboardPage loginCRM(String email, String password) { + //driver.get(ConfigData.URL); + WebUI.openURL(ConfigData.URL); + WebUI.waitForPageLoaded(); + enterEmail(email); + enterPassword(password); + clickLoginButton(); + + return new DashboardPage(driver); + } + + public void verifyLoginSuccess() { + WebUI.waitForPageLoaded(); + Assert.assertTrue(WebUI.checkElementExist(menuDashboard), "\uD83D\uDC1E FAIL!! Can not redirect to Dashboard page."); + Assert.assertEquals(driver.getCurrentUrl(), "https://crm.anhtester.com/admin/", "\uD83D\uDC1E FAIL!! The current url not match."); + } + + public void verifyLoginFail(String expectedMessage) { + WebUI.waitForPageLoaded(); + Assert.assertTrue(WebUI.checkElementExist(errorMessage), "\uD83D\uDC1E FAIL!! The error message not display."); + Assert.assertEquals(WebUI.getElementText(errorMessage), expectedMessage, "\uD83D\uDC1E FAIL!! The content of error massge not match."); + } +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/ProjectPage.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/ProjectPage.java new file mode 100644 index 0000000..286c98a --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/ProjectPage.java @@ -0,0 +1,37 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.pages; + +import com.anhtester.keywords.WebUI; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.testng.Assert; + +public class ProjectPage extends CommonPage { + private WebDriver driver; + + public ProjectPage(WebDriver driver) { + super(driver); + this.driver = driver; + } + + private By headerPage = By.xpath("//span[normalize-space()='Projects Summary']"); + private By buttonAddNewProject = By.xpath("//a[normalize-space()='New Project']"); + private By selectCustomer = By.xpath("//button[@data-id='clientid']"); + private By inputSearchCustomer = By.xpath("//button[@data-id='clientid']/following-sibling::div//input"); + private By itemCustomerName = By.xpath("//span[@class='text']"); + + public void clickAddNewProject() { + WebUI.waitForPageLoaded(driver); + WebUI.clickElement(buttonAddNewProject); + } + + public void checkCustomerDisplayInSelectSection(String customerName) { + WebUI.waitForPageLoaded(driver); + WebUI.clickElement(selectCustomer); + WebUI.sleep(1); + WebUI.setText(inputSearchCustomer, customerName); + WebUI.sleep(1); + String itemCustomer = driver.findElement(itemCustomerName).getText(); + System.out.println("Customer in Select: " + itemCustomer); + Assert.assertEquals(itemCustomer, customerName, "FAIL!! The Customer not display in Project."); + } +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/CustomerTest.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/CustomerTest.java new file mode 100644 index 0000000..43a19a0 --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/CustomerTest.java @@ -0,0 +1,42 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.testcases; + +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.CustomerPage; +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.DashboardPage; +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.LoginPage; +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.ProjectPage; +import com.anhtester.common.BaseTest; +import org.testng.Assert; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class CustomerTest extends BaseTest { + + LoginPage loginPage; + DashboardPage dashboardPage; + CustomerPage customerPage; + ProjectPage projectPage; + + @Test + @Parameters({"customerName"}) + public void testAddNewCustomer(String customerName) { + + String CUSTOMER_NAME = customerName; + + loginPage = new LoginPage(driver); + dashboardPage = loginPage.loginCRM("admin@example.com", "123456"); + + customerPage = dashboardPage.clickMenuCustomer(); //Hàm này nằm bên CommonPage + + int totalCustomersBefore = Integer.parseInt(customerPage.getTotalCustomers()); + System.out.println("\uD83C\uDF40 Total Customers Before: " + totalCustomersBefore); + customerPage.clickAddNewButton(); + customerPage.enterDataAddNewCustomer(CUSTOMER_NAME); + customerPage.checkCustomerInTableList(CUSTOMER_NAME); + System.out.println("\uD83C\uDF40 Total Customers After: " + customerPage.getTotalCustomers()); + Assert.assertEquals(customerPage.getTotalCustomers(), String.valueOf(totalCustomersBefore + 1), "FAIL!! The Total Customers in Customer Page not match."); + customerPage.checkCustomerDetail(CUSTOMER_NAME); + projectPage = customerPage.clickMenuProjects(); + projectPage.clickAddNewProject(); + projectPage.checkCustomerDisplayInSelectSection(CUSTOMER_NAME); + } +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/DashboardTest.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/DashboardTest.java new file mode 100644 index 0000000..26e74eb --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/DashboardTest.java @@ -0,0 +1,34 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.testcases; + +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.DashboardPage; +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.LoginPage; +import com.anhtester.common.BaseTest; +import org.testng.annotations.Test; + +public class DashboardTest extends BaseTest { + + LoginPage loginPage; + DashboardPage dashboardPage; + + @Test(priority = 1) + public void testCheckSectionQuickStatisticsDisplay(){ + loginPage = new LoginPage(driver); + dashboardPage = loginPage.loginCRM("admin@example.com", "123456"); + + //dashboardPage = new DashboardPage(driver); + dashboardPage.clickButtonDashboardOptions(); + dashboardPage.verifyCheckboxQuickStatistics(); + } + + @Test(priority = 2) + public void testCheckTotalSectionQuickStatistics(){ + loginPage = new LoginPage(driver); + dashboardPage = loginPage.loginCRM("admin@example.com", "123456"); + + //dashboardPage = new DashboardPage(driver); + dashboardPage.checkTotalInvoicesAwaitingPayment("3 / 3"); + dashboardPage.checkTotalConvertedLeads(); + dashboardPage.checkTotalProjectsInProgress(); + dashboardPage.checkTotalTasksNotFinished(); + } +} diff --git a/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/LoginTest.java b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/LoginTest.java new file mode 100644 index 0000000..942f885 --- /dev/null +++ b/src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/testcases/LoginTest.java @@ -0,0 +1,51 @@ +package com.anhtester.Bai24_Parameter_MultiBrowser.testcases; + +import com.anhtester.Bai24_Parameter_MultiBrowser.pages.LoginPage; +import com.anhtester.common.BaseTest; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class LoginTest extends BaseTest { + + private LoginPage loginPage; + + @Test + public void testLoginSuccess(){ + loginPage = new LoginPage(driver); + + loginPage.loginCRM("admin@example.com", "123456"); + loginPage.verifyLoginSuccess(); + } + + @Test + public void testLoginFailWithEmailInvalid(){ + loginPage = new LoginPage(driver); + + loginPage.loginCRM("admin123@example.com", "123456"); + loginPage.verifyLoginFail("Invalid email or password"); + } + + @Test + public void testLoginFailWithPasswordInvalid(){ + loginPage = new LoginPage(driver); + + loginPage.loginCRM("admin@example.com", "123"); + loginPage.verifyLoginFail("Invalid email or password"); + } + + @Test + public void testLoginFailWithEmailNull(){ + loginPage = new LoginPage(driver); + + loginPage.loginCRM("", "123"); + loginPage.verifyLoginFail("The Email Address field is required."); + } + + @Test + public void testLoginFailWithPasswordNull(){ + loginPage = new LoginPage(driver); + + loginPage.loginCRM("admin@example.com", ""); + loginPage.verifyLoginFail("The Password field is required."); + } +} diff --git a/src/test/java/com/anhtester/common/BaseTest.java b/src/test/java/com/anhtester/common/BaseTest.java index 866fb0b..6dedcab 100644 --- a/src/test/java/com/anhtester/common/BaseTest.java +++ b/src/test/java/com/anhtester/common/BaseTest.java @@ -3,6 +3,8 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chromium.ChromiumDriver; +import org.openqa.selenium.edge.EdgeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.*; import java.time.Duration; @@ -11,10 +13,48 @@ public class BaseTest { public WebDriver driver; @BeforeMethod - public void createDriver(){ + @Parameters({"browser"}) + public void createDriver(@Optional("firefox") String browser) { + setupDriver(browser); + } + + public WebDriver setupDriver(String browserName) { + switch (browserName.trim().toLowerCase()) { + case "chrome": + driver = initChromeDriver(); + break; + case "firefox": + driver = initFirefoxDriver(); + break; + case "edge": + driver = initEdgeDriver(); + break; + default: + System.out.println("Browser: " + browserName + " is invalid, Launching Chrome as browser of choice..."); + driver = initChromeDriver(); + } + return driver; + } + + private WebDriver initChromeDriver() { + System.out.println("Launching Chrome browser..."); driver = new ChromeDriver(); - driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(40)); driver.manage().window().maximize(); + return driver; + } + + private WebDriver initEdgeDriver() { + System.out.println("Launching Edge browser..."); + driver = new EdgeDriver(); + driver.manage().window().maximize(); + return driver; + } + + private WebDriver initFirefoxDriver() { + System.out.println("Launching Firefox browser..."); + driver = new FirefoxDriver(); + driver.manage().window().maximize(); + return driver; } @AfterMethod diff --git a/suites/SuiteMultiBrowser.xml b/suites/SuiteMultiBrowser.xml new file mode 100644 index 0000000..5b99975 --- /dev/null +++ b/suites/SuiteMultiBrowser.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/suites/SuiteParameter.xml b/suites/SuiteParameter.xml new file mode 100644 index 0000000..bbad3df --- /dev/null +++ b/suites/SuiteParameter.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file