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

Bai 21 #49

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
27 changes: 27 additions & 0 deletions src/main/java/com/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class BasePage {
protected WebDriver driver;
protected WebDriverWait wait;


public BasePage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver, 10);
}


protected WebElement findElementByLocator(By locator) {
return this.driver.findElement(locator);
}

protected WebElement waitAndFind(By locator) {
return this.wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/pages/LoginPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class LoginPage extends BasePage {
protected WebDriver driver;


public LoginPage(WebDriver driver) {
super(driver);
}

By tkBtn = By.id("UserLogin");
By email = By.xpath("//input[@name=\"EmailPhoneDN\"]");
By dnBtn = By.xpath("//*[@class=\"btn-login-wrap\"]");
By pw = By.name("PasswordDN");
By loginSubmitBtn = By.xpath("//button[contains(@class,\"btn btn-login col-xs-12\") and text() = \"Đăng nhập\"]");

public void clickTKBtn() {
waitAndFind(tkBtn).click();
}

public void clickDNBtn() {
waitAndFind(dnBtn).click();
}

public void sendEmail(String value) {
waitAndFind(email).sendKeys(value);
}

public void sendPw(String value) {
waitAndFind(pw).sendKeys(value);
}

public void clickSubmitLogin() {
findElementByLocator(loginSubmitBtn);
}



}
25 changes: 23 additions & 2 deletions src/main/java/com/utils/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;

import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.concurrent.TimeUnit;


public abstract class BasicTest {
Expand All @@ -18,6 +19,7 @@ public abstract class BasicTest {
// private String driverPath;

@BeforeMethod
@Parameters({"BaseURL"})
public void preCondition() {
// Chromedriver path
// driverPath = "src/main/resources/WebDrivers/chromedriver.exe";
Expand All @@ -29,8 +31,27 @@ public void preCondition() {
// Maximize the browser
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//driver.get(BaseURL);
}

@DataProvider(name = "testLogin")
public Object[][] TestDataFeed() {

//Create object array 3 rows, 2 columns
Object[][] testData = new Object[3][2];

//Data Test
testData[0][0] = "admin";
testData[0][1] = "admin";

testData[1][0] = "manager";
testData[1][1] = "demouserpwd";

testData[2][0] = "user1";
testData[2][1] = "demouserpwd";

return testData;
}
@AfterMethod
public void postCondition(){
// Quit the Browser
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/com/Bai16.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 Bai16 extends BasicTest {
@Test()
public void loginTest() throws Exception {
// Launch website
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);

// Click Submit button
WebElement btnRegister = driver.findElement(By.xpath("//button[@name=\"register\"]"));
btnRegister.click();
WebElement noticeString = driver.findElement(By.xpath("//ul[@class=\"woocommerce-error\"]"));
Assert.assertTrue(noticeString.getText().contains("Vui lòng cung cấp địa chỉ email hợp lệ"));

//Dien email invalid
WebElement inputEmail = driver.findElement(By.xpath("//input[@id='reg_email']"));
inputEmail.sendKeys("abc@xyz");
WebElement btnRegister2 = driver.findElement(By.xpath("//button[@name=\"register\"]"));
btnRegister2.click();
WebElement noticeString2 = driver.findElement(By.xpath("//ul[@class=\"woocommerce-error\"]"));
Assert.assertTrue(noticeString2.getText().contains("Vui lòng cung cấp địa chỉ email hợp lệ"));


//Dien email hop le
WebElement inputEmail2 = driver.findElement(By.xpath("//input[@id='reg_email']"));
inputEmail2.clear();
inputEmail2.sendKeys("trangtq@behemoth.vn");
WebElement btnRegister3 = driver.findElement(By.xpath("//button[@name=\"register\"]"));
btnRegister3.click();
WebElement noticeString3 = driver.findElement(By.xpath("//ul[@class=\"woocommerce-error\"]"));
Assert.assertTrue(noticeString3.getText().contains("Vui lòng nhập mật khẩu tài khoản"));
}
}
39 changes: 39 additions & 0 deletions src/test/java/com/Bai17.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 Bai17 extends BasicTest {
@Test()
public void loginTest() throws Exception {
// Launch website
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);

// Log in
WebElement inputEmail = driver.findElement(By.xpath("//input[@id='username']"));
inputEmail.clear();
inputEmail.sendKeys("trangtq.9593@gmail.com");
WebElement inputPassword = driver.findElement(By.xpath("//input[@id='password']"));
inputPassword.clear();
inputPassword.sendKeys("Quynhtrang");
WebElement btnLogin = driver.findElement(By.xpath("//button[@name='login']"));
btnLogin.click();
String homepage = "https://bantheme.xyz/hathanhauto/";
driver.get(homepage);

// Click on 'Tai khoan'
WebElement taiKhoan = driver.findElement(By.xpath("//a[@class='pos-login']"));
taiKhoan.click();
// Click log-out
WebElement btnLogout = driver.findElement(By.xpath("//a[contains(text(),'Thoát')]"));
btnLogout.click();
// Click on Back button
driver.navigate().back();
Assert.assertTrue(driver.findElement(By.xpath("//button[@name='login']")).isDisplayed());
}
}
57 changes: 57 additions & 0 deletions src/test/java/com/Bai18.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com;

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

import com.utils.BasicTest;

public class Bai18 extends BasicTest {
@Test()
public void loginTest() throws Exception {
// Launch website
String url = "https://bantheme.xyz/hathanhauto/tai-khoan/";
driver.get(url);

// Log in and go to home page
WebElement inputEmail = driver.findElement(By.xpath("//input[@id='username']"));
inputEmail.clear();
inputEmail.sendKeys("trangtq.9593@gmail.com");
WebElement inputPassword = driver.findElement(By.xpath("//input[@id='password']"));
inputPassword.clear();
inputPassword.sendKeys("Quynhtrang");
WebElement btnLogin = driver.findElement(By.xpath("//button[@name='login']"));
btnLogin.click();
String homepage = "https://bantheme.xyz/hathanhauto/";
driver.get(homepage);
String originalWindow = driver.getWindowHandle();

//Open New Tab
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.open()");

//Loop through until we find a new window handle
for (String windowHandle : driver.getWindowHandles()) {
if(!originalWindow.contentEquals(windowHandle)) {
driver.switchTo().window(windowHandle);
break;
}
}
String newWindow = driver.getWindowHandle();
//Go to homepage in new tab
driver.get(homepage);


//Close old tab
driver.switchTo().window(originalWindow);
driver.close();
driver.switchTo().window(newWindow);
// Click on 'Dang Nhap'
WebElement btnDangNhap = driver.findElement(By.xpath("//a[@class='pos-login']"));
btnDangNhap.click();
Assert.assertEquals(driver.getCurrentUrl(), "https://bantheme.xyz/hathanhauto/tai-khoan/");

}
}
27 changes: 27 additions & 0 deletions src/test/java/com/Bai19.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 Bai19 extends BasicTest {
@Test(dataProvider = "testLogin")
public void loginTest(String username, String pwd) throws Exception {

//Get element
WebElement account = driver.findElement(By.xpath("//*[@id=\"username\"]"));
WebElement password = driver.findElement(By.id("password"));
WebElement btnLogin = driver.findElement(By.xpath("//button[contains(text(), 'Log in ')]"));

account.clear();
account.sendKeys(username);
password.clear();
password.sendKeys(pwd);
btnLogin.click();

Assert.assertTrue(driver.getCurrentUrl().contains("dashboard"));
}
}
30 changes: 30 additions & 0 deletions src/test/java/com/Bai20.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com;

import org.openqa.selenium.By;
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.BasicTest;

public class Bai20 extends BasicTest {
@Test(dataProvider = "testLogin")
public void loginTest(String username, String pwd) throws Exception {

WebDriverWait wait = new WebDriverWait(driver, 30);

//Get element
//WebElement account = driver.findElement(By.xpath("//*[@id=\"username\"]"));
//WebElement password = driver.findElement(By.id("password"));
//WebElement btnLogin = driver.findElement(By.xpath("//button[contains(text(), 'Log in ')]"));

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"username\"]"))).clear();
driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(username);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password"))).clear();
driver.findElement(By.id("password")).sendKeys(pwd);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[contains(text(), 'Log in ')]"))).click();

Assert.assertTrue(driver.getCurrentUrl().contains("dashboard"));
}
}
44 changes: 44 additions & 0 deletions src/test/java/com/Bai21.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com;

import javax.swing.Action;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
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.applitools.eyes.selenium.SeleniumEyes.WebDriverAction;
import com.utils.BasicTest;
import com.utils.Utils;

public class Bai21 extends BasicTest {
@Test()
public void loginTest() throws Exception {
// Launch website
String url = "https://zingmp3.vn/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);

//Find element and right click
WebDriverWait wait = new WebDriverWait(driver, 10);
Actions action = new Actions(driver);
WebElement media = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class=\"media\"]")));
action.moveToElement(media).contextClick().perform();
Assert.assertTrue(driver.findElement(By.xpath("//*[@class=\"zm-contextmenu song-menu\"]")).isDisplayed());
// Continue hover to "Share" option
WebElement shareBtn = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Chia sẻ')]")));
action.moveToElement(shareBtn).perform();
Assert.assertTrue(
wait.until(ExpectedConditions.visibilityOfElementLocated(
(By.xpath("//*[@class=\"menu share-content submenu-content\"]"))
)
).isDisplayed());




}
}
Loading