Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.junit.jupiter.api.Assertions.fail;

import java.time.Duration;
import java.time.LocalDateTime;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Alert;
Expand All @@ -12,26 +14,43 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Sleeper;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class EgovSampleControllerTestSelenium {

private static final Duration WAIT_DURATION = Duration.ofSeconds(1);

@LocalServerPort
private int port;

WebDriver driver;

@BeforeEach
public void setup() {
driver = new ChromeDriver();
}

@AfterEach
void tearDown() {
if (driver != null) {
sleep();
driver.quit();
}
}

@Test
void test() {
if (log.isDebugEnabled()) {
log.debug("test");
}

driver.get("http://localhost:8080/");
driver.get("http://localhost:" + port + "/");

JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;

Expand All @@ -53,7 +72,7 @@ void test() {

sleep();
WebElement regUser = driver.findElement(By.id("regUser"));
regUser.sendKeys("test 이백행 등록자 " + now);
regUser.sendKeys("test 이백행");

sleep();
javascriptExecutor.executeScript("sampleAdd();");
Expand All @@ -70,10 +89,11 @@ void test() {

private void sleep() {
try {
Thread.sleep(1000);
Sleeper.SYSTEM_SLEEPER.sleep(WAIT_DURATION);
} catch (InterruptedException e) {
fail("InterruptedException: Thread.sleep");
Thread.currentThread().interrupt();
fail("InterruptedException: Selenium Sleeper", e);
}
}

}
}