-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
585 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/DemoParameter2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CommonPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
119 changes: 119 additions & 0 deletions
119
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/CustomerPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/DashboardPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/LoginPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/com/anhtester/Bai24_Parameter_MultiBrowser/pages/ProjectPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} |
Oops, something went wrong.