2012-11-13 2 views
3

다음 시나리오와 관련된 문제가 있습니다.Watir의 대화 상자 다루기

Google 크롬을 사용하여 시스템에 로그인 할 테스트 스크립트를 작성 중입니다.

나는 Excel에서 데이터를 읽습니다.

첫 번째 데이터 집합에 잘못된 사용자 이름/암호 조합이 있습니다.

잘못된 암호를 입력하면 Username/Password가 올바르지 않다는 메시지와 함께 팝업 창이 나타납니다.

이 경우 팝업 창을 닫을 수 있어야하며 사용자 이름/암호 조합이 일치 할 때까지 watir은 Excel의 다음 데이터 집합을 읽어야합니다.


문제점 팝업 대화 상자를 감지하는 방법을 모르겠습니다. 다음과 같은 코드가 있습니다 :

<div id="alertMsg" style="width: auto; min-height: 76.69999980926514px; height: auto;" class="ui-dialog-content ui-widget-content"><div class="dialogBoxTitle">&nbsp;</div> 
<div class="alertMessage pointSearch">  
    <form name="saveComfortModelForm" class="pointSearchFrm"> 
     <table cellpadding="0" cellspacing="0" width="100%" height="100%" class="pointSearchTable"> 
      <tbody><tr> 
       <td>Login failed due to invalid password or username</td> 
      </tr> 
     </tbody></table>  
    </form> 
</div></div> 

또한 팝업이 닫히는 링크가 있습니다. 코드는 다음과 같습니다 :

<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"> 
<span class="ui-dialog-title" id="ui-dialog-title-alertMsg">&nbsp;</span> 
<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button"> 
<span class="ui-icon ui-icon-closethick">close</span> 
</a> 
</div> 

이 메시지가 표시되면 창을 닫아야합니다.

답변

0

요소의 표시 여부 중 하나를 선택하여 팝업 대화 상자가 표시되는지 여부를 감지 할 수 있습니다. 이 방법은 visible? 또는 present? 방법으로 수행 할 수 있습니다. 시도 :

browser.link(:class => "ui-dialog-titlebar-close").click 

논리의 Watir과 부분이있을 수 같은 :

begin 
    #Execute your logic to sign in with the next user/password 

    #Check if the sign in was successful 
    sign_in_successful = not(browser.div(:id => "alertMsg").present?) 
    unless sign_in_successful 
    browser.link(:class => "ui-dialog-titlebar-close").click 
    end 
end until sign_in_successful 

업데이트 : 그것은 것 같다

browser.div(:id => "alertMsg").present? 
#=> Returns true if popup is displayed, false if not displayed 

당신은 가까운 링크를 클릭하여 팝업을 닫을 수 있습니다 일부 do not prefer the begin-while/until 및 루프를 대신 사용해야합니다.

loop do 
    #Execute your logic to sign in with the next user/password 

    if browser.div(:id => "alertMsg").present? 
    browser.link(:class => "ui-dialog-titlebar-close").click 
    else 
    break 
    end 
end 

관련 문제