본문 바로가기
IT/UITEST

UI-Test 10 wait

by dya0 2019. 5. 7.

화면이 로딩되기 전에 요소를 선택하면 NoSuchElementException 오류가 발생한다. 

이런 상황을 방지하기 위해서 Wait을 사용한다. 

wait에는 두 가지가 있다.

]
  1. 암시적 대기 (implicitly Wait)
    • 스크립트의 모든 요소에 적용된다
    • 요소가 암시적 대기열에 지정도니 시간 프레임에 있을 때 사용하는 것이 좋다.
    • 
      
      
       
      	WebDriverWait wait = new WebDriverWait(driver,10);
      	driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      
  2. 명시적 대기 (Explicitly Wait)
    • 우리가 의도한 요소에서만 적용된다.
    • 요소를 로드하는데 시가닝 오래 걸리지만 요소의 속성을 확인하는데 사용할 때 좋다
    • 
      
       
      	WebDriverWait wait = new WebDriverWait(driver,10);
      	wait.until(ExpectedConditions.alertIsPresent());
      			driver.switchTo().alert().accept();
      			wait.until(ExpectedConditions.titleContains("게시판"));
      			wait.until(ExpectedConditions.elementToBeClickable(By.id("board_name")));