[JAVA] Selenium

Selenium UI-based unit testing method

Main source

package G_T.OfficeSystem.test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTest {
	public static void main(String[] args) {
		SeleniumTest doTest = new SeleniumTest();
		doTest.threadTest();
	}
	void threadTest() {
		ExecutorService pool = Executors.newFixedThreadPool(8);
		RunImpl runImpl = new RunImpl();
		for (int i = 0; i < 3; i++) {
			pool.submit(runImpl);
		}
		pool.shutdown();
	}
	class RunImpl implements Runnable {
		@Override
		public void run() {
			WebDriver driver = new ChromeDriver();
			driver.get("http://localhost:8080/OfficeSystem_Hibernate/Login");
			WebElement userId = driver.findElement(By.id("userId"));
			WebElement email = driver.findElement(By.id("email"));
			WebElement password = driver.findElement(By.id("password"));
			userId.sendKeys("hoang");
			email.sendKeys("[email protected]");
			password.sendKeys("1");
			driver.findElement(By.cssSelector(".BUTTON")).click();
			driver.get("http://localhost:8080/OfficeSystem_Hibernate/Chat");
//			driver.close();
		}
	}
}

pom

<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>3.9.1</version>
</dependency>

What else you need

Requires chromedriver.exe as drive driver.get("http://localhost:8080/OfficeSystem_Hibernate/Login");

(Reference material https://www.shookuro.com/entry/2019/11/03/16042)

Recommended Posts

Selenium
Try Selenium
Selenium x Java