Chrome IDE 설치
https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd
Selenium IDE
Selenium Record and Playback tool for ease of getting acquainted with Selenium WebDriver.
chrome.google.com
셀레늄 웹 드라이버 설치
https://www.selenium.dev/downloads/
https://chromedriver.chromium.org/
각자 PC에 설치된 크롬(또는 선호하는 브라우저) 버전을 확인해서 버전에 맞는 driver를 설치해야 한다.
PATH Environment Variable 에 추가
다운로드 후 압축 해제, chromedriver를 원하는 경로에 복사
[Mac]
Bash :
echo 'export PATH=$PATH:/{설치경로}' >> ~/.bash_profile
source ~/.bash_profile
zsh :
echo 'export PATH=$PATH:/{bin}' >> ~/.zshenv
source ~/.zshenv
드라이버 실행해서 경로, 권한 확인
>> chromedriver
Starting ChromeDriver 112.0.5615.49 (bd2a7bcb881c11e8cfe3078709382934e3916914-refs/branch-heads/5615@{#936}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[Windows]
내 컴퓨터 -> 마우스 우 클릭 -> 속성 -> 고급 시스템 설정
아래 있는 "환경 변수"를 클릭합니다.
환경 변수 창에서
Path를 찾아서 선택한 후 편집을 클릭
새로 만들기를 클릭 후 ChromeDriver가 설치(압축 해제)된 Path를 추가
Java 공식 문서의 path 설정 가이드
https://www.java.com/ko/download/help/path_ko.html
참고 : Java에서 System.setProperty로 경로를 지정할 수도 있음
System.setProperty("webdriver.chrome.driver","/path/to/chromedriver");
ChromeDriver driver = new ChromeDriver();
IntelliJ 구성
New Project -> Gralde -> Java
IntelliJ 터미널에서 Gradle upgrade
./gradlew wrapper --gradle-version 8.0.1
##설치 완료된 후
./gradlew -v
Welcome to Gradle 8.0.1!
... 생략...
build.gradle 에 Selenium 추가
... 생략...
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
//For Selenium
testImplementation 'org.seleniumhq.selenium:selenium-java:4.8.0'
testImplementation 'org.seleniumhq.selenium:selenium-http-jdk-client:4.8.0'
}
... 생략...
Gradle Reload
Extenal Libraries에 라이브러리 설치 확인
첫 번째 테스트 코드 추가
프로젝트 Root에서 New -> Directory
src/test/java 선택
selenium 패키지에 FirstScriptTest.java 추가
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class FirstScriptTest {
@Test
public void eightComponents() throws InterruptedException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
String title = driver.getTitle();
assertEquals("Web form", title);
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
WebElement textBox = driver.findElement(By.name("my-text"));
WebElement submitButton = driver.findElement(By.cssSelector("button"));
Thread.sleep(2000L);
textBox.sendKeys("Selenium");
submitButton.click();
WebElement message = driver.findElement(By.id("message"));
String value = message.getText();
assertEquals("Received!", value);
Thread.sleep(3000L);
driver.quit();
}
}
'프로그래밍 > Java-Spring' 카테고리의 다른 글
맥북 JAVA 버전 변경 (0) | 2023.12.05 |
---|---|
영어 자판으로 입력된 한글 변환 코드 (0) | 2023.08.29 |
Java 함수형 인터페이스 #3 - 스트림, 람다 (0) | 2023.01.20 |
Java 함수형 프로그래밍 #2 (0) | 2023.01.17 |
Java 함수형 프로그래밍 (0) | 2023.01.17 |