Test Selenium Webdriver

prom.xml file setup

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>TestNGMaven</groupId>
	<artifactId>TestNGMaven</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<properties>
		<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
	</properties>
	<dependencies>
		<!-- https://mvnrepository.com/artifact/org.testng/testng -->
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>6.14.3</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>3.141.59</version>
		</dependency>

	</dependencies>
</project>

Cai TestNG: https://viblo.asia/p/tim-hieu-ve-testng-framework-phan-1-aWj53Vyol6m

package autotest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
//Viet Test Script
/*1. Xay dung Repository
 * 		+HTML Attribute
 * 		+ CSS Seletor
 * 		+ XPATH
 */


public class FirstScript {
	WebDriver driver;

	@BeforeTest
	public void beforeTest() {
		//Khai bao driver
		System.setProperty("webdriver.gecko.driver","D:\\pleiades\\workspace\\TestNGMaven\\driver\\geckodriver.exe");
		driver = new FirefoxDriver();
		//Mo trang web
		driver.get("http://zooog.jp/");
		driver.manage().window().maximize();
	}

	@BeforeMethod
	public void beforeMethod() {
		//cai dat reset de tranh lam nhieu trong cac testCase
		driver.navigate().refresh();

	}

	@AfterMethod
	public void afterMethod() {
		//Su dung cai dat xu ly loi
	}

	@Test
	public void FirstTest() {
		//1 Xac dinh cac control nhap du lieu
		WebElement txtUsername = driver.findElement(By.className(""));
		WebElement txtPassword = driver.findElement(By.className(""));
		//2. Nhap du lieu la user va name khong ton tai
		txtUsername.sendKeys("abc");
		txtPassword.sendKeys("1234");
		//3.Click vao login
		WebElement btnclick = driver.findElement(By.className("mailbtn"));
		btnclick.click();
		//4. Cho thong bao
		WebElement lbtNotify = driver.findElement(By.className(""));
		Assert.assertEquals(lbtNotify.getText(), "Thong bao");
		//5. Kiem tra massage

	}


	@Test
	public void SecondTest() {
		System.out.println("Test case two");
	}

	@AfterTest
	public void afterTest() {
		driver.close();
		driver.quit();
	}
}

Chào mừng bạn đến với blog của tôi! Đây là nơi tôi chia sẻ những trải nghiệm, suy nghĩ và kiến thức mà tôi học được trong cuộc sống và công việc. Hy vọng bạn sẽ tìm thấy điều gì đó hữu ích và thú vị tại đây.

Design a site like this with WordPress.com
Get started