2012-07-17 6 views
0

Eclipse에서 Selenium WebDriver를 사용합니다.페이지 제목을 올바르게 확인 하시겠습니까?

제목이 올바르게 표시되는지 확인하는 방법을 씁니다.

class Check { 
    String text_to_found; 
    String reason; 

    Check (String t, String r) { 
     text_to_found=t; 
     reason=r; 
    } 

    public void check_title() { 
     try { 
      Assert.assertTrue("Title " + text_to_found + " not found", text_to_found.equals(reason)); 
     } catch (AssertionError e) { 
      System.err.println("title not found: " + e.getMessage()); 
     } 
} 

나는 그런 명령을 호출 : 그것은 올바른 작동

Check title1 = new Check ("Title", driver.getTitle()); 
title1.check_title(); 

처음 여기에 코드입니다. 그러나 두 번째 (그리고 계속) 번,이 메서드를 호출하면 (새 윈도우가 열렸을 때) 제목이 발견되지 않는다고하지만 정확한지는 알 수 있습니다. 조언, 코드에 어떤 문제가 있습니까?

답변

0

방금 ​​코드를 사용하여 google.com의 제목을 확인했습니다. 당신의 코드에서 제목이 일치하지 않는 경우 -

Check title1 = new Check ("G3oogle", driver.getTitle()); 
    title1.check_title(); 

우리는 결과를 얻을 - title not found: Title G3oogle not found

을하지만 아래와 같이 일치하는 경우 -

Check title1 = new Check ("Google", driver.getTitle()); 
    title1.check_title(); 

를 콘솔에 아무것도 인쇄되지 않습니다. 제목이 일치하면 콘솔에 아무 것도 인쇄하지 않고 코드를 수정할 수 있습니다. -

 public void check_title() {  

    if(text_to_found.equals(reason)){ 
      System.out.println("title found: Title "+text_to_found+" found"); 
    } 
    else{ 

     System.out.println("title not found: Title "+text_to_found+" not found"); 
    } 
    } 
관련 문제