Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bai19 #73

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,11 @@
<version>5.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.0</version>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions src/main/java/com/utils/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public void preCondition() {
public void postCondition(){
// Quit the Browser
driver.quit();

}
}
45 changes: 45 additions & 0 deletions src/test/java/com/BookingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.utils.Utils;

import com.utils.BasicTest;

public class BookingTest extends BasicTest {
// Booking thành công - khi giỏ hàng = 0
@Test(priority = 1)
public void BookingSuccess() throws Exception {
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
WebElement emailInput = driver.findElement(By.xpath("//input[@id='username']"));
emailInput.sendKeys("trongtuyen451@gmail.com");
WebElement passInput = driver.findElement(By.xpath("//input[@id='password']"));
passInput.sendKeys("Admin@123456");
WebElement loginBtn = driver.findElement(By.xpath("//button[@name='login']"));
loginBtn.click();
Utils.hardWait();
WebElement seachBox = driver.findElement(By.xpath("//input[@placeholder='Tìm kiếm...'][1]"));
seachBox.sendKeys("Mercedes");
Utils.hardWait();
WebElement optionFirts = driver.findElement(By.xpath("//a[text()='Bơm nước xe ']"));
optionFirts.click();
WebElement selectOption = driver.findElement(By.xpath("//select[@id='pa_xuat-xu']/option[@value='germany']"));
selectOption.click();
WebElement btnPlus = driver.findElement(By.xpath("//button[@class='plus']"));
btnPlus.click();
WebElement btnAdd = driver.findElement(By.xpath("//button[contains(@class,'single_add_to_cart_button')]"));
btnAdd.click();
String urlCard = "https://bantheme.xyz/hathanhauto/gio-hang/";
Assert.assertEquals(driver.getCurrentUrl(), urlCard);
WebElement iconCard = driver.findElement(By.xpath("//div[@class='d-table-cell link-cart']//a/b[text()='2']"));
Assert.assertTrue(iconCard.isDisplayed());
}
}
100 changes: 100 additions & 0 deletions src/test/java/com/LoginIceHrmTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.utils.BasicTest;
import com.utils.Utils;

public class LoginIceHrmTest extends BasicTest {
@DataProvider(name = "loginTestData")
public Object[][] testDataFeed() {
Object[][] testdata = new Object[3][3];
// true admin
testdata[0][0] = "admin";
testdata[0][1] = "admin";
testdata[0][2] = false;
// true manager
testdata[1][0] = "manager";
testdata[1][1] = "demouserpwd";
testdata[1][2] = false;
// true user 1
testdata[2][0] = "user1";
testdata[2][1] = "demouserpwd";
testdata[2][2] = false;

return testdata;
}
@DataProvider(name = "loginTestDataFalse")
public Object[][] testDataFeedFalse() {
Object[][] testdata = new Object[3][3];

// false Admin
testdata[0][0] = "admin";
testdata[0][1] = "1234567";
testdata[0][2] = true;
// false manager
testdata[1][0] = "manager";
testdata[1][1] = "1234567";
testdata[1][2] = true;
// false user
testdata[2][0] = "user1";
testdata[2][1] = "1234567";
testdata[2][2] = true;

return testdata;
}
public boolean isMessgageDisplayed() {
try {
WebElement messageError = driver.findElement(By.xpath("//div[@class='alert alert-danger']"));
return true;
} catch (Exception e) {
return false;
}
}
@Test(dataProvider = "loginTestData")
public void loginTestSuccess(String uname, String pw, boolean expectedMesageErrorDisplay) throws Exception {
String url = "https://icehrm-open.gamonoid.com/login.php";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
Utils.hardWait(1000);

WebElement emailInput = driver.findElement(By.xpath("//input[@id='username']"));
emailInput.sendKeys(uname);
Utils.hardWait(1000);
WebElement passInput = driver.findElement(By.xpath("//input[@id='password']"));
passInput.sendKeys(pw);
Utils.hardWait(1000);

WebElement loginBtn = driver.findElement(By.xpath("//button[@class='btn btn-info btn-medium w-100 text-uppercase'][1]"));
// WebElement loginButton = driver.findElement(By.xpath("//button[contains(text(),'Log in')]"));
loginBtn.click();
Utils.hardWait(1000);
// boolean MessgageDisplayed = isMessgageDisplayed();
Assert.assertEquals(isMessgageDisplayed(), expectedMesageErrorDisplay);
}
@Test(dataProvider = "loginTestDataFalse")
public void loginTestFalse(String unamefalse, String pwfalse, boolean expectedMesageErrorDisplay) throws Exception {
String url = "https://icehrm-open.gamonoid.com/login.php";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
Utils.hardWait(1000);

WebElement emailInput = driver.findElement(By.xpath("//input[@id='username']"));
emailInput.sendKeys(unamefalse);
Utils.hardWait(1000);
WebElement passInput = driver.findElement(By.xpath("//input[@id='password']"));
passInput.sendKeys(pwfalse);
Utils.hardWait(1000);

WebElement loginBtn = driver.findElement(By.xpath("//button[@class='btn btn-info btn-medium w-100 text-uppercase'][1]"));
// WebElement loginButton = driver.findElement(By.xpath("//button[contains(text(),'Log in')]"));
loginBtn.click();
Utils.hardWait(1000);
// boolean MessgageDisplayed = isMessgageDisplayed();
Assert.assertEquals(isMessgageDisplayed(), expectedMesageErrorDisplay);
}
}
102 changes: 98 additions & 4 deletions src/test/java/com/LoginTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,113 @@
package com;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.utils.BasicTest;
import com.utils.Utils;

