2013-06-17 2 views
1

여기에 내가하려는 작업이 있습니다.iOS UI 자동화 : 두 개의 alertView를 처리합니다. 하나는 다른 하나를 트리거합니다.

1) "어디에서 쇼핑하고 있습니까?"라는 질문을하는 alertView가 하나 있습니다. 이 경고에는 건너 뛰기/취소 및 계속하기위한 두 개의 단추가 있습니다. 2) 건너 뛰기 버튼을 클릭하면 "Nearby listings :"이라는 제목의 또 다른 alertView가 팝업되고 사용자가 상점을 선택할 수있는 근처 상점의 tableView 목록이 표시됩니다. 이 버튼에는 취소 버튼이 하나만 있습니다.

내 문제는 내가이 건너 뛰기 버튼을 탭하고 두 번째 경고 팝업 그래서

UIATarget.onAlert = function onAlert(alert) { 
     var title = alert.name(); 
     UIALogger.logWarning("Alert with title ’" + title + "’ encountered!"); 
     if (title == "Where are you shopping?") { 
      alert.buttons()["Skip"].tap(); 
      return true; // bypass default handler 
     } 
     return false; 
     } 

같은 기본 핸들러를 우회하려고 할 때마다입니다 (버튼 경고를 일축하고 홈 페이지로 돌아 소요 취소) 기본 버튼은 두 번째 경고에서 탭하도록 지정되어 있는데, 코드를 작성하지 않은 경우에도 마찬가지입니다.

첫 번째 경고 건너 뛰기 버튼을 탭하고 두 번째 경고 셀 중 하나를 탭하고 싶습니다. 그래서 아래의 코드를 시도했지만 셀을 두드리지 않고 두 번째 경고를 닫습니다. 그것을하는 방법을 모르십시오. 나는 초보자이므로 정말 도움이된다.

var target = UIATarget.localTarget(); 
    var app = target.frontMostApp(); 
    var window = app.mainWindow(); 
    var testName = "Test 1"; 

    UIALogger.logStart(testName); 


    var buttonScan = target.frontMostApp().windows()[0].buttons()["scan btn"]; 
    //UIATarget.localTarget().pushTimeout(1); 

    target.delay(1); 

    //app.logElementTree(); 

    if (buttonScan.isValid()) { 
    buttonScan.tap(); 

    // first alert box "Where are you shopping" 
    UIATarget.onAlert = function onAlert(alert) { // this is never called 
     var title = alert.name(); 
     UIALogger.logWarning("Alert with title ’" + title + "’ encountered!"); 
     if (title == "Where are you shopping?") { 
      alert.buttons()["Skip"].tap(); 
     return true; // bypass default handler 
     } 
    return false; 
} 

// second alert box "Nearby listings:" 
UIATarget.onAlert = function onAlert(alert) { 
    var title = alert.name(); 
UIALogger.logMessage("Dismiss the keyboard" + title); 
    UIALogger.logWarning("Alert2 with title ’" + title + "’ encountered!"); 
    if (title == "Nearby listings:") { 

     return true; // bypass default handler 
    } 
    return false; // use default handler that is dismissing the alert 
    } 


     UIALogger.logPass(testName); 


    } else { 

     UIALogger.logFail(testName); 

    } 
+0

당신은 당신의'onAlert' 핸들러가 호출되고 있음을 확인 했습니까? Apple 설명서를 인용하면 경고가 지정되지 않은 경우'cancel'을 클릭하거나 처리기가 false를 반환하려고 시도합니다. 귀하의 경우에는 조건문이 모두 true 또는 false 인 경우 취소를 클릭합니다. 따라서 첫 번째 경고에서 '계속'버튼을 클릭 할 수 있는지 확인하십시오. – ekims

+0

@ekims 응답 해 주셔서 감사합니다. 나에게 예상되는 동작은 건너 뛰기 (첫 번째 경고의 취소 단추)를 클릭하면 두 번째 경고가 그 안에 tableView와 함께 나타나야한다는 것입니다. 이제이 두 번째 경고에서 다른 화면으로 이동하게 될 셀 (제품 목록) 중 하나를 선택하고 싶습니다. –

+0

첫 번째 시나리오에서 경고 처리기가 작동하는지 확인하기 위해 첫 번째 경고에서 '계속'버튼을 클릭하십시오. 경고 처리기를 지정하지 않으면 기본적으로 취소 단추가 사용됩니다. 이렇게하면 문제가 발생한 곳을 좁히는 데 도움이됩니다. – ekims

답변

2

UITarget 인스턴스를 사용하기 전에 onAlert 처리기를 설정해보십시오. 예를 들어

는 :

// first alert box "Where are you shopping" 
UIATarget.onAlert = function onAlert(alert) { // this is never called 
     var title = alert.name(); 
     UIALogger.logWarning("Alert with title ’" + title + "’ encountered!"); 
     if (title == "Where are you shopping?") { 
      alert.buttons()["Skip"].tap(); 
      return true; // bypass default handler 
     } 
    return false; 
} 
    var target = UIATarget.localTarget(); 
    var app = target.frontMostApp(); 
    var window = app.mainWindow(); 
    var testName = "Test 1"; 

    UIALogger.logStart(testName); 

    var buttonScan = target.frontMostApp().windows()[0].buttons()["scan btn"]; 
    //UIATarget.localTarget().pushTimeout(1); 

    target.delay(1); 
    //app.logElementTree(); 

    if (buttonScan.isValid()) { 
    buttonScan.tap(); 

    //alert should happen here 
+0

안녕하세요, 이제 작동 중입니다 (onAlert를 맨 위로 이동). 마지막 시도에서 견적을 놓치고있었습니다. 고마워요. 당신은 저에게 더 많은 시간의 고통을 덜어 줬습니다. 나는 내 다음 UIAutomation 벤처를 위해 당신과 연락하고 싶습니다. –

+0

문제 없습니다. 몇 가지 작업 프로젝트에서이 도구를 사용했으며 가능한 경우 도움을 제공하게되어 기쁩니다. – ekims