0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Selenium

Posted at

Selenium

UIベースでの単体テストの方法

メインソース

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("hoang1@gmail.com");
			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>

ほかに必要なもの

driveとしてchromedriver.exeが必要
driver.get("http://localhost:8080/OfficeSystem_Hibernate/Login");

(参考資料 https://www.shookuro.com/entry/2019/11/03/16042)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?