public class LoginTest extends BasicTest {
@DataProvider(name = "loginTestData")
public Object[][] testDataFeed() {
Object[][] testdata = new Object[1][3];

testdata[0][0] = "trongtuyen451@gmail.com";
testdata[0][1] = "Admin@123456";
testdata[0][2] = true;
return testdata;
}

@DataProvider(name = "loginTestDataFalse")
public Object[][] testDataFeedFalse() {
Object[][] testdata = new Object[5][3];

testdata[0][0] = "trongtuyen@gmail.com";
testdata[0][1] = "Admin@123456";
testdata[0][2] = true;

testdata[1][0] = "trongtuyen123@gmail.com";
testdata[1][1] = "Admin@123456";
testdata[1][2] = true;

testdata[2][0] = "";
testdata[2][1] = "Admin@123456";
testdata[2][2] = true;

testdata[3][0] = "trongtuyen451@gmail.com";
testdata[3][1] = "";
testdata[3][2] = true;

testdata[4][0] = "";
testdata[4][1] = "";
testdata[4][2] = true;

return testdata;
}


public boolean isLogoutDisplayed() {
try {
WebElement logoutBtn = driver.findElement(By.xpath("//li[contains(@class,'logout')]"));
return true;
} catch (Exception e) {
return false;
}

}

@Test()
public void loginTest() throws Exception {
// Launch website
String url = "https://automationtestpro.com/";
@Test(dataProvider = "loginTestData")
public void loginTestSuccess(String uname, String pw, boolean expectedLogoutDisplay) throws Exception {
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
Utils.hardWait(1000); // 3s

WebElement emailInput = driver.findElement(By.xpath("//input[@id='username']"));
emailInput.sendKeys(uname);
Utils.hardWait(1000); // 3s
WebElement passInput = driver.findElement(By.xpath("//input[@id='password']"));
passInput.sendKeys(pw);
Utils.hardWait(1000); // 3s

WebElement loginBtn = driver.findElement(By.xpath("//button[@name='login']"));
loginBtn.click();
Utils.hardWait(1000); // 3s
boolean logoutBtnDisplayed = isLogoutDisplayed();
Assert.assertEquals(logoutBtnDisplayed, expectedLogoutDisplay);
}



public boolean isMessageErrorDisplayed() {
try {
WebElement messageError = driver.findElement(By.xpath("//ul[@class='woocommerce-error']"));
return true;
} catch (Exception e) {
return false;
}

}
@Test(dataProvider = "loginTestDataFalse")
public void loginTestFalse(String unameFalse, String pwFalse, boolean expectedErrorMessageDisplay) throws Exception {
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
Utils.hardWait(1000); // 3s

WebElement emailInput = driver.findElement(By.xpath("//input[@id='username']"));
emailInput.sendKeys(unameFalse);
Utils.hardWait(1000); // 3s
WebElement passInput = driver.findElement(By.xpath("//input[@id='password']"));
passInput.sendKeys(pwFalse);
Utils.hardWait(1000); // 3s

WebElement loginBtn = driver.findElement(By.xpath("//button[@name='login']"));
loginBtn.click();
Utils.hardWait(1000); // 3s
boolean messageErrorDisplayed = isMessageErrorDisplayed();
Assert.assertEquals(messageErrorDisplayed, expectedErrorMessageDisplay);
}
}
56 changes: 56 additions & 0 deletions src/test/java/com/RegisterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.utils.BasicTest;

public class RegisterTest extends BasicTest {
// Đăng kí fails - để trống mật khẩu
@Test(priority = 1)
public void registerTestFaisePasswordEmty() throws Exception {
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
WebElement emailInputReg = driver.findElement(By.xpath("//input[@id='reg_email']"));
emailInputReg.sendKeys("trongtuyen451@gmail.com");
WebElement passInputReg = driver.findElement(By.xpath("//input[@id='reg_password']"));
passInputReg.sendKeys("");
WebElement RegBtn = driver.findElement(By.xpath("//button[contains(@class,'register')]"));
RegBtn.click();
WebElement errorrMessageText = driver.findElement(By.xpath("//strong[contains(text(), 'Lỗi:')]"));
Assert.assertTrue(errorrMessageText.isDisplayed());
}

// Dăng kí failse - để trống email
@Test(priority = 2)
public void registerTestFailseEmailEmty() throws Exception {
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
WebElement emailInputReg = driver.findElement(By.xpath("//input[@id='reg_email']"));
emailInputReg.sendKeys("");
WebElement passInputReg = driver.findElement(By.xpath("//input[@id='reg_password']"));
passInputReg.sendKeys("Admin@123456");
WebElement RegBtn = driver.findElement(By.xpath("//button[contains(@class,'register')]"));
RegBtn.click();
//=> thêm asert
}

// Đăng kí thành công
@Test(priority = 3)
public void registerTestSuccess() throws Exception {
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
WebElement emailInputReg = driver.findElement(By.xpath("//input[@id='reg_email']"));
emailInputReg.sendKeys("trongtuyen453@gmail.com");
WebElement passInputReg = driver.findElement(By.xpath("//input[@id='reg_password']"));
passInputReg.sendKeys("Admin@123456");
WebElement RegBtn = driver.findElement(By.xpath("//button[contains(@class,'register')]"));
RegBtn.click();
//=> thêm asert
}
}
51 changes: 51 additions & 0 deletions src/test/resources/suites/Regression.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="1" parallel="tests" name="DemoSuite">
<test thread-count="1" parallel="classes" name="DemoTest">
<parameter name="browser" value="chrome"/>
<classes>


<class name="com.LoginTest" >
<methods>
<include name="loginTestSuccess"/>
</methods>

<methods>
<include name="loginTestFalse"/>
</methods>
</class>


<class name="com.RegisterTest" >
<methods>
<include name="registerTestSuccess"/>
</methods>
<methods>
<include name="registerTestFailseEmailEmty"/>
</methods>
<methods>
<include name="registerTestFaisePasswordEmty"/>
</methods>
</class>


<class name="com.BookingTest" >
<methods>
<include name=" BookingSuccess"/>
</methods>
</class>


<class name="com.LoginIceHrmTest" >
<methods>
<include name="loginTestSuccess"/>
</methods>
<methods>
<include name=" loginTestFalse"/>
</methods>
</class>

</classes>
</test>
</suite> <!-- Suite -->
Loading